UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间。
模拟一下,发现其实灰常水的贪心。。。
不能直接求最大和最小的= =。只要求出每只蚂蚁都走长路下木棍时的最大值,和走短路时的就行了。
代码:
/*
* Author: illuz <iilluzen@gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: uva10714.cpp
* Lauguage: C/C++
* Create Date: 2013-08-29 22:52:12
* Descripton: UVA 10714 Ants, greed, simutation
*/
#include <cstdio>
#include <algorithm>
using namespace std; int main() {
int cas;
int Max, Min, len, n, t, L, S;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d", &len, &n);
Min = 0;
Max = 0;
while (n--) {
scanf("%d", &t);
if (t > len / 2) L = t, S = len - t;
else L = len - t, S = t;
Min = max(L, Min);
Max = max(S, Max);
}
printf("%d %d\n", Max, Min);
}
return 0;
}
UVA 10714 Ants 蚂蚁 贪心+模拟 水题的更多相关文章
- UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11039 - Building designing 贪心,水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- uva 10714 Ants(贪心)
题目连接:10714 - Ants 题目大意:一根棍子上有n只蚂蚁, 这些蚂蚁开始可以任意朝着一个方向移动一直走,向左或是向右,并且移动速度是相同的,但是一旦蚂蚁碰到迎面走来的另一只蚂蚁,那么这两只蚂 ...
- UVA - 442 Matrix Chain Multiplication(栈模拟水题+专治自闭)
题目: 给出一串表示矩阵相乘的字符串,问这字符串中的矩阵相乘中所有元素相乘的次数. 思路: 遍历字符串遇到字母将其表示的矩阵压入栈中,遇到‘)’就将栈中的两个矩阵弹出来,然后计算这两个矩阵的元素相乘的 ...
- UVA - 10714 Ants
最多时间就是每仅仅蚂蚁选择最久的爬行方式 最少时间就是每仅仅蚂蚁选择最快地爬行方式 #include<iostream> #include<map> #include<s ...
- 模拟水题,查看二维数组是否有一列都为1(POJ2864)
题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
随机推荐
- 关于Failed to convert property value of type [org.quartz.impl.StdScheduler] to required type [org.springframework.scheduling.quartz.SchedulerFactoryBean
在一个业务类有下列属性 private SchedulerFactoryBeanscheduler; public SchedulerFactory BeangetScheduler() { retu ...
- VC 对话框背景颜色、控件颜色(三种方法)
系统环境:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为对话框设置背景颜色.控件颜色 既然MFC对话框不好开发,那么现在我们来开始美化我们的对话框.为对话框设置背景颜色 ...
- html5学习链接
http://www.runoob.com/tags/html-colorpicker.html
- 【HDOJ】4057 Rescue the Rabbit
挺有意思的一道题目,解法是AC自动机+DP.AC自动机建立fail指针时,一定要注意结点的属性也需要传递.AC自动机结合了trie和kmp的优点.需要注意的是,每个模式串仅计算一次,否则这题很难解. ...
- Oracle建表插数据等等
Oracle的表的管理: 表名和列的命名规则,详见 数据库命名规范 . 必须以字母开头 . 长度不能超过30个字符 . 不能使用Oracle的保留字 . 只能使用如下字符 column_name-Z, ...
- 推荐GitHub上10 个开源深度学习框架
推荐GitHub上10 个开源深度学习框架 日前,Google 开源了 TensorFlow(GitHub),此举在深度学习领域影响巨大,因为 Google 在人工智能领域的研发成绩斐然,有着雄厚 ...
- BZOJ2843: 极地旅行社
2843: 极地旅行社 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 90 Solved: 56[Submit][Status] Descripti ...
- PowerDesigner一些小技巧
1.安装PD v12.0版 2.由pdm生成建表脚本时,字段超过15字符就发生错误(oracle) 原因未知,解决办法是打开PDM后,会出现Database的菜单栏,进入Database - Edit ...
- linux系统利用yum安装其他软件或服务
1.下载yum的配置源(最好用网易163的源,也可以使其他的源) wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo 下载到 /etc/ ...
- [codevs2152]滑雪
题目来源 http://www.tyvj.cn/p/1004 http://www.luogu.org/problem/show?pid=1434# http://codevs.cn/problem/ ...