浙江科技学院第十三届程序设计竞赛 1008 A Heavy Rainy Day 贪心
2016-03-28 16:38
525 查看
思路:可以分以最快和最慢的四个人为一组,或者最快的一个人和最慢的俩个人一组,比较用时最少的即可。
#include<map> #include<queue> #include<cmath> #include<cstdio> #include<stack> #include<iostream> #include<cstring> #include<algorithm> #define inf 0x3f3f3f3f #define eps 1e-8 #define mod 1000000007 #define ls l,mid,rt<<1 #define rs mid+1,rt,rt<<1|1 #define LL __int64 using namespace std; int nu[1010]; int main(){ int n,m,i,j,k,cla; while(~scanf("%d",&n)){ for(i = 0;i < n;++ i){ scanf("%d",&nu[i]); } int ans = 0; sort(nu,nu + n); while(n >= 4){ if(2*nu[0]+nu[n-2]+nu[n-1] > 2*nu[1]+nu[0]+nu[n-1]) ans += 2*nu[1]+nu[0]+nu[n-1]; else ans += 2*nu[0]+nu[n-2]+nu[n-1]; n -= 2; } if(n == 3) ans += nu[0]+nu[1]+nu[2]; else if(n == 2) ans += nu[1]; else ans += nu[0]; printf("%d\n",ans); } return 0; }
相关文章推荐
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- Jump Game I,II 贪心
- Wildcard Matching
- 贪心法实现无向图的划分 代码
- 贪心题目循环和控制台折行
- HDOJ 1009
- 【解题报告】【USACO】酸奶工厂
- 【解题报告】【】交谊舞
- POJ 1328
- Best Cow Line
- HDU 1009 Fatmouse's Trade
- POJ2377 Bad Cowtractors
- 贪心 hdu 1003
- 最大容器
- 满足和为定值的两个数或多个数
- Codeforces Round #300
- HUD1052 __ P2 1002 __ Tian Ji -- The Horse Racing
- 2015年国家集训队测试 BZOJ3816矩阵变幻