POJ 1700 cross river (数学模拟)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 10311 | Accepted: 3889 |
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
- 仅仅有一个人的时候:sum=time[1];
- 二个人的时候: sum=time[1]+time[2]
- 三的人的时候: sum=time[1]+time[2]+time[3]
- 重点!当大于四个人的时候。为了追求时间最短化。仅仅有两种运送方式:(1) 最快。次快去-->最快回--->最慢。次慢去-->次快 time[2]+time[1]+time[n]+time[n-1]+time[2]
- (2) 最快,最慢去-->最快回-->最快。次快去-->最快回 time[n]+time[1]+time[n-1]+time[1]
#include<cstdio>
#include<algorithm> #define maxn 100001
using namespace std;
int time[maxn]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",time+i); sort(time+1,time+n+1); while(n)
{
if(n==1)
{
sum+=time[1];
n=0;
}
else if(n==2)
{
sum+=time[2];
n=0;
}
else if(n==3)
{
sum+=time[1]+time[2]+time[3];
n=0;
}
else
{
if(time[2]*2>=time[1]+time[n-1])
sum+=2*time[1]+time[n]+time[n-1];
else
sum+=2*time[2]+time[1]+time[n];
n-=2;
}
} printf("%d\n",sum);
} return 0;
}
POJ 1700 cross 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 ...
- poj 1700
http://poj.org/problem?id=1700 题目大意就是一条船,有N个人需要过河,求N个人最短过河的时间 #include <stdio.h> int main() { ...
- POJ 1700 F(Contest #3)
Description A group of N people wishes to go across a river with only one boat, which can at most ca ...
- POJ 1700 经典过河问题(贪心)
POJ题目链接:http://poj.org/problem?id=1700 N个人过河,船每次最多只能坐两个人,船载每个人过河的所需时间不同,问最快的过河时间. 思路: 当n=1,2,3时所需要的最 ...
- 1700 Crossing River
题目链接: http://poj.org/problem?id=1700 1. 当1个人时: 直接过河 t[0]. 2. 当2个人时: 时间为较慢的那个 t[1]. 3. 当3个人时: 时间为 t[0 ...
随机推荐
- CheckBox控件实现选项的选中
1:设置控件属性 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- [Swust OJ 767]--将军回家(Dijkstra算法)
题目链接:http://acm.swust.edu.cn/problem/767/ Time limit(ms): 1000 Memory limit(kb): 65535 Description ...
- JavaSE学习总结第08天_面向对象3
08.01 工具类中使用静态 例: class ArrayTool { //将构造方法私有,外界不能创建该类的对象 private ArrayTool(){} //遍历数组 public stat ...
- vs2010 条件断点 has changed是什么意思?
在vs2010 断点设置 condition里,有2个选项可以选择: 一个是true,另个是has changed,true好理解,如果表达式为真则停止.但是has changed是什么意思.看了官网 ...
- 历时一年,我的著作《第一行代码——Android》已出版!
前言 事实上我当初决定開始写博客的想法挺简单的,认为自己搞技术这么多年了,总应该要留下点什么.既然没能写出什么出色的应用,那至少也要留下点文字分享给大家,以指引在我后面的开发人员们,毕竟我也从前辈们的 ...
- as3声谱效果,有在线演示地址,能够播放本地音乐
来源:潮汕IT男 简单的as3声谱效果,能够播放本地音乐. tag=as3" style="word-wrap:break-word; margin:0px; padding:0p ...
- 【Tomcat】java.lang.OutOfMemoryError
1.Java heap space Heap size 昨天在服务器上面部署项目,之前服务器上面已经有一个项目的了. 然后我再部署一个,上去跑了之后,居然内存溢出了. 好吧,内存溢出就调一下,调了之后 ...
- 我的wifi
首先利用百度查找 怎么承载网络,托管网络的用户名和密码 . 1.以管理员身份运行命令提示符: 快捷键win+R→输入cmd→回车 2.启用并设定虚拟WiFi网卡: 运行命令:netsh wlan se ...
- ORACLE存储过程笔记3
ORACLE存储过程笔记3 流程控制 1.条件 if expression thenpl/sql or sqlend if; if expression thenpl/sql or sqlel ...
- Python 数据处理扩展包: numpy 和 pandas 模块介绍
一.numpy模块 NumPy(Numeric Python)模块是Python的一种开源的数值计算扩展.这种工具可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list str ...