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

兄弟,先从大到小排序再求和就行了

Posted by sunmoonstar_love at 2005-08-07 10:01:36 on Problem 2487
In Reply To:牛人们;帮我查一下错误(附源码)这么简单的题你们看一眼就OK!!! Posted by:aaasssaaasss at 2005-08-07 09:46:26
> #include<stdio.h>
> int main()
> {
> 	int i,j,t;
> 	int n,m,p=0;
> 	int a[1000],b[1000];
> 	long k,sum;
> 	scanf("%d",&n);
> 	while(p<n)
> 	{
> 		sum=0;
> 		scanf("%ld%d",&k,&m);
> 		for(i=0;i<m;i++)
> 		    scanf("%d",&a[i]);
> 		
> 		for(i=0;i<m-1;i++)
> 		{
> 		    for(j=m-1;j>=i;j--)
> 			{
> 			    if(a[j]<a[j+1])
> 				{
> 				    t=a[j+1];a[j+1]=a[j];a[j]=t;
> 				}
> 			}
> 		    sum+=a[i];
> 		    if(sum<k)
> 			    b[p]=i+2;
> 		}
> 	    if(sum<k)
> 		    b[p]=0;
> 	    p++;
> 	}
> 	for(i=0;i<n;i++)
> 	{
> 		printf("Scenario #%d:\n",i+1);
> 		if(b[i]==0)
> 			printf("impossible\n");
> 		if(b[i]!=0)
> 			printf("%d\n",b[i]);
> 		printf("\n");
> 	}
> 	return 1;
> }

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