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 ...
随机推荐
- C# Datetime 使用详解
获得当前系统时间: DateTime dt = DateTime.Now; Environment.TickCount可以得到“系统启动到现在”的毫秒值 DateTime now = DateTime ...
- ROS:Nvidia Jetson TK1开发平台
原文链接: http://wiki.ros.org/NvidiaJetsonTK1 1. Nvidia Jetson TK1 Jetson TK1 comes pre-installed with L ...
- MFC 缩放和显示IplImage
序言:使用OpenCV嵌入MFC的框内,图像大小不能和框大小进行匹配,因此需要缩放,使图像适用于MFC框. 后来找到了一种新的方法,此方案貌似u已经废弃. (1).在MFC中显示图片 void CAv ...
- 实验0 安装GLUT包及工程的创建与运行
下面将对Windows下在MicroSoft Visual C++2010(简称MSVC)环境下的OpenGL编程进行简单介绍. 1.安装GLUT工具包 GLUT不是OpenGL所必须的,但它会给我们 ...
- (转)OpenLayers3基础教程——OL3之Popup
http://blog.csdn.net/gisshixisheng/article/details/46794813 概述: 本节重点讲述OpenLayers3中Popup的调用时实现,OL3改用O ...
- Data mapping-数据映射
数据映射:根据数据的结构信息建立数据间的映射操作机制. 数据映射的要素: 一.数据 1.源数据: 2.目标数据: 3.数据间关系: 4.数据的元数据(结构信息). 5.元素类型的对应关系. 二.元数据 ...
- .NET 解决方案 核心库整理
一系列令人敬畏的.NET核心库,工具,框架和软件: https://www.cnblogs.com/weifeng123/p/11039345.html 企业级解决方案收录: https://www ...
- BZOJ 1705: [Usaco2007 Nov]Telephone Wire 架设电话线 DP + 优化 + 推导
Description 最近,Farmer John的奶牛们越来越不满于牛棚里一塌糊涂的电话服务 于是,她们要求FJ把那些老旧的电话线换成性能更好的新电话线. 新的电话线架设在已有的N(2 <= ...
- 一个休假申请页对input标签各种属性的用法案例(手机端)
<%@ page language="java" import="java.util.*" contentType="text/html; ch ...
- CallableStatement的用法
CallableStatement 对象为所有的 DBMS 提供了一种以标准形式调用已储存过程的方法.已储存过程储存在数据库中.对已储存过程的调用是 CallableStatement 对象所含的内容 ...