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 keep CT to have with larger aircraft. PTA wants you to write a program that fills each aircraft to capacity (in keeping
The name pack 'em tight) and also minimizes the total cost of operations for that route.
Input
The input file may contain in 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 shoshould not be processed.
Output
For each data set in the input file, the output file shoshould 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 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 shocould be formatted as follows:
Data Set <n>: cannot be flown
Sample Input
60030 2020 405501 132 295491 132 2920000000001 23 759911 2022 400
Sample output
Data set 1: 0 aircraft A, 15 aircraft BData set 2: 20 aircraft A, 10 aircraft BData set 3: 11 aircraft A, 14 aircraft BData set 4: 6 aircraft A, 285714284 aircraft BData set 5: cannot be flown
Question Analysis:
Ax + by = W. We know that a, B, and W are used to evaluate X, Y, and X and Y are non-negative integers. However, X and Y have a weight value, and the cost of all X and Y is the smallest. Assume that the cost of X is small, so take the greater value of X and the smaller value of Y, you only need to traverse (note that the number of passengers is 0)
#include<iostream>#include <iomanip>#include<stdio.h>#include<cmath>#include<iomanip>#include<list>#include <map>#include <vector>#include <string>#include <algorithm>#include <sstream>#include <stack>#include<queue>#include<string.h>using namespace std;int main(){long long n;int geshu=0;while(scanf("%lld",&n)&&n!=0){geshu++;unsigned int costA,costB,passengersA,passengersB;scanf("%d%d%d%d",&costA,&passengersA,&costB,&passengersB);double biA=(double)costA/passengersA,biB=(double)costB/passengersB;bool chgFlag=false;if(biA>biB){chgFlag=true;swap(costA,costB);swap(passengersA,passengersB);}unsigned int count=0,numberB=0,numberA;bool flag=false;unsigned long long cost=-1;while(1){if(n<0)break;if(passengersA==0&&passengersB==0)break;else if(passengersA==0){if(n%passengersB==0){flag=true;numberA=0;numberB=n/passengersB;}break;}else if(passengersB==0){if(n%passengersA==0){flag=true;numberB=0;numberA=n/passengersA;}break;}if(n%passengersA==0){unsigned long long price=n/passengersA*costA+count*costB;if(price<cost){flag=true;cost=price;numberA=n/passengersA;numberB=count;break;}}count++;n=n-passengersB;}printf("Data set %d: ",geshu);if(chgFlag)swap(numberA,numberB);if(flag)printf("%d aircraft A, %d aircraft B\n",numberA,numberB);else printf("cannot be flown\n");}}