Linear world

Time Limit: 3000MS Memory Limit: 65536K

Total Submissions: 4514 Accepted: 1025

Description

The Disc, being flat, has no real horizon. Any adventurous sailors who get funny ideas from staring at eggs and oranges for too long and set out for the antipodes soon learned that the reason why distant ships sometimes looked as though they were disappearing over the edge of the world was that they were disappearing over the edge of the world. (Terry Pratchett -Colour of Magic)

Not so long time ago people used to believe that they live on 2-D world and if they will travel long enough in one direction, they will fall down over the edge. Even when it was proved that the Earth is rounded some of them were still afraid to travel to the southern hemisphere.

Try to imagine one 1-D (linear) world. On such world there are only two possible directions (left and right). All inhabitants of such world were created exactly at the same time and suddenly all of them start to move (all with same constant velocity) in one or the other direction. If two inhabitants encounter each other, they politely exchange greetings and then they turn around and start to move in an opposite direction. When an inhabitant reaches the end of the world he falls away and disappears.

Your task is to determine, for a given scenario of creation, which inhabitant and when (counting from the moment of creation) will be the last one to fall away. You can assume that the time required to exchange greetings and turn around is 0.

Input

The input consists of multiple descriptions (data sets) of the creation moment. File structure is as follows:

N

LV

DIR POS NAME



The first line defines the number of inhabitants (N<32000). Data set starting with value N=0 represents the end of the input file. The second line contains length of the world L(float) and velocity of inhabitants V(float). Both values are always positive. In next N lines the data about inhabitants are given in an order of increasing POS (positive direction):

DIR – initial direction (‘p’ or ‘P’ for positive and ‘n’ or ‘N’ for negative)

POS – position in the time of creation (0<=POS<=L)

NAME – name of inhabitant (string up to 250 characters)

Input values within one line are separated with at least one space and there will be no empty lines in input. You may assume that input is always correct and that each data set has only one unique solution.

Output

The output consists of one line per each input data set. The first value should be the time when the last inhabitant will fall of the linear world counting from the moment of creation. Value should be printed truncated to two decimal places in a field 13 characters wide. The second value should be the name of the inhabitant. Values should be separated with single space character.

Sample Input

1

13.5 2

p 3.5 Smarty

4

10 1

p 1 Helga

n 3 Joanna

p 5 Venus

n 7 Clever

0

Sample Output

     5.00 Smarty
9.00 Venus

解题心得:

  1. 题意就是有一个木杆长len,给你n个人在木杆上走,每个人有自己的方向和位置,可以向前走也可以向后走,每个人速度相同,如果两个人相撞了那么两个人瞬间掉头以相同的速度反向运行,问最后一个人掉下木杆的时间和那个人的名字。
  2. 和蚂蚁走线一个思路,两个人相撞就可以看做两个人直接从对方身体穿过去了,但是这个题还多了一个两个人互相穿过去之后还交换了名字。那么怎么知道最后一个人的名字是什么呢。可以先算出如果不交换名字最后掉下去的人是谁,然后看在他行走的方向和他方向相反的人有几个,,有多少人就会有多少次碰撞(因为速度一样),假设有k个。因为每次碰撞这个人的名字都只能传给他方向上的前面一个人,所以这个人的名字就向前面传递了k次。
  3. 还有这个题在输入输出上搞事情真的没啥意思。注意P和p都是向前,输出保留两位小数(不是四舍五入),数字要留够十三个数位。

#include <algorithm>
#include <stdio.h>
#include <climits>
using namespace std;
const int maxn = 4e4+100; struct Inhabitants{
int dir;
double pos,time;
char name[300]; bool operator < (const Inhabitants& a) const {
return abs(a.pos) > abs(pos);
}
}inha[maxn]; int main() {
int n,ans_man;
double v,len,Max;
while(scanf("%d",&n) && n) {
Max = 0.0;
scanf("%lf%lf",&len,&v);
for(int i=0;i<n;i++) {
char temp[5];
scanf("%s%lf%s",temp,&inha[i].pos,inha[i].name);
if(temp[0] == 'p' || temp[0] == 'P')
inha[i].dir = 1;
else
inha[i].dir = 0;
if(inha[i].dir)
inha[i].time = (len-inha[i].pos)/v;
else
inha[i].time = inha[i].pos/v;
}
sort(inha,inha+n);
for(int i=0;i<n;i++) {
if(inha[i].time > Max) {
Max = inha[i].time;
ans_man = i;
}
}
int cnt = 0;
if(inha[ans_man].dir) {
for(int i=ans_man;i<n;i++)
if(inha[i].dir != inha[ans_man].dir)
cnt++;
ans_man += cnt;
} else {
for(int i=ans_man;i>=0;i--)
if(inha[i].dir != inha[ans_man].dir)
cnt++;
ans_man -= cnt;
}
printf("%13.2f %s\n",(int)(Max*100)/100.0,inha[ans_man].name);
}
return 0;
}

