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

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: 

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

Source

 
类似POJ的 ANTS
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; #define MAX_N 33000 struct ant {
char dir;
double pos;
string name;
};
int N;
double L,V;
ant s[MAX_N];
double p[MAX_N]; void solve() {
double t = ;
for(int i = ; i < N; ++i) {
double e;
e = (s[i].dir == 'p' ||
s[i].dir == 'P') ? L : 0.0;
t = max(t,fabs(e - s[i].pos));
} for(int i = ; i < N; ++i) {
if(s[i].dir == 'p'
|| s[i].dir == 'P') {
p[i] = s[i].pos + t;
} else {
p[i] = s[i].pos - t;
}
} sort(p,p + N);
int pos;
for(int i = ; i < N; ++i) {
if(p[i] == 0.0 || p[i] == L) {
pos = i;
break;
}
}
int t1 = (t / V) * ;
printf("%13.2f ",(double)t1 / 100.0);
cout << s[pos].name << endl; } int main()
{
//freopen("sw.in","r",stdin); while(~scanf("%d",&N) && N) {
scanf("%lf%lf",&L,&V);
for(int i = ; i < N; ++i) {
scanf(" %c%lf",&s[i].dir,&s[i].pos);
cin >> s[i].name; } //printf("%d\n",(int)); /*for(int i = 0; i < N; ++i) cout << s[i].dir << " "
<< s[i].pos << " "
<< s[i].name << endl;*/ solve();
}
//cout << "Hello world!" << endl;
return ;
}

POJ 2674的更多相关文章

  1. POJ 2674 Linear world

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

  2. Greedy:Linear world(POJ 2674)

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

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

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

  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 3370. Halloween treats 抽屉原理 / 鸽巢原理

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

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

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

  8. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  9. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

随机推荐

  1. SegmentFault 2014黑客马拉松 北京 作品demo

    1号作品展示——最熟悉的陌生人 app 利用录音(声纹识别)和照片来让好久不见的见面变得不那么尴尬. 2号作品展示——神奇魔镜 app 灵感来自通话<白雪公主>,穿越到今天的“魔镜”功能依 ...

  2. Socket(1)

    端口号可以从0~65535: 今天就写TCP相关.在下一节我会分别写有关UDP,还有MultiCastSocket. Socket的工作原理: 通信两端都建立一个Socket,从而两端形成虚拟链路.通 ...

  3. hdu 1196 Lowest Bit

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1196 Lowest Bit Description Given an positive integer ...

  4. Table ‘performance_schema.session_variables’ doesn’t exist

    运行mysql时,提示Table ‘performance_schema.session_variables’ doesn’t exist 解决的方法是: 第一步:在管理员命令中输入: mysql_u ...

  5. Machine Learning 学习笔记 (1) —— 线性回归与逻辑回归

    本系列文章允许转载,转载请保留全文! [请先阅读][说明&总目录]http://www.cnblogs.com/tbcaaa8/p/4415055.html 1. 梯度下降法 (Gradien ...

  6. 基于.net mvc的校友录(三、实体模型实现)

    实体模型设计 由于是实际开发,而且是时间比较紧的,所以,在开发实现过程中,总有一些对原计划的改动: AlumniBookModel数据库实体模型 这是主数据实体类,EF会根据此实体生成数据库,它的每一 ...

  7. 最大后验估计(MAP)

    最大后验估计是根据经验数据获得对难以观察的量的点估计.与最大似然估计类似,但是最大的不同时,最大后验估计的融入了要估计量的先验分布在其中.故最大后验估计可以看做规则化的最大似然估计. 首先,我们回顾上 ...

  8. 小组开发项目针对性的NABC分析

    单独就我们团队开发项目——重力解锁的功能特点而言,我们解决了智能手机屏幕解锁的乏味和繁琐的特点,显得更有趣味性和独特性,更符合现代人追随时尚的潮流:我们根据个人的不同喜好和便利性来设定一些动作,利用重 ...

  9. java设计模式类图大全

    近来在看书实现GoF的23个设计模式,自己一点点地用建模工具按照自己的理解画出类图(是比较符合我个人思考理解的,个人觉得比通用类图更详细些),碰巧找到了一个挺好用的UML建模工具StarUML,也刚好 ...

  10. iOS 自定义导航栏 和状态栏

    一.更改状态栏颜色 (StatusBar) 就是比如导航栏是红色的状态栏是绿色的. 要实现这样的效果其实很简单,就是添加一个背景view. 简单的实现过程如下: 1 // 设置导航颜色 可用 2 [s ...