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 |
Re:why???????In Reply To:看 我的第一次 greedy haha AC Posted by:qqgyp at 2006-05-27 22:56:49 我这样做为什么不行啊!!!!!!!!!!!! #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { int n(0);vector<int> t; //t记录每个人所需要的时间 cin>>n; int m,v,i; while(n--) { cin>>m; for (i=0;i<m;i++) { cin>>v; t.push_back(v); } sort(t.begin(),t.end()); //将个人所需要的时间进行排序 long int useTime=0; for( i = m - 1;i >= 3;i -= 2) { if(2 * t[1] >= t[0] + t[i - 1])//方案1 useTime += 2 * t[0] + t[i - 1] + t[i]; else useTime += 2 * t[1] +t[0] + t[i]; //方案2 } if(i == 2)useTime += t[0] + t[1] + t[2]; if(i == 1)useTime += t[1]; if(i == 0)useTime += t[0]; cout<<useTime<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator