POJ 1484 Blowing Fuses(我的水题之路——我必须在心中牢记这次惨痛的教训)
2012-01-30 17:32
471 查看
Blowing Fuses
Description
Maybe you are familiar with the following situation. You have plugged in a lot of electrical devices, such as toasters, refrigerators, microwave ovens, computers, stereos, etc, and have them all running. But at the moment when you turn on the TV, the fuse blows,
since the power drawn from all the machines is greater than the capacity of the fuse. Of course this is a great safety feature, avoiding that houses burn down too often due to fires ignited by overheating wires. But it is also annoying to walk down to the
basement (or some other inconvenient place) to replace to fuse or switch it back on.
What one would like to have is a program that checks before turning on an electrical device whether the combined power drawn by all running devices exceeds the fuses capacity (and it blows), or whether it is safe to turn it on.
Input
The input consists of several test cases. Each test case describes a set of electrical devices and gives a sequence of turn on/off operations for these devices.
The first line of each test case contains three integers n, m and c, where n is the number of devices (n <= 20), m the number of operations performed on these devices and c is the capacity of the fuse (in Amperes). The following n lines contain one positive
integer ci each, the consumption (in Amperes) of the i-th device.
This is followed by m lines also containing one integer each, between 1 and n inclusive. They describe a sequence of turn on/turn off operations performed on the devices. For every number, the state of that particular devices is toggled, i.e. if it is currently
running, it is turned off, and if it is currently turned off, it will by switched on. At the beginning all devices are turned off.
The input will be terminated by a test case starting with n = m = c = 0. This test case should not be processed.
Output
For each test case, first output the number of the test case. Then output whether the fuse was blown during the operation sequence. The fuse will be blown if the sum of the power consumptions ci of turned on devices at some point exceeds the capacity of the
fuse c.
If the fuse is not blown, output the maximal power consumption by turned on devices that occurred during the sequence.
Output a blank line after each test case.
Sample Input
Sample Output
Source
Southwestern European Regional Contest 1998
首先,这道题是一道水题(非常弱弱的说)。
这道题先给你3个数字,表示有n个电器,m次操作,电流最高流量c。之后有n个数,表示每一个电器打开时候产生的电流,接着有m个操作步骤,用数字表示,分别表示操作哪个设备,第奇数次操作是打开该设备,第偶数次操作是关闭该设备。看在所有步骤操作完之前,电流总量是否要比c大,如果是,则熔丝会烧断,如果不会,则输出不会烧断,并且输出操作过程中的最大电流量。
解题很简单,是现对于所有的设备电流保存下来,然后对于每一次操作,如果是打开,就让电流数加上打开设备的电流量。如果是关闭,就在电流数上减去设备电流。
注意点:
1)提交前要去除调试printf代码(1OLE)
2)虽然在操作过程中可能电流量已经大于c,但是不能直接break,要把所有的数据读完才能输出,否则会OLE。(2OLE)
3)不要怀疑自己已经很熟悉的C语言基础知识,比如“把输出格式的两个‘\n’分在两个printf,会有不一样的效果”,这种思维是极度错误的(1WA)
4)不要忘记去除freopen(1WA)
代码(1AC 2WA 3OLE 人生在挫折中成长/(ㄒoㄒ)/~~):
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2652 | Accepted: 1056 |
Maybe you are familiar with the following situation. You have plugged in a lot of electrical devices, such as toasters, refrigerators, microwave ovens, computers, stereos, etc, and have them all running. But at the moment when you turn on the TV, the fuse blows,
since the power drawn from all the machines is greater than the capacity of the fuse. Of course this is a great safety feature, avoiding that houses burn down too often due to fires ignited by overheating wires. But it is also annoying to walk down to the
basement (or some other inconvenient place) to replace to fuse or switch it back on.
What one would like to have is a program that checks before turning on an electrical device whether the combined power drawn by all running devices exceeds the fuses capacity (and it blows), or whether it is safe to turn it on.
Input
The input consists of several test cases. Each test case describes a set of electrical devices and gives a sequence of turn on/off operations for these devices.
The first line of each test case contains three integers n, m and c, where n is the number of devices (n <= 20), m the number of operations performed on these devices and c is the capacity of the fuse (in Amperes). The following n lines contain one positive
integer ci each, the consumption (in Amperes) of the i-th device.
This is followed by m lines also containing one integer each, between 1 and n inclusive. They describe a sequence of turn on/turn off operations performed on the devices. For every number, the state of that particular devices is toggled, i.e. if it is currently
running, it is turned off, and if it is currently turned off, it will by switched on. At the beginning all devices are turned off.
The input will be terminated by a test case starting with n = m = c = 0. This test case should not be processed.
Output
For each test case, first output the number of the test case. Then output whether the fuse was blown during the operation sequence. The fuse will be blown if the sum of the power consumptions ci of turned on devices at some point exceeds the capacity of the
fuse c.
If the fuse is not blown, output the maximal power consumption by turned on devices that occurred during the sequence.
Output a blank line after each test case.
Sample Input
2 2 10 5 7 1 2 3 6 10 2 5 7 2 1 2 3 1 3 0 0 0
Sample Output
Sequence 1 Fuse was blown. Sequence 2 Fuse was not blown. Maximal power consumption was 9 amperes.
Source
Southwestern European Regional Contest 1998
首先,这道题是一道水题(非常弱弱的说)。
这道题先给你3个数字,表示有n个电器,m次操作,电流最高流量c。之后有n个数,表示每一个电器打开时候产生的电流,接着有m个操作步骤,用数字表示,分别表示操作哪个设备,第奇数次操作是打开该设备,第偶数次操作是关闭该设备。看在所有步骤操作完之前,电流总量是否要比c大,如果是,则熔丝会烧断,如果不会,则输出不会烧断,并且输出操作过程中的最大电流量。
解题很简单,是现对于所有的设备电流保存下来,然后对于每一次操作,如果是打开,就让电流数加上打开设备的电流量。如果是关闭,就在电流数上减去设备电流。
注意点:
1)提交前要去除调试printf代码(1OLE)
2)虽然在操作过程中可能电流量已经大于c,但是不能直接break,要把所有的数据读完才能输出,否则会OLE。(2OLE)
3)不要怀疑自己已经很熟悉的C语言基础知识,比如“把输出格式的两个‘\n’分在两个printf,会有不一样的效果”,这种思维是极度错误的(1WA)
4)不要忘记去除freopen(1WA)
代码(1AC 2WA 3OLE 人生在挫折中成长/(ㄒoㄒ)/~~):
#include <cstdio> #include <cstdlib> #include <cstring> int n, m, c; int cap[25]; int turn[25]; int main(void){ int max, tmp; int ii, i, j; int oprate; ii = 0; while (scanf("%d%d%d", &n, &m ,&c), n != 0 && m != 0 && c != 0){ ii++; tmp = max = 0; memset(cap, 0, sizeof(cap)); memset(turn, 0, sizeof(turn)); for (i = 1; i <= n; i++){ scanf("%d", &cap[i]); } for (i = 0; i < m ; i++){ scanf("%d", &oprate); if (max == -1){ continue; } if (turn[oprate] == 0){ tmp += cap[oprate]; if (tmp > max){ max = tmp; } if (max > c){ max = -1; continue; } turn[oprate] = 1; } else if (turn[oprate] == 1){ tmp -= cap[oprate]; turn[oprate] = 0; } } printf("Sequence %d\n", ii); if (max == -1){ printf("Fuse was blown.\n"); } else{ printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n", max); } printf("\n"); } return 0; }
相关文章推荐
- POJ 1118 Lining Up(我的水题之路——斜率最多)
- POJ 1207 The 3n+1 problem(我的水题之路——输入输出要保持原有顺序)
- POJ 1326 Mileage Bank(我的水题之路——模拟,四舍五入)
- POJ 1504 Adding Reversed Numbers(我的水题之路——逆向数高精度加法)
- POJ 2019 Cornfields(我的水题之路——多case??TLE??)
- POJ 2459 Feed Accounting(我的水题之路——英文题啊!!!)
- POJ 3086 Triangular Sums(我的水题之路——三角数累加)
- POJ 3224 Go for Lab Cup!(我的水题之路——赢的场数最多)
- POJ 1247 Magnificent Meatballs(我的水题之路——数组两边求和)
- POJ 1528 Perfection(我的水题之路——因子之和)
- POJ 1656 Counting Black(我的水题之路——表格涂色)
- POJ 2328 Guessing Game(我的水题之路——猜数字测谎)
- POJ 2538 WERTYU(我的水题之路——键盘错位)
- POJ 3096 Surprising Strings(我的水题之路——重点,D-pairs)
- POJ 3300 Tour de France(我的水题之路——车轮角速度最大)
- 惨痛的教训啊,必须要检查函数的返回类型
- POJ 1543 Perfect Cubes(我的水题之路——四重暴力水)
- POJ 1580 String Matching(我的水题之路——字符串公共子串的比较雏形)
- POJ 1658 Eva's Problem(我的水题之路——等差or等比)
- POJ 2028 When Can We Meet?(我的水题之路——边输入,边搜索)