当前位置:网站首页>OJ 1505 保险丝
OJ 1505 保险丝
2022-07-28 05:26:00 【JETECHO】
描述
现有n个设备,标号分别从1到n,第i个设备的用电量为c[i]。我们有一保险丝,当当前设备使用电量之和超过保险丝的总容量时则会跳闸。接下来有m次操作,初始化所有设备都为关闭状态,每操作一次则改变状态,若当前状态为开启,那么操作完毕后则变为关闭,反之亦然。
输入
测试数据有多组。
输入第一行有3个整数,n、m、c,n(n<=20)表示设备的个数,c表示保险丝的总容量。
接下来有n行,每行一个数字,第i行表示第i个设备的容量。 接下来有m行,每行一个数字k,表示掰动第k个设备的开关。
当n、m、c都为0时,输入结束。
输出
对于每个样例,先输出样例号(见样例),若跳闸了则输出“Fuse was blown.”(引号不输出)。否则先输出“Fuse was not blown.”,然后另起一行输出在进行设备开关的过程中最大的用电量。
具体格式参见样例。
每个样例的最后输出一个空行。
输入样例 1
2 2 10
5
7
1
2
3 6 10
2
5
7
2
1
2
3
1
3
0 0 0
输出样例 1
Sequence 1
Fuse was blown.
Sequence 2
Fuse was not blown.
Maximal power consumption was 9 amperes.
题目说每触发一次就可以改变一次状态,每改变一次状态都意味着电压的加和减,那么可以使用二维数组,第二行表示等的状态,将其初始化为-1每次改变状态就乘-1,对于每次次电压的变化可以为乘以-1之后的第二行乘以第一行的数据,这样就可以达到关闭减电压打开加电压的功能了,同时再统计做大电压。保险丝就使用一个特征变量控制即可,保证被更改之后可以表示跳闸即可即可。
#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;
}
边栏推荐
猜你喜欢

开放式耳机推荐哪款最好、性价比最高的开放式耳机

七夕送女朋友什么礼物好?不会送礼的男生速看!

什么气传导蓝牙耳机好、配置比较高的气传导耳机推荐

Hugging face's problem record I

QT implementation outputs relevant information to log file

What's a good gift for your girlfriend on the Chinese Valentine's day in 2022? Practical and beautiful gift recommendation

1、 Ffmpeg record audio as PCM file

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

夹子套利/搬砖套利系统开发

Icc2 (III) clock tree synthesis
随机推荐
【动态规划--买卖股票的最佳时期系列3】
Filter
如何模拟实现strcpy库函数
[server usage record] log in to the remote server through the springboard machine and transfer files
开放式耳机有哪些、四款音质超好的气传导耳机推荐
小程序:生命周期
Servlet
QT parse string into JSON data and parse
ubuntu mysql 设置远程访问权限
Use and safe shutdown of qthread thread in QT
当前学习进度
QT solves the problem of rebuilding UI files every time they are modified
转义字符笔记
1、 Ffmpeg record audio as PCM file
error: redefinition of ‘xxx‘
IP地址的五大分类
JSP should pass parameters to the background while realizing the file upload function
ubunut 服务器上传下载文件
C语言memcpy库函数与memmove的作用
My notes