当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
OJ 1505 保险丝
Redhawk Dynamic Analysis
What's a good gift for your girlfriend on the Chinese Valentine's day in 2022? Practical and beautiful gift recommendation
Current learning progress
浮点型数据在内存中如何存储
【C语言】字符串库函数介绍及模拟
pyppeteer 下拉 selenium下拉
Relative path and absolute path
QT implementation outputs relevant information to log file
NFT数藏盲盒+模式系统开发
Bug experience related to IAP jump of stm32
量化交易机器人系统开发
新的selenium
OJ 1242 大一上之初出茅庐
【自我救赎的开始】
Use and safe shutdown of qthread thread in QT
Solve the problem that the memory occupation is higher than that of the application process
JSP should pass parameters to the background while realizing the file upload function
JSON笔记
气传导耳机哪个好、性价比最高的气传导耳机推荐









