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:《挑战程序设计竞赛》这道题例程这个if是想干啥的??

Posted by Yi_iY at 2018-02-02 23:55:12 on Problem 3253
In Reply To:《挑战程序设计竞赛》这道题例程这个if是想干啥的?? Posted by:forestsea at 2017-08-31 23:18:39
> #include<iostream>
> #include<algorithm>
> #include<cstdio>
> using namespace std;
> typedef long long ll;
> int N,L[20001];
> void solve()
> {
> 	ll ans=0;
> 	while(N>1)
> 	{
> 		int mii1=0,mii2=1;
> 		if(L[mii1]>L[mii2])
> 		swap(mii1,mii2);
> 		
> 		for(int i=2;i<N;i++)
> 		{
> 			if(L[i]<L[mii1])
> 			{
> 				mii2=mii1;
> 				mii1=i;
> 			}
> 			else if(L[i]<L[mii2])
> 			mii2=i;
> 		}
> 		
> 		int t=L[mii1]+L[mii2];
> 		ans+=t;
> 		
> 		if(mii1==N-1)//就是这个if,去掉也AC了
> 		swap(mii1,mii2);
> 		
> 		L[mii1]=t; 
> 		L[mii2]=L[N-1];
> 		N--;
> 	}
> 	cout<<ans<<endl;
> }
> int main(void)
> {
> 	int i;
> 	while(scanf("%d",&N)!=EOF)
> 	{
> 		for(i=0;i<N;i++)
> 		cin>>L[i];
> 		solve();
> 	}
> 	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