Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
wa了n多次,哪位大神帮我看看吧#include<stdio.h> #include<algorithm> using namespace std; int n,a[10020]; void init() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); } int slove1(int k) { if(k<3) return a[k]; if(k==3) return a[1]+a[2]+a[3]; int minute; if(a[k-1]+a[1]<2*a[2]) minute=2*a[1]+a[k]+a[k-1]; else minute=2*a[2]+a[1]+a[k]; minute+=slove1(k-2); return minute; } void slove2(int k) { if(k==1) {printf("%d\n",a[1]);return ;} if(k==2) {printf("%d %d\n",a[1],a[2]);return ;} if(k==3) {printf("%d %d\n%d\n%d %d",a[1],a[3],a[1],a[1],a[2]);return ;} if(a[k-1]+a[1]<2*a[2]) printf("%d %d\n%d\n%d %d\n,%d\n",a[1],a[k],a[1],a[1],a[k-1],a[1]); else printf("%d %d\n%d\n%d %d\n%d\n",a[1],a[2],a[1],a[k-1],a[k],a[2]); slove2(k-2); } int main() { init(); if(n==0) {printf("0\n");return 0;} printf("%d\n",slove1(n)); slove2(n); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator