Hust oj 1046 Balls Collision(水题)

Balls Collision
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 71(51 users)Total Accepted: 49(45 users)Rating: Special Judge: No
Description

  There is an absolutely slippery groove whose length is M miles and the width is 0.2 mile. N balls whose weights are all the same and the radiuses are all 0.1 mile roll in the groove at the speed of 1mile/s in the direction of left or right. when two balls come into collision, there is no energy lost.
Your task is to write a program to output the time at which the first ball rolls down the groove and the time at which the last ball rolls down the groove.

Input

  The input file contains several test cases. The description of each case starts with a line containing two integers M (0<=M<=1000000) and N (1<=N<=100). Each of the following N lines contains the direction (R presents the direction of right and L presents the direction of left) and the distance (in miles) from the left side of the groove at starting time.
The input is terminated by a test case with M= 0 and N = 0. It should not be processed.

Output

  For each test case you should output the time (in second) at which the first ball rolls down the groove and the time (in second) at which the last ball rolls down the groove in a single line.

Sample Input

10 2
R 3
R 9
20 3
L 1
L 11
R 9
0 0

Sample Output

1 7
1 11

这题都快做烂了啊= =蚂蚁感冒

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int n,m;
int x;
int Max,Min;
char desc;

int main()
{
    while(~scanf("%d%d",&m,&n) && (n+m))
    {
        Max = -1;
        Min = 0x3f3f3f;
        getchar();
        for(int i=0;i<n;i++)
        {
            scanf("%c %d",&desc,&x);
            getchar();
            if(desc == 'L')
            {
                int temp = x;
                if(Max < temp)
                    Max = temp;
                if(Min > temp)
                    Min = temp;
            }
            else
            {
                int temp = m - x;
                if(Max < temp)
                    Max = temp;
                if(Min > temp)
                    Min = temp;
            }
        }
        printf("%d %d\n",Min,Max);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值