C++ runtime error, vc6.0下测试没问题,提交至OJ出现runtime error,求指导 10
#include<stdio.h>intn,ca,a,cb,b;intmain(){intcount=0;intc1,c2,f1,f2;boolflag;while(1)...
#include <stdio.h>
int n,ca,a,cb,b;
int main()
{
int count=0;
int c1,c2,f1,f2;
bool flag;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
count++;
scanf("%d %d %d %d",&ca,&a,&cb,&b);
c1=0;
c2=0;
flag = false;
if( a == 0 )
{
if( b != 0 && n%b==0 )
{
flag = true;
c2 = n/b;
}
}
else if( b==0 && n%a==0 )
{
flag = true;
c1 = n/a;
}
else{
f1 = n/a+1;
f2 = n/b+1;
if( (cb==0&&ca!=0) || (ca!=0 && (float)a / (float)ca < (float) b / (float) cb) )
{
for( ; c1 < f1; c1++)
{
if( n%b == 0 )
{
c2 = n/b;
flag = true;
break;
}
n-=a;
if( n < b )
{
if( n%a ==0 )
{
c1 = f1-1;
flag=true;
}
break;
}
}
}
else
{
for( ; c2 < f2; c2++)
{
if( n%a == 0 )
{
c1=n/a;
flag = true;
break;
}
n-=b;
if( n < a ){
if( n%b==0 )
{
c2 = f2-1;
flag = true;
}
break;}
}
}}
if( flag )
printf("Data set %d: %d aircraft A, %d aircraft B\n",count,c1,c2);
else
printf("Data set %d: cannot be flown\n",count);
}
return 0;
} 展开
int n,ca,a,cb,b;
int main()
{
int count=0;
int c1,c2,f1,f2;
bool flag;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
count++;
scanf("%d %d %d %d",&ca,&a,&cb,&b);
c1=0;
c2=0;
flag = false;
if( a == 0 )
{
if( b != 0 && n%b==0 )
{
flag = true;
c2 = n/b;
}
}
else if( b==0 && n%a==0 )
{
flag = true;
c1 = n/a;
}
else{
f1 = n/a+1;
f2 = n/b+1;
if( (cb==0&&ca!=0) || (ca!=0 && (float)a / (float)ca < (float) b / (float) cb) )
{
for( ; c1 < f1; c1++)
{
if( n%b == 0 )
{
c2 = n/b;
flag = true;
break;
}
n-=a;
if( n < b )
{
if( n%a ==0 )
{
c1 = f1-1;
flag=true;
}
break;
}
}
}
else
{
for( ; c2 < f2; c2++)
{
if( n%a == 0 )
{
c1=n/a;
flag = true;
break;
}
n-=b;
if( n < a ){
if( n%b==0 )
{
c2 = f2-1;
flag = true;
}
break;}
}
}}
if( flag )
printf("Data set %d: %d aircraft A, %d aircraft B\n",count,c1,c2);
else
printf("Data set %d: cannot be flown\n",count);
}
return 0;
} 展开
2个回答
展开全部
应该是Sicily 1099 Packing Passengers这道题吧?
【AC源代码】
#include <cstdio>
#include <cmath>
int main() {
long long x, y, ac, bc, am, bm, remain, k, upper;
int c, tc;
//freopen("in.txt", "r", stdin);
tc = 1;
while(scanf("%d", &c), c != 0)
{
scanf("%lld %lld %lld %lld", &am, &ac, &bm, &bc);
if (bc == 0 && ac != 0)
{
remain = c % ac;
x = c / ac;
y = 0;
}
else if (bc == 0 && ac == 0)
{
remain = 1;
}
else if (bc != 0 && ac == 0)
{
remain = c % bc;
y = c / bc;
x = 0;
}
else
{
k = am * bc - ac * bm;
upper = (long long)floor((double)(c / ac));
if (k > 0)
{
for (x = 0; x <= upper; x++)
{
remain = (c - x * ac) % bc;
y = (c - x * ac) / bc;
if (!remain) break;
}
}
else
{
for (x = upper; x >= 0; x--)
{
remain = (c - x * ac) % bc;
y = (c - x * ac) / bc;
if (!remain) break;
}
}
}
printf("Data set %d: ", tc++);
if (remain)
printf("cannot be flown\n");
else
printf("%lld aircraft A, %lld aircraft B\n", x, y);
}
return 0;
}
【AC源代码】
#include <cstdio>
#include <cmath>
int main() {
long long x, y, ac, bc, am, bm, remain, k, upper;
int c, tc;
//freopen("in.txt", "r", stdin);
tc = 1;
while(scanf("%d", &c), c != 0)
{
scanf("%lld %lld %lld %lld", &am, &ac, &bm, &bc);
if (bc == 0 && ac != 0)
{
remain = c % ac;
x = c / ac;
y = 0;
}
else if (bc == 0 && ac == 0)
{
remain = 1;
}
else if (bc != 0 && ac == 0)
{
remain = c % bc;
y = c / bc;
x = 0;
}
else
{
k = am * bc - ac * bm;
upper = (long long)floor((double)(c / ac));
if (k > 0)
{
for (x = 0; x <= upper; x++)
{
remain = (c - x * ac) % bc;
y = (c - x * ac) / bc;
if (!remain) break;
}
}
else
{
for (x = upper; x >= 0; x--)
{
remain = (c - x * ac) % bc;
y = (c - x * ac) / bc;
if (!remain) break;
}
}
}
printf("Data set %d: ", tc++);
if (remain)
printf("cannot be flown\n");
else
printf("%lld aircraft A, %lld aircraft B\n", x, y);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询