Poj:2674-linear World (Name Exchange collision) __ Elastic collision

Source: Internet
Author: User
Tags abs time limit
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 in eggs and oranges for too long and set out for the Antipodes so On learned that the reason why distant ships sometimes looked as though they and were over the edge of the world Was this they were disappearing over the edge of the world. (Terry pratchett-colour of Magic)
Not, long time ago people used to believe, they live on 2-d world and if they would travel long enough in one directi On, they'll fall down the edge. Even when it was proved this is rounded some of them were still afraid to travel to the southern.
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 in the same time and suddenly all of them Constant velocity) in one or the other direction. If two inhabitants encounter each other, they politely exchange greetings and then they turn around and a n 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 while (counting from moment On) is the last one to fall away. You can assume this 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 defines the number of inhabitants (n<32000). The Data set starting with value n=0 represents the "end of" 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 a order of increasing POS (positive direction):
Dir–initia L direction (' P ' or ' P ' for positive and ' n ' or ' n ' to negative)
Pos–position in the time of Creation (0<=POS&L T;=L)
Name–name of inhabitant (string up to $ characters)
Input values within one line are separated with at least one space and there'll be no empty lines in input. You could assume that the input is always correct and so each of the data set has only one unique solution. Output

The output consists of one line per each input data set. The the ' the ' the ' the ' inhabitant ' is the ' time ' ' the ' linear world counting ' moment of ' crea tion. Value should is printed truncated to two decimal places in a field characters wide. The second value should be the name of the inhabitant. Values should be separated with a 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

Tips for solving problems: the point is that there is a wooden rod Len, give you n personal walk in the wood, each person has their own direction and position, you can go forward can also go backwards, everyone is the same speed, if two people collided so two people instantaneous turn around at the same speed reverse operation, Ask the last person to drop the time of the wooden pole and the name of that person. And the Ant line a train of thought, two people collided can be seen as two people directly from the other body through the past, but this problem is more than a two people wear each other after the exchange of names. So how do you know what the last person's name is? You can work out who is the last person to fall if you do not exchange names, and then see how many people will collide (because of speed), and how many collisions (because of velocity) in the direction in which he walks in the opposite direction. Because each collision of the person's name can only be passed to his direction in front of a person, so this person's name is passed to the front k times. There is this problem in the input and output to do things really do not mean. Note that both P and P are forward, the output retains two decimal places (not rounded), and the number is 13 digits long.

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

 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.