标签:style blog http os io for ar art
对于此问题有两种策略
1、最快的带最慢的和次慢的
2、最快和次快带最慢和次慢
此链接有详细解释点击打开链接<span style="font-size:18px;"><span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int s[1050]; int main() { int a; scanf("%d",&a); for(int i=0;i<a;i++) scanf("%d",&s[i]); if(a==1) { printf("%d\n%d\n",s[0],s[0]); return 0; } sort(s,s+a); int ans=a,cne,sum=0,d,e; while(ans>3) { int sum1=2*s[0]+s[ans-2]+s[ans-1]; int sum2=2*s[1]+s[0]+s[ans-1]; if(sum1>sum2) sum+=sum2; else sum+=sum1; ans-=2; } if(ans==3) printf("%d\n",sum+=s[0]+s[1]+s[2]); else printf("%d\n",sum+=s[1]); while(a>3) { if(s[0]+s[a-2]<2*s[1]) printf("%d %d\n%d\n%d %d\n%d\n",s[0],s[a-1],s[0],s[0],s[a-2],s[0]); else printf("%d %d\n%d\n%d %d\n%d\n",s[0],s[1],s[0],s[a-2],s[a-1],s[1]); a-=2; } if(a==3) printf("%d %d\n%d\n%d %d\n",s[0],s[2],s[0],s[0],s[1]); else printf("%d %d\n",s[0],s[1]); return 0; } </span></span>
poj 2573 Bridge (过桥问题 贪心),布布扣,bubuko.com
标签:style blog http os io for ar art
原文地址:http://blog.csdn.net/asuxiexie/article/details/38533379