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 ...
随机推荐
- HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned
参考: .Net HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is re ...
- 如何使用json在前后台进行数据传输
上一篇博客写到用javascript生成多组文本,可以让数据的输入不受显示,现在我们需要把这些输入写入数据库,这里就用到json传入. 首先,我们来写一下后台如何生成要传输的数据 function g ...
- BZOJ1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 4 ...
- call, apply && bind, currying
简要概括: apply(): 将函数作为指定对象的方法来调用,传递给它的是指定的参数数组 ——function.apply(thisobj, args) 或者 function.apply(thiso ...
- Timeout for tests
如果想把timeout太久的测试自动标记为失败,有两种方法: 1.在 @Test里加上 Timeout 参数 定义"timeout=1000“的话,如果超过1000 毫秒,failure会被 ...
- Keywords Search - HDU 2222(AC自动机模板)
题目大意:输入几个子串,然后输入一个母串,问在母串里面包含几个子串. 分析:刚学习的AC自动机,据说这是个最基础的模板题,所以也是用了最基本的写法来完成的,当然也借鉴了别人的代码思想,确实是个很神 ...
- myeclipse 闪退解决方法
今天提交一个svn文件发生卡死,然后关闭myeclipse后发生,打开myeclipse出险闪退,摸索半天,发现: 只要修改下工作空间的名称,然后打开myeclipse重新导入即可,只是之前的配置都没 ...
- angularJS 指令二
指令详解1.用directive()方法来定义指令.directive('myDirective',function($timeout,userDefinedService){ return {};} ...
- swiper.js 移动端触摸滑动插件
API链接: http://www.swiper.com.cn/api/start/2014/1218/140.html <body> <div class="swiper ...
- Spring Boot 入门概念介绍
使用spring-boot快速开发spring应用 转 http://itindex.net/detail/49108-spring-boot-%E5%BC%80%E5%8F%91 spring多年以 ...