poj-1700 crossing river(贪心题)
题目描述:
Input
Output
Sample Input
- 1
- 4
- 1 2 5 10
Sample Output
- 17
- 题目大意:过河,速度取慢的
题解:有点像汉诺塔的感觉,贪心算法,直接看代码吧,大水题
- #include<iostream>
- #include<algorithm>
- #include<cstring>
- #include<sstream>
- #include<cmath>
- #include<cstdlib>
- #include<queue>
- using namespace std;
- #define PI 3.14159265358979323846264338327950
- int T,n,a[],t;
- int main()
- {
- scanf("%d",&T);
- while(T--)
- {
- t=;
- scanf("%d",&n);
- memset(a,,sizeof(a));
- for(int i=;i<n;i++)
- scanf("%d",&a[i]);
- sort(a,a+n);
- if(n==)
- t=a[];
- else if(n==)
- t=a[];
- else if(n==)
- t=a[]+a[]+a[];
- else
- {
- for(int i=n-;i>;i=i-)
- {
- if(i>=)
- {
- if(a[]+a[i-]>=*a[])
- t=t+a[]+*a[]+a[i];
- else
- t=t+*a[]+a[i]+a[i-];
- }
- if(i==)
- t=t+a[]+a[]+a[];
- if(i==)
- t=t+a[];
- }
- }
- printf("%d\n",t);
- }
- }
poj-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 ...
- 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 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 ...
- 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 ...
- Crossing River(1700poj)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9919 Accepted: 3752 De ...
- POJ 3190 Stall Reservations贪心
POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...
- Sliding Window POJ - 2823 单调队列模板题
Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间 ...
随机推荐
- NET Core项目部署
NET Core项目部署到linux(Centos7) 阅读目录 1.开篇说明 2.Jexus简单说明 3.Visual Studio 2015本地发布并且测试 4.配置Jexus并且部署.NET C ...
- tomcat7 fail to start inside Ubuntu Docker container
The tomcat startup script needs some special privileges. Concrete it needs to check all running proc ...
- Python 踩坑之旅进程篇其三pgid是个什么鬼 (子进程\子孙进程无法kill 退出的解法)
目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4.1 技术关键字 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 Github: https: ...
- LCD1602显示中文汉字
小子在西藏 2011-11-25编写 特别说明笔者是上面的作者,感谢那些原意分享知识的人.时隔5年我又看到了笔者当年写的东西,我想这期间还有许许多多的人 今天写在博客上,愿更多后来者可以学习. LCD ...
- github新手指南
- 采用React+Ant Design组件化开发前端界面(一)
react-start 基础知识 1.使用脚手架创建项目并启动 1.1 安装脚手架: npm install -g create-react-app 1.2 使用脚手架创建项目: create ...
- Eclipse 主题(Theme)配置
< 程序员大牛必备的装逼神器 > 一个牛逼的程序员,除了有牛逼的技术,还要有高逼格的风格,说白了,就和人一样,单是内在美还不行,必须外表也要美,就好比,一个乞丐,他内在美,但是全身臭气熏天 ...
- 《移动Web前端高效开发实战》笔记2——使用Gulp构建一个ECMAScript 6和Sass应用
8.3.1 安装和配置 运行Gulp需要Node.js环境,请参看第二章内容搭建Node.js环境.使用NPM全局安装Gulp,命令如下: npm install gulp-cli –g 然后,在项目 ...
- <Android 应用 之路> 聚合数据SDK
聚合数据介绍 聚合数据是一个为智能手机开发者,网站站长,移动设备开发人员及图商提供原始数据API服务的综合性云数据平台.包含手机聚合,网站聚合,LBS聚合三部分,其功能类似于Google APIS.[ ...
- Google Chrome 浏览器的备用(离线)安装程序
Google Chrome 浏览器的备用(离线)安装程序(适用于 Windows) 如果您在使用 http://www.google.com/chrome 上的标准安装程序下载 Chrome 浏览器时 ...