2011年11月5日星期六

POJ 1484 Blowing Fuses


#include
int main()
{
int n,m,c,i,count = 1;
while(scanf("%d%d%d",&n,&m,&c) &&  n){
int dev[21]={0},flag[21]={0},max = 0,sum = 0;
for(i = 1;i <= n;i ++)
scanf("%d",&dev[i]);
while(m --){
scanf("%d",&i);
if(!flag[i]){
flag[i] = 1;
sum += dev[i];
}
else {flag[i] = 0;sum -= dev[i];}
if(sum > max)max = sum;
}
printf("Sequence %d\n",count);
if(max > c)printf("Fuse was blown.\n\n");
else printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n\n",max);
count ++;
}
return 0;
}



思路清晰,简单明了。模拟水题。。。。。
开一个判断数组,关了的就开,然后累计负载;开了的就关,释放负载,过程中记录最大值。

没有评论:

发表评论