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 ...
随机推荐
- js 如何给标签增加属性
<html> <head> <meta charset="UTF-8"> <title></title> </he ...
- 闰年or平年判断
<script type="text/javascript">var year = prompt("请输入一个年份");if(year!=null) ...
- 微信公众号API使用总结
官网: https://mp.weixin.qq.com/ API: http://mp.weixin.qq.com/wiki/home/index.html 接口调试工具:h ...
- nim游戏解法(转)
转自:http://acm.hdu.edu.cn/forum/read.php?fid=9&tid=10617 取火柴的游戏 题目1:今有若干堆火柴,两人依次从中拿取,规定每次只能从一堆中取若 ...
- 团体程序设计天梯赛-练习集-L1-041. 寻找250
L1-041. 寻找250 对方不想和你说话,并向你扔了一串数…… 而你必须从这一串数字中找到“250”这个高大上的感人数字. 输入格式: 输入在一行中给出不知道多少个绝对值不超过1000的整数,其中 ...
- centos7 删除libc.so.6 紧急救援
wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz tar zxvf glibc-2.18.tar.gz cd glibc-2.18 mkdir b ...
- Day 17 time,datetime,random,os,sys,json,pickle
time模块 1.作用:打印时间,需要时间的地方,暂停程序的功能 时间戳形式 time.time() # 1560129555.4663873(python中从1970年开始计算过去了多少秒) 格式化 ...
- 【剑指Offer】30、连续子数组的最大和
题目描述: HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是 ...
- 阿里云服务器centos7环境下安装xampp后,mysql有进程,但是却没有监听3306端口
配置阿里云服务器centos7中xampp环境时出现了一种情况: 在centos中可以使用命令进入mysql 修改后也可以远程用phpmyadmin连接mysql 但是用navicat却无法连接 先修 ...
- NOIP2009 T2 Hankson的趣味题
传送门 题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上, ...