当前位置:网站首页>OJ 1505 fuse
OJ 1505 fuse
2022-07-28 06:38:00 【JETECHO】
describe
existing n Devices , The labels are from 1 To n, The first i The power consumption of devices is c[i]. We have a fuse , When the sum of the current power consumption of the equipment exceeds the total capacity of the fuse, it will trip . Next there is m operations , Initialize that all devices are turned off , Each operation changes the state , If the current status is on , Then it will turn off after the operation , vice versa .
Input
There are multiple sets of test data .
The first input line has 3 It's an integer ,n、m、c,n(n<=20) Indicates the number of devices ,c Indicates the total capacity of the fuse .
Next there is n That's ok , One number per line , The first i Line representation i Capacity of devices . Next there is m That's ok , One number per line k, It means breaking the second k Switch of a device .
When n、m、c All for 0 when , End of input .
Output
For each example , First output the sample number ( See Example ), If it trips, it outputs “Fuse was blown.”( Quotation marks are not output ). Otherwise, output “Fuse was not blown.”, Then start another line to output the maximum power consumption in the process of switching the equipment .
See the example for the specific format .
The last output of each sample is a blank line .
sample input 1
2 2 10
5
7
1
2
3 6 10
2
5
7
2
1
2
3
1
3
0 0 0
sample output 1
Sequence 1
Fuse was blown.
Sequence 2
Fuse was not blown.
Maximal power consumption was 9 amperes.
The title says that each trigger can change the state , Every change of state means the addition and subtraction of voltage , Then you can use a two-dimensional array , The second line indicates the status of etc , Initialize it to -1 Multiply every time you change state -1, For each voltage change, it can be multiplied by -1 Then multiply the second row by the data of the first row , In this way, the function of closing the voltage reduction and opening the voltage increase can be achieved , At the same time, increase the voltage . The fuse can be controlled with a characteristic variable , Ensure that it can indicate tripping after being changed .
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int n,m,c,cont=1;;
while(cin>>n>>m>>c&&(n||m||c))
{
int a[n+1][2];
memset(a,-1,sizeof(a));
for(int i=1;i<=n;i++)
cin>>a[i][0];
int sum=0,MAX=0;
bool flag=true;
while(m--)
{
int x;
cin>>x;
a[x][1]*=-1;
sum+=a[x][1]*a[x][0];
if(sum>c)
flag=false;
else
{
if(sum>MAX)
MAX=sum;
}
}
if(!flag)
printf("Sequence %d\nFuse was blown.\n\n",cont);
else
printf("Sequence %d\nFuse was not blown.\nMaximal power consumption was %d amperes.\n\n",cont,MAX);
cont++;
}
return 0;
}
边栏推荐
猜你喜欢

夹子套利/搬砖套利系统开发
![[PTA----输出全排列]](/img/66/d1699cd55fa5ff4a55e3e150d02c1b.png)
[PTA----输出全排列]

2022-06-07 ResponseBodyAdvice导致Swagger出现弹框问题

What's a gift for girls on Chinese Valentine's day? Selfie online and thoughtful gift recommendation

Get the current directory in QT

【C笔记】数据类型及存储

Leetcode 刷题日记 剑指 Offer II 048. 序列化与反序列化二叉树

SSAO By Computer Shader(一)

What's a good gift for your girlfriend on Chinese Valentine's day? Boys who can't give gifts, look!

[PTA--利用队列解决猴子选大王问题】
随机推荐
scrapy 命令
量化交易机器人系统开发
刷题记录----反转链表(反转整个链表)
set_ multicycle_ path
气传导蓝牙耳机什么牌子好、气传导耳机最好的品牌推荐
【实现简易版扫雷小游戏】
OJ 1045 reverse and add
C语言memcpy库函数与memmove的作用
SSAO By Computer Shader(一)
【C笔记】数据类型及存储
Leetcode 刷题日记 剑指 Offer II 050. 向下的路径节点之和
七夕礼物送女生什么好?颜值在线又有心意的礼物推荐
OJ 1242 大一上之初出茅庐
2022年七夕礼物推荐!好看便宜又实用的礼物推荐
Listener
STM32的IAP跳转相关bug经历
scrapy 定时执行
What is the best and most cost-effective open headset recommended
NFT data storage blind box + mode system development
2022-05-15 based on JWT token