POJ 1484 Blowing Fuses(我的水题之路——我必须在心中牢记这次惨痛的教训)
来源:互联网 发布:淘宝开店诈骗 编辑:程序博客网 时间:2024/05/22 08:39
Blowing Fuses
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2652 Accepted: 1056
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.
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.
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.
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 1057123 6 102572123130 0 0
Sample Output
Sequence 1Fuse was blown.Sequence 2Fuse 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 1484 Blowing Fuses(我的水题之路——我必须在心中牢记这次惨痛的教训)
- POJ 1484 Blowing Fuses(水~)
- poj 1484 Blowing Fuses
- poj 1484 Blowing Fuses
- poj 1484Blowing Fuses
- poj 1484 Blowing Fuses
- POJ 1484 Blowing Fuses 笔记
- 1484 Blowing Fuses
- 牢记这次的目的
- jQuery的惨痛教训
- 惨痛的教训
- Blowing Fuses
- Blowing Fuses
- Blowing Fuses
- 使用ConcurrentLinkedQueue惨痛的教训
- 惨痛的教训改用SVN
- 代码编写的惨痛教训
- flask 404 惨痛的教训
- POJ 1493 Machined Surfaces(我的水题之路——移动后的空格)
- MyEclipse优化加载速度和去掉一些没用的设置
- POJ 1488 TEX Quotes(我的水题之路——暴水,字符转换)
- CentOS 5.x 系统下使用yum 升级php到5.2.x
- 使用递归方式遍历指定磁盘路径下的文件及文件夹
- POJ 1484 Blowing Fuses(我的水题之路——我必须在心中牢记这次惨痛的教训)
- 学JAVA IO先学装饰模式
- POJ 1504 Adding Reversed Numbers(我的水题之路——逆向数高精度加法)
- C语言复习之结构体和指针
- 正则表达式实例
- java 静态代理与动态代理(代理模式)
- 关于JSF2.0的Resources
- web打印
- Linux中samba配置和windows映射Linux驱动盘