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

Re:为什么会wa呢?

Posted by geek at 2007-07-11 00:01:17 on Problem 3253
In Reply To:为什么会wa呢? Posted by:cpp00548001 at 2007-07-10 18:53:53
> #include<iostream.h>
> #include<stdlib.h>
> int compare(const void *ele1,const void * ele2)
> {
> 	return (*(int*)ele1)-(*(int*)ele2);
> }
> void main()
> {
> 	int pieces[20000];
> 	int num;
> 	cin>>num;
> 	for(int i=0;i<num;i++)
> 	{
> 		cin>>pieces[i];
> 	}
> 	qsort((void*)pieces,num,sizeof(pieces[0]),compare);
> 	int cost=0;
> 	int temp;
> 	for(i=1;i<num;i++)
> 	{
> 		pieces[i]=pieces[i]+pieces[i-1];
> 		cost+=pieces[i];
> 
> 		temp=pieces[i];
> 		for(int j=i+1;j<num;j++)
> 		{
> 			if(temp>pieces[j])
> 			{
> 				pieces[j-1]=pieces[j];
> 			}
> 			else {break;}
> 		}
> 		pieces[j-1]=temp;
> 	}
> 	cout<<cost<<endl;
> }
把cost的类型改成long long 就可以了

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