POJ:2674-Linear world(名字交换碰撞)的更多相关文章

  1. POJ 2674 Linear world

    POJ 2674 Linear world 题目大意: 一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的时间和名字. 注意两点: 相撞可视为擦肩而过,蚂蚁们不管掉 ...

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

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

  3. Greedy:Linear world(POJ 2674)

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

  4. POJ 2674

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

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

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

  6. ProgrammingContestChallengeBook

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

  7. cocos 碰撞系统

    前面的话 本文将简要介绍 Cocos Creator 中的碰撞系统,Cocos Creator 内置了一个简单易用的碰撞检测系统,支持圆形.矩形以及多边形相互间的碰撞检测 编辑碰撞组件 当添加了一个碰 ...

  8. Ubuntu 16.04 64位安装arm-linux-gcc交叉编译器以及samba服务器

    交叉编译器是嵌入式开发的必要工具,但是由于目前大多数人使用64位ubuntu,在照着很多教程做的时候,就会失败,失败原因是64位ubuntu需要额外安装32位的兼容包.以arm-linux-gcc-3 ...

  9. 关于Server2008 R2日志的查看

    Server 2008 r2通过 系统事件查看器 分析日志: 查看 系统 事件: 事件ID号: 审计目录服务访问 4934 - Active Directory 对象的属性被复制 4935 -复制失败 ...

随机推荐

  1. 弹性布局 Flexible Box

    页面中任何一个元素都可以指定为 弹性布局(Flex) 属性:display 取值: 1.flex     将块级元素变为弹性布局容器 2.inline-flex   将行内元素变为弹性布局容器 兼容性 ...

  2. JDK、JRE、javac和JVM的关系

      .java为Java的源文件后缀,编写的代码需要写在.java文件中.     Javac编译器,用于读取Java源代码,并将其编译成字节代码.经过javac编译后形成.class,是字节码文件. ...

  3. mybatis怎样自动生成java类,配置文件?

    其实没有什么东西是可以自动生成的,只不过是别人已经写好了,你调用罢了. 所以想要mybatis自动生成java类,配置文件等,就必须要一些配置和一些jar包.当然这些配置也很简单. 为了有个初步的认识 ...

  4. hdu-2844&&POJ-1742 Coins---多重背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目大意: Tony想要买一个东西,他只有n中硬币每种硬币的面值为a[i]每种硬币的数量为c[ ...

  5. 谷歌Web中文开发手冊:3响应式

    https://developers.google.com/web/fundamentals/getting-started/your-first-multi-screen-site/responsi ...

  6. 【CCPC-Wannafly Winter Camp Day3 (Div1) G】排列(水题)

    点此看题面 大致题意:已知 \(p\)为\(n\)的一个排列,定义\(A(p)_i=min_{j=1}^ip_j\),若用\(q_i\)表示\(p\)第\(i\)小的前缀的长度(以值为第一关键字,下标 ...

  7. jade在命令行实时编译

    jade文件: doctype html html head title jade study body h1 imoock jade study 在jade文件夹下,终端输入 jade index. ...

  8. 转:SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)

    转:https://www.cnblogs.com/zyw-205520/p/4771253.html 1.基本概念   1.1.Spring Spring是一个开源框架,Spring是于2003 年 ...

  9. JS面向对象、prototype、call()、apply()

    一. 起因 那天用到prototype.js于是打开看看,才看几行就满头雾水,原因是对js的面向对象不是很熟悉,于是百度+google了一把,最后终于算小有收获,写此纪念一下^_^. prototyp ...

  10. Ubuntu下几种常用的文本编辑器

    常见的基于控制台的文本编辑器有以下几种: emacs           综合性的GNU emacs 编辑环境 nano              一个类似于经典的pico的文本编辑器,内置了一个pi ...