poj 1852 Ants_贪心
题目大意:很多的蚂蚁都在长度为L(cm)的膀子上爬行,它们的速度都是1cm/s,到了棒子终端的时候,蚂蚁就会掉下去。如果在爬行途中遇到其他蚂蚁,两只蚂蚁的方向都会逆转。已知蚂蚁在棒子的最初位置坐标,但是我们不知道他们会往哪一个方向爬。请求出所有蚂蚁掉下去的最短时间和最长时间。
思路:当蚂蚁碰撞时,两只蚂蚁相反方向走,换个思路就是把他们的身份互换,相当于直接穿过,所以不用考虑蚂蚁的碰撞问题。
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(int argc, char** argv) {
int t,n,len,x,y,ans1,ans2;
scanf("%d",&t);
while(t--){
scanf("%d%d",&len,&n);
ans1=0;
ans2=0;
for(int i=0;i<n;i++){
scanf("%d",&x);
y=len-x;
if(x>y)swap(x,y);
if(x>ans1) ans1=x;
if(y>ans2) ans2=y;
}
printf("%d %d\n",ans1,ans2);
}
return 0;
}
poj 1852 Ants_贪心的更多相关文章
- POJ 1852 Ants(贪心)
POJ 1852 Ants 题目大意 有n只蚂蚁在木棍上爬行,每只蚂蚁的速度都是每秒1单位长度,现在给你所有蚂蚁初始的位置(蚂蚁运动方向未定),蚂蚁相遇会掉头反向运动,让你求出所有蚂蚁都·掉下木棍的最 ...
- POJ 1852 Ants || UVA 10881 - Piotr's Ants 经典的蚂蚁问题
两题很有趣挺经典的蚂蚁问题. 1.n只蚂蚁以1cm/s的速度在长为L的竿上爬行,当蚂蚁爬到竿子的端点就会掉落.当两只蚂蚁相撞时,只能各自反向爬回去.对于每只蚂蚁,给出距离左端的距离xi,但不知道它的朝 ...
- poj 1852&3684 题解
poj 1852 3684 这两题思路相似就放在一起. 1852 题意 一块长为L长度单位的板子(从0开始)上有很多只蚂蚁,给出它们的位置,它们的方向不确定,速度为每秒一长度单位,当两只蚂蚁相遇的时候 ...
- POJ 1456(贪心)
#include <string.h> #include <iostream> #include <queue> #include <stdio.h> ...
- poj -3614 Sunscreen(贪心 + 优先队列)
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- POJ 1456 - Supermarket - [贪心+小顶堆]
题目链接:http://poj.org/problem?id=1456 Time Limit: 2000MS Memory Limit: 65536K Description A supermarke ...
- poj 3404&&poj1700(贪心)
Bridge over a rough river Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4143 Accept ...
- poj 2287(贪心)
Tian Ji -- The Horse Racing Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 12490 Acc ...
随机推荐
- Silverlight 结合ArcGis 在地图画点
原文 http://www.dotblogs.com.tw/justforgood/archive/2012/05/10/72076.aspx 我们直接来看完成后的画面读者会比较有兴趣 如上,小马在地 ...
- python处理.seq文件
# Deal with .seq format for video sequence # Author: Kaij # The .seq file is combined with images, # ...
- C++ 11学习(1):lambda表达式
转载请注明,来自:http://blog.csdn.net/skymanwu #include <iostream> #include <vector> #include &l ...
- 杭电1010(dfs + 奇偶剪枝)
题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...
- JQuery中阻止事件冒泡方式及其区别
JQuery 提供了两种方式来阻止事件冒泡. 方式一:event.stopPropagation(); $("#div1").mousedown(function( ...
- IOS 使用dispatch_once 创建单例
+ (instantClass *)sharedClient { static instantClass *_sharedClient = nil; static dispatch_once_t on ...
- LeetCode——Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- SQL Server2008R2安装失败问题之语言包问题
今天安装SQL Server2008 的时候出现了,如下的的问题,安装过程在ExcuteStandardTimingsWorkflow时候报错,结束安装. 提示: ...
- 疯狂Android第一章:Android环境配置以及基本概念
第一章 无关痒痛:Android Studio安装,配置,基本功能介绍! 重点内容:Android应用基本结构分析. 基础概念部分(只需知道作用,原理后见代码): Activity:安卓系统中负责与用 ...
- Oracle数据类型与.NET中的对应关系(转)
Oracle数据类型与.NET中的对应关系 2011-02-24 10:02:16 标签:C# oracletype Oracle 数据类型 .NET Oracle连接添加的引用不同,会存在数据类型不 ...