标题:ZOJ 1195总是超时,不知道是哪的错
只看楼主
雅雅
Rank: 2
等 级:论坛游民
帖 子:38
专家分:34
注 册:2010-7-4
结帖率:80%
已结贴  问题点数:10 回复次数:5 
ZOJ 1195总是超时,不知道是哪的错
程序如下:
#include<stdio.h>
#define N 1000
int main()
{
    int n,m,c,d=0;
    int i,ci[N];

    while(scanf("%d%d%d",&n,&m,&c))
    {
        if(m==0 && n==0 &&c==0)
            break;
        d++;
        for(i=0;i<(m+n);i++)
            scanf("%d",&ci[i]);
        printf("Sequence %d\n",d);
        if(ci[m-1]+ci[n-1]>c)
            printf("Fuse was blown.\n");
        else
        {
            printf("Fuse was not blown.\n");
            printf("Maximal power consumption was %d amperes.\n",ci[m-1]+ci[n-1]);
        }
        printf("\n");
    }
    return 0;
}
搜索更多相关主题的帖子: ZOJ 超时 
2010-07-15 20:34
雅雅
Rank: 2
等 级:论坛游民
帖 子:38
专家分:34
注 册:2010-7-4
得分:0 
有人知道是怎么回事吗?
2010-07-18 20:31
草狼
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:577
专家分:1040
注 册:2010-4-6
得分:0 
把while(scanf("%d%d%d",&n,&m,&c))
改成 while(~scanf("%d%d%d",&n,&m,&c))或 while(scanf("%d%d%d",&n,&m,&c)!=EOF)

2010-07-18 20:58
雅雅
Rank: 2
等 级:论坛游民
帖 子:38
专家分:34
注 册:2010-7-4
得分:0 
回复 3楼 草狼
我试过了,不行的
2010-07-18 21:08
草狼
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:577
专家分:1040
注 册:2010-4-6
得分:10 
我也得代码 能AC了

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,m,i,c,sum,max,tem=0;
    int p[10000],q[10000],w[10000],e[10000];
    while(~scanf("%d%d%d",&n,&m,&c))
    {
        tem++;
        for(i=0;i<10000;i++) w[i]=0;
        if(n==0&&m==0&&c==0) break;
        for( i=0;i<n;i++)
            scanf("%d",&p[i]);
        for(i=0;i<m;i++)
        {
            scanf("%d",&q[i]);
            w[q[i]]++;
            e[i]=w[q[i]];
        }
        sum=0,max=-1;
        for(i=0;i<m;i++)
        {
            if(e[i]%2!=0)
                sum+=p[q[i]-1];
            else
                sum-=p[q[i]-1];
            if(sum>max)
                max=sum;
        }
        printf("Sequence %d\n",tem);
        if(max<=c)
            printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n\n",max);
        else
            printf("Fuse was blown.\n\n");
    }
    return 0;
}
2010-07-19 07:47
雅雅
Rank: 2
等 级:论坛游民
帖 子:38
专家分:34
注 册:2010-7-4
得分:0 
回复 4楼 雅雅
谢谢你!!!

其实是我也理解错题意了...
2010-07-19 09:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-313098-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.281252 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved