POJ 2674 Linear world
题目大意: 一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的时间和名字。
注意两点: 相撞可视为擦肩而过,蚂蚁们不管掉不掉头它们的相对位置保持不变
这个题是大白上原来的蚂蚁相撞问题(POJ 1852)的加强版
如果只考虑最后掉下去那只蚂蚁的时间(即蚂蚁全部掉下的最长时间),那么可以认为这些蚂蚁相撞时直接擦肩而过.
但是该题还要求出最后掉下去那只蚂蚁的名字,这样看起来似乎要考虑每个蚂蚁相撞的情况,若记录获得最大值的蚂蚁为A,若A和B碰撞,之后B又和C碰撞,之后C又和D.... 的最后一个人,这样最后一个相撞的人的名字即为所求,但是这样就不好处理
如果把相撞视为擦肩而过,让蚂蚁们按原方向一直走,每只蚂蚁走pos+maxn或者pos-maxn后,此时对这些距离从小到大排序,找到位置为0或者L的点,记起下标为temp,由于蚂蚁的相对位置保持不变,则ant[pos].name即为所求.
注意最后是要截取两位小数,不是四舍五入,所以要用floor(maxn/V*100)/100.0(因为这个wa了几次)
/*
* Created: 2016年04月06日 10时29分37秒 星期三
* Author: Akrusher
*
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={,,-,},dy[]={,,,-};
const int INF=0x3f3f3f3f;
const ll mod=1e9+;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true; struct node{
char dir[]; //方向
double pos;//位置
char name[];
};
node ant[];
double p[];
int n;
double L,V;
bool cmp(node x,node y){
return x.pos<y.pos;
}
void solve(){
double maxn,dis;
maxn=;
rep(i,,n){
dis=(ant[i].dir[]=='P'||ant[i].dir[]=='p')?L:;
maxn=max(maxn,abs(dis-ant[i].pos));
}
rep(i,,n){
dis=(ant[i].dir[]=='P'||ant[i].dir[]=='p')?maxn:-maxn;
p[i]=dis+ant[i].pos;
}
sort(p,p+n);
int temp;
rep(i,,n){
if(p[i]==||p[i]==L){
temp=i;break;
}
}
printf("%13.2f %s\n",floor(maxn/V*)/100.0,ant[temp].name);
}
int main()
{
while(in(n)&&n){
inlf2(L,V);
rep(i,,n){
scanf("%s %lf %s",&ant[i].dir,&ant[i].pos,&ant[i].name);
}
solve();
}
return ;
}
POJ 2674 Linear world的更多相关文章
- POJ 2674 Linear world(弹性碰撞)
Linear world Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4426 Accepted: 1006 Desc ...
- Greedy:Linear world(POJ 2674)
Linear world 题目大意:一些人生活在线性世界中,到达线性世界两端就会消失,两个人的前进方向有两个,相遇会改变各自相遇方向,求最后一个人掉下的人的名字和时间. 其实这一题就是弹性碰撞的模 ...
- POJ 2674
Linear world Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2448 Accepted: 564 Descr ...
- poj 2674 线性世界 弹性碰撞
弹性碰撞的题目一般都是指碰到就会掉转方向的一类题目,这里我们可以忽略掉头,仅仅看成擦肩而过,交换名字等等 题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名 ...
- ProgrammingContestChallengeBook
POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...
- [POJ 2420] A Star not a Tree?
A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4058 Accepted: 200 ...
- 萌新笔记——Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))
在上篇,我了解了基数的基本概念,现在进入Linear Counting算法的学习. 理解颇浅,还请大神指点! http://blog.codinglabs.org/articles/algorithm ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
随机推荐
- PHP+Mysql-表单数据插入数据库及数据提取完整过程
网站在进行新用户注册时,都会将用户的注册信息存入数据库中,需要的时候再进行提取.今天写了一个简单的实例. 主要完成以下几点功能: (1)用户进行注册,实现密码重复确认,验证码校对功能. (2)注册成功 ...
- javascript(js)中的substring和substr方法
1. substring 方法 定义和用法: substring 方法用于提取字符串中介于两个指定下标之间的字符. 语法: stringObject.substring(start,end) 参数 ...
- 【HDOJ】2699 Five in a Row
wa了几次,至少要考虑4个方向:下.右.左下.右下.很像当年北航的机试题目. /* 2699 */ #include <iostream> #include <cstdio> ...
- 【gm】
gm : GraphicsMagick for node.js aheckmann/gm imgAreaSelect 图片剪裁 apt-get install imagemagick 执行conver ...
- C#导出数据的EXCEL模板设计
一:将如下图中,查询出来的数据导出到EXCEL中 二:Excel的状态 三:设计的背后工作 四:最后一步,隐藏
- Final对象
常量指不能改变的量. 在Java中用final标志,声明方式和变量类似: final double PI = 3.1415927; 虽然常量名也可以用小写,但为了便于识别,通常使用大写字母表示常量. ...
- Json.Net学习笔记(十) 保持对象引用
更多内容见这里:http://www.cnblogs.com/wuyifu/archive/2013/09/03/3299784.html 默认情况下,Json.Net将通过对象的值来序列化它遇到的所 ...
- [OSX] 取消开机启动
以Pulse Secure为例 参考:https://kb.pulsesecure.net/articles/Pulse_Secure_Article/KB26679 输入指令: launchctl ...
- 《algorithm puzzles》——谜题
这篇文章开始正式<algorithm puzzles>一书中的解谜之旅了! 狼羊菜过河: 谜题:一个人在河边,带着一匹狼.一只羊.一颗卷心菜.他需要用船将这三样东西运至对岸,然而,这艘船空 ...
- Parameterized tests
Parameterized继承自Suite.Parameterized是在参数上实现了Suite,修饰一个测试类,然后提供多组构造函数的参数用于测试不同场景. import java.util.Arr ...