博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1484 Blowing Fuses
阅读量:4973 次
发布时间:2019-06-12

本文共 3842 字,大约阅读时间需要 12 分钟。

Blowing Fuses

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 2584

Accepted: 1029

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

2 2 1057123 6 102572123130 0 0

Sample Output

Sequence 1Fuse was blown.Sequence 2Fuse was not blown.Maximal power consumption was 9 amperes.

 

1: #include
2: using namespace std;
3: int main()
4: {
5: 	int n,m,c;
6: 	int consumption[30];
7: 	int flag[30];
8: 	int i,j;
9: 	int sum;
10: 	int operation;
11: 	int cases=0;
12: 	int burned;
13: 	int max_sum;
14: //	freopen("E:\\c++\\oj\\t.txt","rt",stdin);
15: 	while(1)
16: 	{
17: 		cin>>n>>m>>c;
18: 		if(n==0&&m==0&&c==0)
19: 			break;
20: 		cases++;
21: 		for(j=1;j<=n;j++)
22: 			cin>>consumption[j];
23: 		sum=0;
24: 		burned=0;
25: 		max_sum=0;
26: 		memset(flag,0,sizeof(flag));
27: 		for(i=0;i
28: 		{
29: 			cin>>operation;
30: 			if(burned==1)
31: 				continue;
32: 			if(flag[operation]==0)
33: 			{
34: 				flag[operation]=1;
35: 				sum+=consumption[operation];
36: 				if(sum>c)
37: 				{
38: 					cout<<"Sequence "<
<
39: 					cout<<"Fuse was blown."<
<
40: 					burned=1;
41: 				}
42: 				else if(sum>max_sum)
43: 				{
44: 					max_sum=sum;
45: 				}
46: 			}
47: 			else
48: 			{
49: 				sum-=consumption[operation];
50: 				flag[operation]=0;
51: 			}
52: 		}
53: 		if(burned==0)
54: 		{
55: 			cout<<"Sequence "<
<
56: 			cout<<"Fuse was not blown."<
57: 			cout<<"Maximal power consumption was "<
<<" amperes."<
<
58: 		}
59: 	}
60: 	return 0;
61: }
62:
63:

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/21/2257541.html

你可能感兴趣的文章
【LaTeX】E喵的LaTeX新手入门教程(1)准备篇
查看>>
highcharts曲线图
查看>>
extjs动态改变样式
查看>>
PL/SQL Developer 查询的数据有乱码或者where 字段名=字段值 查不出来数据
查看>>
宏定义
查看>>
笔记:git基本操作
查看>>
生成php所需要的APNS Service pem证书的步骤
查看>>
JavaWeb之JSON
查看>>
HOT SUMMER 每天都是不一样,积极的去感受生活 C#关闭IE相应的窗口 .
查看>>
windows平台上编译mongdb-cxx-driver
查看>>
optionMenu-普通菜单使用
查看>>
2016-2017-2点集拓扑作业[本科生上课时]讲解视频
查看>>
【MemSQL Start[c]UP 3.0 - Round 1 C】 Pie Rules
查看>>
Ognl中“%”、“#”、“$”详解
查看>>
我对应用软件——美团的看法
查看>>
执行了的程序,才是你的程序.
查看>>
struts2.x + Tiles2.x读取多个xml 配置文件
查看>>
表单校验之datatype
查看>>
python第六篇文件处理类型
查看>>
ubuntu16系统磁盘空间/dev/vda1占用满的问题
查看>>