Sicily 1099 Packing Passengers

阅读: 评论:0

Sicily 1099 Packing Passengers

Sicily 1099 Packing Passengers

Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
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 : aircraft A, aircraft B
Where is an integer number equal to 1 for the first data set, and incremented by one for each subsequent data set, is the number of airplanes of type A in the optimal solution for the test case, and 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 : 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
这道题的目的是在让每架飞机都满载的情况之下运走所有乘客,并选择花费最少的一个,思路让性价比低的飞机的架数尽可能的少,并满足飞机必须满载的要求,核心代码如下
先考虑numa或numb为0的情况

然后根据题目的要求及性价比选择飞机

#include<iostream>
using namespace std;
int main(){int n;int times=1;while(cin>>n&&n!=0){bool flag=false;int costa,costb;int numa,numb;cin>>costa>>numa>>costb>>numb;if(numa==0){if(n%numb==0){int num=n/numb;cout<<"Data set "<<times++<<": 0 aircraft A, "<<num<<" aircraft B"<<endl;}else{cout<<"Data set "<<times++<<": cannot be flown"<<endl;}continue;}if(numb==0){if(n%numa==0){int num=n/numa;cout<<"Data set "<<times++<<": "<<num<<" aircraft A, "<<"0 aircraft B"<<endl;}else{cout<<"Data set "<<times++<<": cannot be flown"<<endl;}continue;}double pera,perb;pera=(double)costa/(double)numa;perb=(double)costb/(double)numb;if(pera<=perb){int max=n/numb;int a,b;for(int i=0;i<=max;i++){int left=n-i*numb;if(left%numa==0&&left!=0){a=left/numa;b=i;flag=true;break;}if(left==0){a=0;b=max;flag=true;}}if(flag){cout<<"Data set "<<times++<<": "<<a<<" aircraft A, "<<b<<" aircraft B"<<endl;}}else{int max=n/numa;//cout<<max;int a,b;for(int i=0;i<=max;i++){int left=n-i*numa;if(left%numb==0&&left!=0){b=left/numb;a=i;flag=true;break;}if(left==0){b=0;a=max;flag=true;}}if(flag){cout<<"Data set "<<times++<<": "<<a<<" aircraft A, "<<b<<" aircraft B"<<endl;}}if(!flag){cout<<"Data set "<<times++<<": cannot be flown"<<endl;}}
}

本文发布于:2024-01-29 04:43:19,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170647460412777.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:Sicily   Passengers   Packing
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23