poj1700--贪心--Crossing River
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 12260 | Accepted: 4641 |
Description
cross. Each person has a different rowing speed; the speed of a couple is determined by the speed of the slower one. Your job is to determine a strategy that minimizes the time for these people to get across.
Input
to cross the river. Each case is preceded by a blank line. There won't be more than 1000 people and nobody takes more than 100 seconds to cross.
Output
Sample Input
1
4
1 2 5 10
Sample Output
17#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
return a<b;
}
int main()
{
int t,s[1001];
scanf("%d",&t);
while(t--)
{
memset(s,0,sizeof(s));
int n,sum=0,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n,cmp);
for(i=n-1;i>2;i-=2)
{
if(s[0]*2+s[i]+s[i-1]>s[0]+s[1]*2+s[i])
sum+=s[0]+s[1]*2+s[i];
else sum+=s[0]*2+s[i]+s[i-1];
}
if(i==2) sum+=s[0]+s[1]+s[2];
if(i==1) sum+=s[1];
if(i==0) sum=s[0];
printf("%d\n",sum);
}
return 0;
}
poj1700--贪心--Crossing River的更多相关文章
- POJ1700:Crossing River(过河问题)
POJ1700 题目链接:http://poj.org/problem?id=1700 Time Limit:1000MS Memory Limit:10000KB 64bit IO ...
- 贪心Crossing river
英文题目: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...
- POJ 1700 Crossing River (贪心)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...
- poj 1700 Crossing River 过河问题。贪心
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9887 Accepted: 3737 De ...
- Crossing River
Crossing River 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=26251 题意: N个人希望去过 ...
- Crossing River(1700poj)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9919 Accepted: 3752 De ...
- poj-1700 crossing river(贪心题)
题目描述: A group of N people wishes to go across a river with only one boat, which can at most carry tw ...
- Crossing River poj1700贪心
题目描述:N个人过河,只有一只船,最多只能有两人划船,每个人划船速度不同,船速为最慢的人的速度.输入T为case个数,每个case输入N为人数,接下来一行输入的是每个人过河的时间,都不相同.要求输出N ...
- ACM学习历程——POJ 1700 Crossing River(贪心)
Description A group of N people wishes to go across a river with only one boat, which can at most ca ...
随机推荐
- 关于改变安卓Button样式,这里有一个好方法。
首先,在drawable下创建一个新的xml文件(例如我创建的为button.xml).然后在里面输入以下代码. <item> <shape> <gradient and ...
- ie8及其以下版本兼容性问题之圆角
解决办法:在http://css3pie.com/页面下载一个PIE.htc的文件,加载到根目录下,然后在css中加上一句behavior:url(../js/PIE.htc);如下: .border ...
- ubuntu 14.04安装x11VNC
环境:Ubuntu 14.04, 1)安装x11vnc: sudo apt-get install x11vnc 2)设置VNC的连接密码: x11vnc -storepasswd Enter VNC ...
- 读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++]
读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++] 第2章 数据和基本类型 1. 整型 2. 习题:左值和右值 3. C++关键字/保留字和操作符替代值 4. 声明 ...
- Apex语言(三)原始数据类型
1.原始数据类型(Primitive) 整数:Integer 双精度:Double 单精度:Decimal 长整型:Long 日期:Date 日期时间:Datetime 字符串:String ID:I ...
- Android LinearLayout整个布局设置不可点击
1,activity的xml布局(布局中有个Button按钮,点击按钮弹出一个popupwindow ) <?xml version="1.0" encoding=" ...
- VCSA服务重启命令
Sphere Web Client界面的服务分别是: vmware-mbcs vmware-netdumper vmware-rbd-watchdog 分别执行命令确认,首先执行命令: service ...
- Microsoft Visual Studio 常用快捷键总结
table tr:nth-child(odd){ background: #FFFFCC; } table tr:nth-child(even){ background: #FFFF99; } Mic ...
- swift-正则验证手机号码
// 手机号验证正则表达式 func validateMobile(phoneNum:String)-> Bool { // 手机号以 13 14 15 18 开头 八个 \d 数字字符 let ...
- 49.filter、query比较
主要知识点 1.filter与query用在同一次查询中的语法 2.filter与query使用场景对比 3.二都的性能比较 一.filter与query示例 1.先准备数据 PUT /com ...