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

过了贴代码攒rp

Posted by 1000010314 at 2012-01-18 14:01:39 on Problem 3370
#include <string.h>
#include <stdio.h>
using namespace std;

int duplicate(int * a,int n)
{
    bool b[n];
    memset(b,1,sizeof(b));
    for(int i=0;i<n;i++)
    {
        if(b[a[i]]==false){return a[i];}
        b[a[i]]=false;
    }
    return 0;
}

int find(int * a,int n,int start,int target)
{
    for(int i=start;i<n;i++)
    {
        if(a[i]==target){return i;}
    }
    return -1;
}

int main()
{
    int c,n;
    while(scanf("%d %d\n",&c,&n))
    {
        if(c==0&&n==0){return 0;}
        int a,sum=0;
        int * b=new int [n];
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            sum+=a;sum%=c;
            b[i]=sum;
        }
        sum=duplicate(b,c);
        if(!sum)
        {
            int d=find(b,c,0,0);
            for(int i=0;i<=d;i++)
            {
                printf("%d ",i+1);
            }
            printf("\n");
        }
        else
        {
            int i=find(b,c,0,sum);
            int j=find(b,c,i+1,sum);
            for(int k=i+1;k<=j;k++)
            {
                printf("%d ",k+1);
            }
            printf("\n");
        }
    }
    return 0;
}

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