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

why wa????? sp 有问题? 还是偶写错了? 另题过了

Posted by CydorniaKnight at 2009-04-12 15:22:35 on Problem 3370
#include<iostream>
using namespace std;

#define maxn 100010

int c,n,sign[maxn],num[maxn],sum[maxn];

int main()
{
	int i,j,a,b,flag;
	while(scanf("%d%d",&c,&n)){
		if(0==c&&0==n) break;
		flag=1;
		for(i=0;i<n;++i)
		{
			sign[i]=0;
			scanf("%d",&num[i]);
		}
		if(1==c){
			printf("1");
			for(i=2;i<=n;++i)
				printf(" %d",i);
			printf("\n");
			continue;
		}
		for(sum[0]=i=0;i<n;++i)
		{
			sum[i+1]=sum[i]+num[i];
		}
		j=1;
		for(i=1;i<=n;++i)
		{
			if(sign[sum[i]%c]){
				j=0;
				flag=0;
				break;
			}else{
				sign[sum[i]%c]=i;
				if(0==sum[i]%c){
					flag=0;
					break;
				}
			}
		}
		if(flag) printf("no sweets\n");
		if(j){
			printf("1");
			for(i=2;i<=sign[0];++i)
				printf(" %d",i);
			printf("\n");
		}else{
			b=i;
			a=sign[sum[i]%c];
			printf("%d",a+1);
			for(i=a+2;i<=b;++i)
				printf(" %d",i);
			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