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 ;
}

最新文章

  1. git常用命令1
  2. 夺命雷公狗---DEDECMS----3快速入门之隐藏
  3. OracleHelper 动软生成
  4. 20145129 《Java程序设计》第3周学习总结
  5. 深刻理解Java中final的作用(一):从final的作用剖析String被设计成不可变类的深层原因
  6. 如何同时启动多个Tomcat服务
  7. 基数排序(RadixSort)
  8. 安卓系统运行Debian-7.0环境(Debian for android)
  9. 使用正则表达式给网址添加a标签
  10. iOS开发中的Html解析方法
  11. 关于postgresql group by 报错
  12. Serialization
  13. linux正则表达式(基础正则表达式+扩展正则表达式)
  14. LeetCode 193. Valid Phone Numbers
  15. php设计模式之六大设计原则
  16. Hibernate5笔记8--Hibernate事务相关内容
  17. 「要买车网」免费获取汽车电商要买车网购车优惠券 - 持续更新(2016-03-12)www.fortunelab.cn
  18. 20145314郑凯杰 《Java程序设计》第2周学习总结 代码开始!
  19. JavaScript 访问对象属性和方法及区别
  20. python之设置小数保留位数

热门文章

  1. 【C#】 装箱 (boxing) 和拆箱 (unboxing)
  2. 浅谈objective—C管理内存
  3. linux kernel 0.11 head
  4. spring aop 使用xml方式的简单总结
  5. oracle 配置 oem
  6. [INS-41112] Specified network interface doesnt maintain connectivi
  7. Redo日志
  8. android开发系列之git常用命令
  9. Android动画解析--XML
  10. Swift计算文本宽高