fjnu 1685 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

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.
KEY:这题也不什么难题,我开了个数组flag来表示电器的开关,模拟一遍就可以了;

  
  
Source:

#include
< iostream >
using   namespace  std;

int  a[ 1000 ];
int  flag[ 1000 ];
int  n,m,c;

void  count()
{
    
int max=-1;
    
int sum=0;
    
int blown=0;
    
int x;
    
for(int i=1;i<=m;i++)
    
{
        cin
>>x;
        
if(flag[x]==0)
        
{
            sum
+=a[x];
            flag[x]
=1;
        }

        
else
        
{
            sum
-=a[x];
            flag[x]
=0;
        }

        
if(sum>c) blown=1;
        
else 
        
{
            
if(sum>max) max=sum;
        }

    }

    
if(blown) cout<<"Fuse was blown."<<endl;
    
else
    
{
        cout
<<"Fuse was not blown."<<endl;
        cout
<<"Maximal power consumption was "<<max<<" amperes."<<endl;
    }

}


void  input()
{
    
for(int i=1;i<=n;i++)
    
{
        cin
>>a[i];
        flag[i]
=0;
    }

}


int  main()
{
    
int N=1;
    
while(cin>>n>>m>>c)
    
{
        
if(n==0&&m==0&&c==0break;
        input();
        cout
<<"Sequence "<<N++<<endl;
        count();
        cout
<<endl;
    }

    
return 0;
}



        

        




 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好,以下是一个简单的使用HTML制作类似于"https://www.fjnu.edu.cn/main.htm"网页的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>福建师范大学</title> </head> <body> <header> <h1>福建师范大学</h1> </header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">学校概况</a></li> <li><a href="#">新闻中心</a></li> <li><a href="#">招生就业</a></li> <li><a href="#">校园生活</a></li> <li><a href="#">教学科研</a></li> <li><a href="#">校友服务</a></li> </ul> </nav> <main> <article> <h2>学校简介</h2> <p>福建师范大学创建于1907年,是福建省人民政府与教育部共建高校。学校主要办学特色是师范教育和人文社会科学,具有百年办学历史和深厚的文化底蕴。</p> </article> <section> <h2>新闻动态</h2> <ul> <li><a href="#">福建师范大学2021年迎新工作启动</a></li> <li><a href="#">2021年福建师范大学教师招聘公告</a></li> <li><a href="#">福建师范大学2021年本科招生计划</a></li> </ul> </section> </main> <aside> <h2>联系我们</h2> <p>地址:福建省福州市闽侯县上街镇</p> <p>电话:0591-83442777</p> <p>邮箱:fjnu@fjnu.edu.cn</p> </aside> <footer> <p>© 2021 福建师范大学</p> </footer> </body> </html> ``` 在这个示例中,我们使用HTML5标记语言来创建网页。我们通过`<header>`元素来定义网页的标题,通过`<nav>`元素来定义网页的主要导航,通过`<main>`元素来定义网页的主要内容,通过`<aside>`元素来定义网页的侧边栏内容,通过`<footer>`元素来定义网页的页脚。在`<main>`元素中,我们使用`<article>`元素来定义学校简介部分的内容,使用`<section>`元素来定义新闻动态部分的内容。网页的样式和布局可以通过CSS来实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值