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的更多相关文章

  1. POJ 2674 Linear world(弹性碰撞)

    Linear world Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4426   Accepted: 1006 Desc ...

  2. Greedy:Linear world(POJ 2674)

      Linear world 题目大意:一些人生活在线性世界中,到达线性世界两端就会消失,两个人的前进方向有两个,相遇会改变各自相遇方向,求最后一个人掉下的人的名字和时间. 其实这一题就是弹性碰撞的模 ...

  3. POJ 2674

    Linear world Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2448   Accepted: 564 Descr ...

  4. poj 2674 线性世界 弹性碰撞

    弹性碰撞的题目一般都是指碰到就会掉转方向的一类题目,这里我们可以忽略掉头,仅仅看成擦肩而过,交换名字等等 题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名 ...

  5. ProgrammingContestChallengeBook

    POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...

  6. [POJ 2420] A Star not a Tree?

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 200 ...

  7. 萌新笔记——Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))

    在上篇,我了解了基数的基本概念,现在进入Linear Counting算法的学习. 理解颇浅,还请大神指点! http://blog.codinglabs.org/articles/algorithm ...

  8. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  9. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

随机推荐

  1. zabbix 参数说明

    <pre name="code" class="html">数据采集的工作模式可以分为被动模式(服务器端到客户端采集数据) 主动模式(客户端主动上报 ...

  2. ZOJ-2008-Invitation Cards(dijkstra)

    题意: 在有向加权图中G(V,E),邮局要从起点S向其他n个节点发送邮件,于是派出n个邮递员,分别到达其他n个地点发送,然后回到起点S,求出所有邮递员所经过的总路程的最小值. 分析: 正向一次dijk ...

  3. Python操作Excel_输出所有内容(包含中文)

    python 2.7.5代码: # coding=utf-8 import sys import xlrd data=xlrd.open_workbook('D:\\menu.xls') table ...

  4. ie中弹出框中元素的定位

    用selenium在ie8浏览器中定位一个弹出框时,直接用ie developer tools可能不一定能定位到,有一个解决的办法是直接在url后面加上#noHide,刷新后,然后再用ie devel ...

  5. Sort Colors —— LeetCode

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  6. bzoj 1093 [ZJOI2007]最大半连通子图(scc+DP)

    1093: [ZJOI2007]最大半连通子图 Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2286  Solved: 897[Submit][St ...

  7. Jenkins 十: 访问控制

    1. 打开“系统管理” –> “Configure Global Security”. 2.  选中“启用安全”. 3. 找到“安全域”,选中“Jenkins专有数据库”,选中“允许用户注册”. ...

  8. 启动tomcat时报classpath not found

    启动tomcat时报classpath  not found 原因是缺包,首先查看tomcat安装地址,然后找到webapps目录下,找到该项目,看lib下是否缺包,不能单纯的看项目下是否缺包.

  9. redis学习心得之二【redis主从配置】

    在前一节我们已经实践启动了一个redis服务,我们将其作为主机,现为其创建一个从机作备份使用 1.复制一份配置出来为从机所用 ~$ cp       redis/etc/redis.conf     ...

  10. php开启curl和openssl

    php开启curl和openssl 开启php curl函数库的步骤 1).去掉windows/php.ini 文件里;extension=php_curl.dll前面的; /*用 echo phpi ...