首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

为什么这道题目小弟我总是RUNTIME ERROR呢

2013-12-05 
求助:为什么这道题目我总是RUNTIME ERROR呢?sicily 1099 Packing Passengers题意描述——DescriptionPTA, Pa

求助:为什么这道题目我总是RUNTIME ERROR呢?
sicily 1099 Packing Passengers
题意描述——
Description
PTA, Pack ‘em Tight Airlines is attempting the seemingly impossible—to fly with only full planes and still make a profit. Their strategy is simplicity and efficiency. Their fleet consists of 2 types of equipment (airline lingo for airplanes). Type A aircraft cost costA dollars to operate per flight and can carry passengersA passengers. Type B aircraft cost costB dollars to operate per flight and can carry passengersB passengers.

PTA has been using software that works well for fewer than 100 passengers, but will be far too slow for the number of passengers they expect to have with larger aircraft. PTA wants you to write a program that fills each aircraft to capacity (in keeping with the name Pack 'em Tight) and also minimizes the total cost of operations for that route.

Input
The input file may contain data sets. Each data set begins with a line containing the integer n (1 <= n <= 2,000,000,000) which represents the number of passengers for that route. The second line contains costA and passengersA, and the third line contains costB and passengersB. There will be white space between the pairs of values on each line. Here, costA, passengersA, costB, and passengersB are all nonnegative integers having values less than 2,000,000,001.
After the end of the final data set, there is a line containing “0” (one zero) which should not be processed.

Output
For each data set in the input file, the output file should contain a single line formatted as follows:
Data set <N>: <A> aircraft A, <B> aircraft B
Where <N> is an integer number equal to 1 for the first data set, and incremented by one for each subsequent data set, <A> is the number of airplanes of type A in the optimal solution for the test case, and <B> is the number of airplanes of type B in the optimal solution. The 'optimal' solution is a solution that lets PTA carry the number of passengers specified in the input for that data set using only airplanes loaded to their full capacity and that minimizes the cost of operating the required flights. If multiple alternatives exist fitting this description, select the one that uses most airplanes of type A. If no solution exists for PTA to fly the given number of passengers, the out line should be formatted as follows:
Data set <N>: cannot be flown

Sample Input
600
30 20
20 40
550
1 13
2 29
549
1 13
2 29
2000000000
1 2
3 7
599
11 20
22 40
0
Sample Output
Data set 1: 0 aircraft A, 15 aircraft B
Data set 2: 20 aircraft A, 10 aircraft B
Data set 3: 11 aircraft A, 14 aircraft B
Data set 4: 6 aircraft A, 285714284 aircraft B
Data set 5: cannot be flown

我的程序是:
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
int Count = 1;
long long Ps_Num;
while (cin >> Ps_Num && Ps_Num != 0)
{
long long cosa, pca, cosb, pcb;
cin >> cosa >> pca >> cosb >> pcb;
double xinga = (double)pca/cosa, xingb = (double)pcb/cosb;
long long x_limit = floor(Ps_Num/pca);
long long y_limit = floor(Ps_Num/pcb);
long long last_x, last_y;
if (xinga == xingb)
{
if (Ps_Num%pca == 0)
cout << "Data set " << Count++ << ": " << Ps_Num/pca << " aircraft A, 0 aircraft B" << endl;


else
cout << "Data set " << Count++ << ": cannot be flown" << endl;
}
else if (xinga > xingb)
{
long long temp;
bool flag = true;
for (long long i = x_limit; i >= 0; i--)
{
int j = (Ps_Num-pca*i)%pcb;
if (j == 0)
{
long long yy = (Ps_Num-pca*i)/pcb;
if (flag)
{
temp = (i*cosa+yy*cosb);
flag = false;
last_x = i;
last_y = yy;
}
else
{
if (temp > (i*cosa+yy*cosb))
{
temp = (i*cosa+yy*cosb);
last_x = i;
last_y = yy;
}
else
{
break;
}
}
}
}
cout << "Data set " << Count++ << ": " << last_x << " aircraft A, " << last_y << " aircraft B" << endl;
}
else
{
long long temp;
bool flag = true;
for (long long i = y_limit; i >= 0; i--)
{
int j = (Ps_Num-pcb*i)%pca;
if (j == 0)
{
long long xx = (Ps_Num-pcb*i)/pca;
if (flag)
{
temp = (i*cosb+xx*cosa); 
flag = false;
last_x = xx;
last_y = i;
}
else
{
if (temp > (i*cosb+xx*cosa))
{
temp = (i*cosb+xx*cosa);
last_x = xx;
last_y = i;
}
else
{
break;
}
}
}
}
cout << "Data set " << Count++ << ": " << last_x << " aircraft A, " << last_y << " aircraft B" << endl;
}
}
return 0;
}
经本人测试,可以通过所有的测试样例,但是提交之后系统提示:Runtime Error,Your program has fatal error.很奇怪呀,不会是有变态的测试数据吧!求解,万分感谢! OJ;
[解决办法]
你把英文大意讲一下吧,不然大家都不愿意看
[解决办法]
LZ所谓的所有的测试样例不会就是sample吧

那只是个sample而已。

热点排行