ZOJ1195 Blowing Fuses

这道ZOJ的水题~~~让我认识了ZOJ的Segmentation Fault。坑爹~~尼玛坑爹~~输出的过程居然不能有for循环的处理程序,只能单独隔离输入,即先要保存输入。算算了,算是ZOJ的奇葩吧~~

AC program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<queue>
#include<map>
using namespace std;
int main()
{
int nn[25];
int ff[25]; 
int mm[1000];
int n,m,c;
int cas=1; 
while(cin>>n>>m>>c,n+m+c)
{
    for(int i=1;i<=n;i++)
       cin>>nn[i];
    for(int i=1;i<=m;i++)
       cin>>mm[i];//要单独输入,和下面的处理一起在for循环的话
                  //就会出现Segmentation Fault 
                  //ZOJ奇葩错误 
    memset(ff,0,sizeof(ff));
    int sum=0; 
    int max=-1; 
    int flag=0; 
    for(int i=1;i<=m;i++)
    {
       int t=mm[i];
       ff[t]=1-ff[t];
       if(ff[t]==1)
            {
               sum+=nn[t];
               if(max<sum)max=sum;
               if(sum>c)
                     {
                       flag=1;
                       break;             
                     } 
                     
            }
       else
           {
              sum-=nn[t];          
           }        
    }
    if(!flag)
        {
            printf("Sequence %d\n",cas++);
            printf("Fuse was not blown.\n");
            printf("Maximal power consumption was %d amperes.\n",max); 
        }
    else
        {
            printf("Sequence %d\n",cas++);
            printf("Fuse was blown.\n");
        } 
    cout<<endl;               
} 
//system("pause"); 
return 0;} 


这个博主也ORZ了:呵呵:http://blog.csdn.net/cherry_sun/article/details/6257498
 

你可能感兴趣的:(ZOJ1195 Blowing Fuses)