poj1700过河问题(贪心)
来源:互联网 发布:天天特价淘宝网衣服 编辑:程序博客网 时间:2024/05/01 14:20
题目链接:poj1700
/*两种过河策略:1、用速度最快的那个每次将人载过河,再回来载其他的人2、用速度最快的和次快的循环载人,即最快的和次快的先过河,次快的留下,最快的回来,接着最慢和次慢的人过河,次快的回来*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int inf = 0xfffffff;const int N = 1005;int a[N];int main(){ int T,n,i; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i = 1; i <= n; i ++) scanf("%d",&a[i]); int sum = 0; sort(a+1, a+n+1);//排序 for(i = n; i >= 4; i -= 2) { int tmp1 = 2*a[1] + a[i] + a[i-1];//策略1 int tmp2 = a[1] + 2*a[2] + a[i];//策略2 sum += min(tmp1, tmp2); } if(i == 3) sum += a[1] + a[2] + a[3];//剩下三个人 if(i == 2) sum += a[2];//剩下两个人 if(i == 1) sum += a[1];//剩下一个人 printf("%d\n",sum); } return 0;}
0 0
- poj1700过河问题(贪心)
- poj1700 过河问题---贪心算法
- POJ1700 【经典过河问题,贪心】
- poj1700(ny47)(过河问题)(贪心)
- poj1700过河问题
- POJ1700 Crossing River 过河问题
- 贪心poj1700
- 贪心问题--过河问题
- poj1700过河 题解
- 【贪心DP】过河问题
- 过河问题 NYOJ 贪心
- 贪心-nyoj-过河问题
- NYOJ45:过河问题【贪心】
- nyoj 过河问题 贪心
- 贪心过河问题
- 贪心算法--过河问题
- nyoj 47 过河 过河问题 【贪心】
- NYOJ_47 过河问题,贪心选择
- Android.AsyncTask
- Linux 搭建SVN 服务器
- 如何在ios中简便地判断内存是否泄露
- ngx_event_pipe_write_to_downstream分析
- 团队建设的几点体会-----之二
- poj1700过河问题(贪心)
- LDO和BUCK降压稳压器对比
- Android - 组件工具箱(widget tool box)
- 监控宝监控服务性能监控都包括哪些指标?
- 跃动着死亡的频率
- libevent(1):初起步
- 监控宝了解应用层服务的性能状况
- 企业软件,WEB和对于他们无限美好的遐想(第七日)--2014-3-16--投票日 + Struts 原理分析 (六)
- Android_仿支付宝账单列表(头部停留及分页数据加载)