POJ:2674-Linear world(名字交换碰撞)
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
解题心得:
- 题意就是有一个木杆长len,给你n个人在木杆上走,每个人有自己的方向和位置,可以向前走也可以向后走,每个人速度相同,如果两个人相撞了那么两个人瞬间掉头以相同的速度反向运行,问最后一个人掉下木杆的时间和那个人的名字。
- 和蚂蚁走线一个思路,两个人相撞就可以看做两个人直接从对方身体穿过去了,但是这个题还多了一个两个人互相穿过去之后还交换了名字。那么怎么知道最后一个人的名字是什么呢。可以先算出如果不交换名字最后掉下去的人是谁,然后看在他行走的方向和他方向相反的人有几个,,有多少人就会有多少次碰撞(因为速度一样),假设有k个。因为每次碰撞这个人的名字都只能传给他方向上的前面一个人,所以这个人的名字就向前面传递了k次。
- 还有这个题在输入输出上搞事情真的没啥意思。注意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(名字交换碰撞)的更多相关文章
- POJ 2674 Linear world
POJ 2674 Linear world 题目大意: 一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的时间和名字. 注意两点: 相撞可视为擦肩而过,蚂蚁们不管掉 ...
- 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 ...
- cocos 碰撞系统
前面的话 本文将简要介绍 Cocos Creator 中的碰撞系统,Cocos Creator 内置了一个简单易用的碰撞检测系统,支持圆形.矩形以及多边形相互间的碰撞检测 编辑碰撞组件 当添加了一个碰 ...
- Ubuntu 16.04 64位安装arm-linux-gcc交叉编译器以及samba服务器
交叉编译器是嵌入式开发的必要工具,但是由于目前大多数人使用64位ubuntu,在照着很多教程做的时候,就会失败,失败原因是64位ubuntu需要额外安装32位的兼容包.以arm-linux-gcc-3 ...
- 关于Server2008 R2日志的查看
Server 2008 r2通过 系统事件查看器 分析日志: 查看 系统 事件: 事件ID号: 审计目录服务访问 4934 - Active Directory 对象的属性被复制 4935 -复制失败 ...
随机推荐
- better-scroll 遇到的问题 1
备注:better-scroll 实现下拉,是父子层的结构,父层的第一个子元素,如果超出父容器,那么就可以实现下拉 问题: 今天在使用better-scroll实现下拉功能,遇到了一个问题 &quo ...
- 如何在K3 WISE BOS集成开发工具中自定义字段过滤条件
1.结论 对于输入过滤条件后BOS报“列名不正确”的过滤条件,要在列名前增加x2标识 无效的过滤 FNumber ,,,,,) 正确的过滤 x2.FNumber ,,,,,) 2.完全可以不看的探索过 ...
- 如何找到Android app启动activity和页面元素信息
在实施app自动化的时候,我们需要知道app 的启动activity和页面元素信息,以此启动app和定位页面元素,那么如何在没有源码的情况下找打他们呢?当然是有好的工具啦,有Android sdk自带 ...
- Java—继承
继承 继承是类与类的一种关系,是一种“is a”的关系.注意:java中的继承是单继承,一个类只有一个父类. 继承的好处:子类拥有父类的所有属性和方法(private修饰的无效),实现代码的复用 语法 ...
- Multi-modal Sentence Summarization with Modality Attention and Image Filtering 论文笔记
文章已同步更新在https://ldzhangyx.github.io/,欢迎访问评论. 五个月没写博客了,不熟悉我的人大概以为我挂了…… 总之呢这段时间还是成长了很多,在加拿大实习的两个多月来 ...
- Hybris开发环境的license计算实现
每隔30天,必须重新执行一次initialize命令把本地所有数据全部清掉然后重新build,需要花费一些时间. 显示在console里的license信息通过license.jsp展示: 剩余的li ...
- node 上的cookie的签名和解签名
cookie签名的原因是防止别人篡改cookie原本的值,如果这个过程中cookie被改变的话,就会在unsign方法返回false 代码: var cookie = require("co ...
- 搭建FTP服务
(一)FTP服务概述 FTP服务概述:名称.功能.特点.端口 VSFTP:very secure FTP 端口:21 服务安装#yum install vsftpd lftp -y ##lftp ...
- 【CCPC-Wannafly Winter Camp Day4 (Div1) F】小小马(分类讨论)
点此看题面 大致题意: 给你一张\(n*m\)的棋盘,问你一匹马在两个点中是否存在一条经过黑白格子数目相等的路径. 简化题目 首先,我们来简化一下题目. 考虑到马每次走的时候,所经过的格子的颜色必然发 ...
- 转:SSM框架——使用MyBatis Generator自动创建代码
转:https://blog.csdn.net/zhshulin/article/details/23912615 这两天需要用到MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的 ...