zoukankan      html  css  js  c++  java
  • POJ 2674

    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
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <cmath>
     6 
     7 using namespace std;
     8 
     9 #define MAX_N 33000
    10 
    11 struct ant {
    12         char dir;
    13         double pos;
    14         string name;
    15 };
    16 int N;
    17 double L,V;
    18 ant s[MAX_N];
    19 double p[MAX_N];
    20 
    21 void solve() {
    22         double t = 0;
    23         for(int i = 0; i < N; ++i) {
    24                 double e;
    25                 e = (s[i].dir == 'p' ||
    26                     s[i].dir == 'P') ? L : 0.0;
    27                 t = max(t,fabs(e - s[i].pos));
    28         }
    29 
    30         for(int i = 0; i < N; ++i) {
    31                 if(s[i].dir == 'p'
    32                    || s[i].dir == 'P') {
    33                         p[i] = s[i].pos + t;
    34                 } else {
    35                         p[i] = s[i].pos - t;
    36                 }
    37         }
    38 
    39         sort(p,p + N);
    40         int pos;
    41         for(int i = 0; i < N; ++i) {
    42                 if(p[i] == 0.0 || p[i] == L) {
    43                         pos = i;
    44                         break;
    45                 }
    46         }
    47         int t1 = (t / V) * 100;
    48         printf("%13.2f ",(double)t1 / 100.0);
    49         cout << s[pos].name << endl;
    50 
    51 
    52 }
    53 
    54 int main()
    55 {
    56     //freopen("sw.in","r",stdin);
    57 
    58     while(~scanf("%d",&N) && N) {
    59             scanf("%lf%lf",&L,&V);
    60             for(int i = 0; i < N; ++i) {
    61                     scanf(" %c%lf",&s[i].dir,&s[i].pos);
    62                     cin >> s[i].name;
    63 
    64             }
    65 
    66             //printf("%d
    ",(int));
    67 
    68             /*for(int i = 0; i < N; ++i) cout << s[i].dir << " "
    69                                             << s[i].pos << " "
    70                                             << s[i].name << endl;*/
    71 
    72             solve();
    73     }
    74     //cout << "Hello world!" << endl;
    75     return 0;
    76 }
    View Code
  • 相关阅读:
    配置文件中文件重复
    大型网站技术架构02
    2018.12.26-12.30第一周毕设计划
    软件架构模式-分层架构II
    软件架构模式-分层架构
    echarts实现中国地图数据展示
    Python数据分析入门(一)——了解Python下的函数包
    Python学习笔记(二)
    Python学习笔记(一)
    Echarts的简单使用
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3653053.html
Copyright © 2011-2022 走看看