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. DrawTool多重笔之前奏 => 通过InkAnalyzer实现图形识别

    这里要介绍的是通过InkAnalyzer来实现简单图形的识别,例如圆,椭圆,正方形,三角形等,当然你也可以通过扩展来实现自定义图形的识别,在使用InkAnalyzer前,你需要引用IAWinFX.dl ...

  2. JS中的DOM与BOM

    javascript组成: 1. ECMAScript 基本语法. 2. BOM (浏览器对象模型) 3. DOM (文档对象模型) 一)BOM(borwser Object  Model) 浏览器对 ...

  3. OpenStack:安装Neutron与provider network

    1. 安装(1)Install Networking services on a dedicated network node# apt-get install neutron-server neut ...

  4. 获得N位数字字母随机组合

    import string import random def get_rand(n): allw = string.letters+string.digits r = [] for i in ran ...

  5. iOS学习之Object-C语言内存管理

    一.内存管理的方式      1.iOS应用程序出现Crash(闪退),90%的原因是因为内存问题.      2.内存问题:      1)野指针异常:访问没有所有权的内存,如果想要安全的访问,必须 ...

  6. Asp.NET网站Session浅谈

    .NET网站在Web.config的<configuration>下<system.web>下<sessionState>配置session. sessionSta ...

  7. modelsim仿真错误解决办法

    编译不成功可能是因为: 1.本身程序有问题. 2.没有设置顶层文件 3.modelsim 出现错误是不要只是看错误的地方,也要看前面的一部分

  8. QWidget设置为模态问题

    设置QWidget的Qt::WindowModality属性为Qt::WindowModal和Qt::ApplicationModal,发现窗体仍然不会模态,网上查了一下,有人说改属性只对window ...

  9. python3.4 安装ipython notebook

    1.安装python3.4 2.安装pyreadline 3.安装ipython-1.2.1.zip 4.安装pyzmq-14.7.0-cp34-none-win32.whl,ZIP包有问题,下载wh ...

  10. vtune 不能查看pg的源代码

    在编译的时候,要加enable-debug 选项 并且如果之前有没有加的话,一定要make clean