题目大意:
保险丝熔断问题。给n,m,c,n代表电器的数量,m代表操作的数量,c代表保险丝容量。
解题思路:
按照输入模拟开关过程就好了
代码如下:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n,m,c,count=0;
int de[300],i,x,sum,max,flag;
int visit[300];
while(scanf("%d%d%d",&n,&m,&c)!=EOF&&(n||m||c))
{
count++;
flag=0;
for(i=1;i<=n;i++)
{
scanf("%d",&de[i]);
}
sum=max=0;
memset(visit,0,sizeof(visit));
for(i=1;i<=m;i++)
{
scanf("%d",&x);
if(!visit[x])
{
visit[x]=1;
sum=sum+de[x];
if(sum>c)
{
flag=1;
continue;
}
if(sum>max)
{
max=sum;
}
}
else
{
visit[x]=0;
sum=sum-de[x];
}
}
if(flag)
{
printf("Sequence %d\nFuse was blown.\n\n",count);
}
else
{
printf("Sequence %d\nFuse was not blown.\nMaximal power consumption was %d amperes.\n\n",count,max);
}
}
return 0;
}