Algorithm 版 (精华区)
发信人: pamws (书虫), 信区: Algorithm
标 题: 1195K-Blowing Fuses-ZJU
发信站: 哈工大紫丁香 (2002年10月09日17:27:21 星期三), 站内信件
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#define ONLINE_JUDGE 1
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("1195.in", "r", stdin);
freopen("1195.out", "w", stdout);
#endif
int cnt=0;
int n, m, c;
int i;
while (scanf("%d %d %d", &n, &m, &c)!=EOF) {
if ((n==0) && (m==0) && (c==0)) break;
cnt+=1; printf("Sequence %d\n", cnt);
int * device=new int[n]; memset(device, 0, n*sizeof(int));
bool * state=new bool[n]; memset(state, 0, n*sizeof(bool));
for (i=0; i<n; i++) {
scanf("%d", &device[i]);
}
int dev;
int fuse=0; int max=0;
for (i=0; i<m; i++) {
scanf("%d", &dev); dev-=1;
state[dev]=!state[dev];
if (state[dev]) {
fuse+=device[dev];
if (fuse>max) max=fuse;
} else {
fuse-=device[dev];
}
}
if (max>c) {
printf("Fuse was blown.\n");
} else {
printf("Fuse was not blown.\n");
printf("Maximal power consumption was %d amperes.\n", max);
}
printf("\n");
}
return 0;
}
--
I Love Google...
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.226.228]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:5.650毫秒