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

为什么总是wa?疑惑!大街帮帮忙看一小下。:[

Posted by TTYYuan at 2006-03-03 10:18:35 on Problem 2487
#include <iostream>
using namespace std;
int main()
{
	int sceNum,staNum,perNum,sum,d;
	int result=0;
	int i=0;
	int j=0;
	int U[1000];
	int V[1000];
	while(cin>>sceNum)
	{
		if(!sceNum)
			break;
		for(int i=0;i<sceNum;i++)//输入该组需要邮票数和人数
		{
			cin>>staNum>>perNum;
			for(int j=0;j<perNum;j++)//将每人邮票数录入数组
				cin>>U[j];
			//冒泡排序
			for(int a=0;a<perNum;a++)
				for(int b=a+1;b<perNum;b++)
				{
					if(U[a]<U[b])
					{
						int temp=U[a];
						U[a]=U[b];
						U[b]=temp;
					}
				}
			//求和
			sum=result=d=0;
			while (sum<staNum)
			{
				sum+=U[d];
				d++;
				if(sum>=staNum||d>perNum)
					break;
				
			}
			V[i]=d;
		}
		for(i=0;i<sceNum;i++)
		{
			cout<<"Scenario #"<<i+1<<':'<<endl;
			if(V[i]<=perNum)
				cout<<V[i]<<endl<<endl;
		    else
			    cout<<"impossible"<<endl<<endl;
		}
		
	}
	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