superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ZOJ 1195 - Blowing Fuses

Posted on 2008-04-13 09:50 superman 阅读(287) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
 1 /* Accepted 1195 C++ 00:00.00 844K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n, m, fuse, sequence = 0;
 9     while((cin >> n >> m >> fuse) && n && m && fuse)
10     {
11         sequence++;
12         cout << "Sequence " << sequence << endl;
13         
14         int c[21= {0};
15         for(int i = 1; i <= n; i++)
16             cin >> c[i];
17         
18         int cnt = 0, max = 0, t;
19         bool state[21= {false}, blown = false;
20         for(int i = 0; i < m; i++)
21         {
22             cin >> t;
23             if(blown)
24                 continue;
25             
26             state[t] ^= 1;
27             max >?= cnt += (state[t] ? c[t] : -c[t]);
28             
29             if(cnt > fuse)
30             {
31                 blown = true;
32                 cout << "Fuse was blown." << endl;
33             }
34         }
35         if(blown == false)
36             cout << "Fuse was not blown." << endl
37                  << "Maximal power consumption was " << max << " amperes." << endl;
38         cout << endl;
39     }
40     
41     return 0;
42 }
43 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理