sicily 1099. Packing Passengers
2015-11-17 16:20
302 查看
1099. Packing Passengers
Constraints
Time Limit: 1 secs, Memory Limit: 32 MBDescription
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 aircraftcost 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 containscostB 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
题目分析
两架飞机装人,要求油费最少
飞机一定要装满人
飞机还可能不能装人,就为了弄个除0的坑
#include <stdio.h>
int main() {
long long total;
int count = 1;
while (scanf("%lld", &total)) {
if (total == 0)
break;
long long ca, pa, cb, pb;
scanf("%lld%lld%lld%lld", &ca, &pa, &cb, &pb);
bool judge = false;
if (pa == 0) {
if (pb == 0) {
printf("Data set %d: cannot be flown\n", count++);
} else {
if (total % pb != 0) {
printf("Data set %d: cannot be flown\n", count++);
} else {
printf("Data set %d: 0 aircraft A, %lld aircraft B\n",
count++, total / pb);
}
}
continue;
}
if (pb == 0) {
if (pa == 0) {
printf("Data set %d: cannot be flown\n", count++);
} else {
if (total % pa != 0) {
printf("Data set %d: cannot be flown\n", count++);
} else {
printf("Data set %d: %lld aircraft A, 0 aircraft B\n",
count++, total / pa);
}
}
continue;
}
if (ca * pb > cb * pa) {
judge = true;
long long temp;
temp = pa; pa = pb; pb = temp;
temp = ca; ca = cb; cb = temp;
}
long long numa = total / pa;
long long numb = 0;
total = total % pa;
while (total % pb != 0 && numa > 0) {
if (numa > 0) {
numa--;
total += pa;
} else {
break;
}
}
if (total % pb != 0) {
printf("Data set %d: cannot be flown\n", count++);
} else {
numb = total / pb;
if (judge) {
numa += numb;
numb = numa - numb;
numa = numa - numb;
}
printf("Data set %d: %lld aircraft A, %lld aircraft B\n",
count++, numa, numb);
}
}
return 0;
}
相关文章推荐
- The specified child already has a parent. You must call removeView() on the child's parent first.
- compiler之automatic memory management以及Java GC
- Anorm, simple SQL data access (play 2.4.x)
- MongoDB小结12 - update【多文档更新】
- 自定义圆形控件RoundImageView并认识一下attr
- GlusterFS复制卷修复原理以及脑裂分析
- 创业公司新品如何寻求科技媒体的报道?
- 防冲撞协议原理实验报告
- Android里面安装windows系统
- C语言宏定义技巧(常用宏定义)
- Installing PHP and the Oracle Instant Client for Linux and Windows For PHP 5.5, OCI8 2.0 and Oracle
- python自省函数的总结(源码剖析)
- 多标识AR例程分析(二)
- Python3下周百度页面实例
- Python模拟登陆(urllib2)
- 编译httpd 和 php
- MongoDB小结11 - update【save】
- Windows Server 2003 IIS支持ASP
- centos时间不同步网络问题
- iOS –app微信支付