1700 Crossing River
题目链接: http://poj.org/problem?id=1700
1. 当1个人时: 直接过河 t[0].
2. 当2个人时: 时间为较慢的那个 t[1].
3. 当3个人时: 时间为 t[0]+t[1]+t[2].
4. 当4个以上的人时, 将t[0] 和 t[1]当作搬运工. 两种方案:
- 最快和次快的过去, 最快的回来, 最慢和次慢的过去, 次快的回来, 这样就将最慢和次慢的送过去了. 时间: t[0]+2*t[1]+t[i]
- 最快的依次送最慢和次慢的过去再回来, 时间: 2*t[0]+t[i-1]+t[i]
以上方案每次就将最慢的和次慢的送过河, 每次送走两个人, 当将其他人送完之后, t[0]和t[1]再过河.
#include <iostream>
#include <algorithm>
using namespace std;
bool comp(int a,int b){
return a<b;
}
int main(){
int m,n,t[],i,sum;
cin>>m;
while(m--){
cin>>n;
sum = ;
for(i=;i<n;++i)
cin>>t[i];
sort(t,t+n,comp);
for(i=n-;i>;i-=){
//把t[0]和t[1]当成搬运工,最后返回到原地
int t1 = t[]+*t[]+t[i];//最快的(即所用时间t[0])和次快的过河,然后最快的将船划回来,再次慢的和最慢的过河,然后次快的将船划回来
int t2 = *t[]+t[i-]+t[i];//最快的和最慢的过河,然后最快的将船划回来,再最快的和次慢的过河,然后最快的将船划回来
sum += t1>t2?t2:t1;
}
if(i==) //3people left
sum += t[]+t[]+t[];
else if(i==) //2 people left
sum += t[];
else // 1 people left
sum += t[];
cout<<sum<<endl;
}
return ;
}
-->
1700 Crossing River的更多相关文章
- 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 ...
- poj 1700 Crossing River C++/Java
http://poj.org/problem?id=1700 题目大意: 有n个人要过坐船过河,每一个人划船有个时间a[i],每次最多两个人坐一条船过河.且过河时间为两个人中速度慢的,求n个人过河的最 ...
- POJ 1700 - Crossing River
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13982 Accepted: 5349 Description A gr ...
- 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 ...
- Crossing River(1700poj)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9919 Accepted: 3752 De ...
- Crossing River
Crossing River 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=26251 题意: N个人希望去过 ...
- POJ 1700 cross river (数学模拟)
...
- poj1700--贪心--Crossing River
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12260 Accepted: 4641 D ...
随机推荐
- 1006 Sign In and Sign Out (25)(25 分)思路:普通的时间比较题。。。
1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...
- 使用Ajax解析数据遇到的问题
数据格式 我最近在使用JQuery的$.ajax访问后台的时候,发现竟然无法解析返回的数据,具体的错误记不清了(以后在遇到问题先截个图),可以在浏览器的Console中看到一个错误,但是去看这条请求是 ...
- 反向生成hibernate实体类和映射文件
工欲善其事,必先利其器.我们可以使用IDE来根据数据库中的表反向生成实体类和映射文件,虽然这些东西手写也并不是难度很大,但是如果存在大量的简单工作需要我们做,也会显得很麻烦. 写在前面 我们反向生成的 ...
- 5月15日上课笔记-js中 location对象的属性、document对象、js内置对象、Date事件对象、
location的属性: host: 返回当前主机名和端口号 定时函数: setTimeout( ) setInterval() 二.document对象 getElementById(); 根据ID ...
- 字体相关CSS属性介绍
font-family 字体系列. font-family可以把多个字体名称作为一个“回退”系统来保存.如果浏览器不支持第一个字体,则会尝试下一个.浏览器会使用它可识别的第一个值. 简单实例: bod ...
- touch python
一 使用while循环输出 1 2 3 4 5 6 8 9 10. i=0 while i<10: i=i+1 if i == 7: continue print(i) 二 求 1-100所 ...
- python dns欺骗
'''' from scapy.all import * from threading import Thread def DNShijacking(): global wg wg=raw_input ...
- pvalue for go kegg enrichment
Simple, fast implementation of Fisher’s exact test. . For example, for the following table: o Havi ...
- 第11章 分布式服务跟踪: Spring Cloud Sleuth
通常一个由客户端发起的请求在后端系统中会经过多个不同的微服务调用来协同产生最后的请求结果, 在复杂的微服务架构系统中, 几乎每一个前端请求都会形成一条复杂的分布式服务调用链路, 在每条链路中任何一个依 ...
- mongodb(五)
mongoDB 启动配置祥讲导出,导入,运行时备份Fsync锁,数据修复用户管理,安全认证 1.启动项 mongod --help 1.1利用config配置文件来启动数据库改变端口为8888 mon ...