Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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: