Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么会TLE呀?好难过。。用的鸽笼定理,有没有哪个大神帮忙看看呀

Posted by wuxiaowu at 2017-12-12 17:10:44 on Problem 3370
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 100005
long long int a[N];
long long int sum[N];
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        if(m==0||n==0)
        {
            break;
        }
        else
        {
            for(int i=1; i<=m; i++)
            {
                scanf("%lld",&a[i]);
            }
            int pos=-1;
            sum[0]=0;
            for(int i=1; i<=m; i++)
            {
                sum[i]=(sum[i-1]+a[i])%n;
                if(sum[i]==0)
                {
                    pos=i;
                }
            }
            if(pos>0)
            {
                printf("%lld",1);
                for(int i=2; i<=pos; i++)
                {
                    printf(" %lld",i);
                }
                printf("\n");
            }
            else
            {

                int x,y;
                for(int i=1; i<=m; i++)
                {
                    for(int j=1; j<=i; j++)
                    {
                        if(sum[i]-sum[j]==0)
                        {
                            x=i;
                            y=j;
                            break;
                        }
                    }
                }
                printf("%lld",y+1);
                for(int k=y+2; k<=x; k++)
                {
                    printf(" %lld",k);
                }
                printf("\n");


            }

        }

    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator