nyoj-47-过河问题|POJ-1700-Crossing River
http://acm.nyist.net/JudgeOnline/problem.php?pid=47
http://poj.org/problem?id=1700
解题思路:求最少需要多少时间才能都通过。先将每个人过河所需的时间升序排序
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 int a[];
6 int n, t, i;
7 int ans;
8
9 int cmp(const void *a, const void *b){
return *(int *)a - *(int *)b;
}
void solve(){
ans = ;
while(n){
if(n == ){
ans += a[];
break;
}
else if(n == ){
ans += a[];
break;
}
else if(n == ){
ans += a[] + a[] + a[];
break;
}
else{
//人较多的情况下,判断是先把走得最慢的两个人送过去合算还是先把走得最快和最慢的人先送过去
if( * a[] > a[] + a[n - ]){
ans += (a[n - ] + a[n] + * a[]);
}
else{
ans += (a[] + * a[] + a[n]);
}
n -= ;
}
}
printf("%d\n", ans);
}
int main(){
scanf("%d", &t);
while(t--){
scanf("%d" ,&n);
for(i = ; i <= n; i++){
scanf("%d", &a[i]);
}
qsort(a + , n, sizeof(a[]), cmp);
solve();
}
return ;
53 }
nyoj-47-过河问题|POJ-1700-Crossing River的更多相关文章
- poj 1700 Crossing River 过河问题。贪心
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9887 Accepted: 3737 De ...
- POJ 1700 Crossing River (贪心)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...
- 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 cross river (数学模拟)
...
- 1700 Crossing River
题目链接: http://poj.org/problem?id=1700 1. 当1个人时: 直接过河 t[0]. 2. 当2个人时: 时间为较慢的那个 t[1]. 3. 当3个人时: 时间为 t[0 ...
- nyoj 47——过河问题——————【贪心】
过河问题 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边.如果不借助手电筒的话,大家是无论如何也不敢过桥去的 ...
- NYOJ 47过河问题
主要思路:先排序.有两种可能是最小的情况,一种是让最小的去带着最大的过去,然后最小的再回来,还有一种就是先最小的和第二小的一块过去, 然后最小的回来,让最大的和第二大的过去,接着第二小的回来,第二小和 ...
- Crossing River(1700poj)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9919 Accepted: 3752 De ...
随机推荐
- WPF后台通知前台事件(ViewModelBase记录)
版本1: 定义:public class ModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler P ...
- QRegExp解析
正则表达式(regular expression)就是用一个“字符串”来描述一个特征,然后去验证另一个“字符串”是否符合这个特征.比如 表达式“ab+” 描述的特征是“一个 'a' 和 任意个 'b' ...
- HDU5950【矩阵快速幂】
主要还是i^4化成一个(i+1)^4没遇到过,还是很基础的一题矩阵快速幂: #include <bits/stdc++.h> using namespace std; typedef lo ...
- UpdateObjectClient 空白目录有问题
UpdateObjectClient 如果目标文件夹下面有空白目录的话 有可能造成无法下载所有文件
- 01 | Jewels and Stones
Question You're given strings J representing the types of stones that are jewels, and S representing ...
- POI刷题记录
POI2007 HNOI2018滚粗后,默默来刷POI 先从2007刷起 bzoj1103[POI2007]大都市meg bzoj1098[POI2007]办公楼biu bzoj1102[POI200 ...
- mysql整理(个人)
注意:以下命令都是在Linux系统下执行的: 1.验证mysql是否安装成功: mysqladmin --version 2.连接mysql服务器: mysql -u root -p 之后输入密码 3 ...
- hdu6318( 2018 Multi-University Training Contest 2)
bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6318 求逆序数的对数 #include<iostream> #include ...
- (AOP)理解
AOP的全称: Aspact Oriented Programming AOP的目标(作用):让我们可以“专心做事” 日志记录,事务处理,异常捕获,缓存操作. AOP原理 将复杂的需求分解出不同 ...
- vue2.0:(四)、首页入门,组件拆分1
为什么需要组件拆分呢?这样才能更符合模块化这样一个理念. 首先是index.html,代码如下: <!DOCTYPE html> <html> <head> < ...