1484 Blowing Fuses
来源:互联网 发布:淘宝零食店加盟 编辑:程序博客网 时间:2024/04/25 16:58
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.
CODE:
#include <stdio.h>#include <string.h>int main(int argc, char *argv[]) { int n,m,c,in[20],i,num,temp,i2=1,max;bool b[20],f;while(scanf("%d%d%d",&n,&m,&c)!=EOF&&(n||m||c)){memset(b,0,sizeof(b));num=0;f=false;max=0;for(i=0;i<n;++i)scanf("%d",&in[i]);for (i=0;i<m;++i){scanf("%d",&temp);--temp;if(!f){if(b[temp]){num-=in[temp];b[temp]=false;}else{num+=in[temp];b[temp]=true;max=max>num?max:num;}if(num>c)f=true;}}printf("Sequence %d\n",i2);if(!f){printf("Fuse was not blown.\n");printf("Maximal power consumption was %d amperes.\n",max);}else{printf("Fuse was blown.\n");}printf("\n");++i2;}return 0;}
- poj 1484 Blowing Fuses
- 1484 Blowing Fuses
- poj 1484 Blowing Fuses
- poj 1484Blowing Fuses
- poj 1484 Blowing Fuses
- POJ 1484 Blowing Fuses 笔记
- Blowing Fuses
- Blowing Fuses
- Blowing Fuses
- POJ 1484 Blowing Fuses(水~)
- fjnu 1685 Blowing Fuses
- zoj 1195 Blowing Fuses
- ZOJ1195 Blowing Fuses
- 661 - Blowing Fuses
- ZOJ 1195 Blowing Fuses
- poj1484 Blowing Fuses
- UVa 661 - Blowing Fuses
- poj1484||zoj1195 Blowing Fuses (模拟)
- CUDA程序开发
- OpenGL-绘制管线
- OpenGL-鼠标交互
- 错误 1 error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 M
- OpenGL-显示列表
- 1484 Blowing Fuses
- MVC思想精髓
- 默认环境变量 PATH
- 技术人员谈管理之质量管理失败原因和提高方法
- 对PInvoke函数...的调用堆栈不对称
- OpenGL-选择与拾取
- System of Equations
- ios5.1.1越狱实践
- Modern C++ Design 繁体版勘误1