Egg Drop(水题)

Description

There is a classic riddle where you are given two eggs and a k-floor building and you want to knowthe highest floor from which you can drop the egg and not have it break.

It turns out that you have stumbled upon some logs detailing someone trying this experiment!The logs contain a series of floor numbers as well as the results of dropping the egg on those floors.You need to compute two quantities—the lowest floor that you can drop the egg from where theegg could break, and the highest floor that you can drop the egg from where the egg might not break.

You know that the egg will not break if dropped from floor 1, and will break if dropped fromfloor k. You also know that the results of the experiment are consistent, so if an egg did not breakfrom floor x, it will not break on any lower floors, and if an egg did break from floor y, it will breakon all higher floors.

Input

The first line of input contains two space-separated integers n and k (1 ≤ n ≤ 100, 3 ≤ k ≤ 100),the number of egg drops and the number of floors of the building, respectively. Each of the followingn lines contains a floor number and the result of the egg drop, separated by a single space. Thefloor number will be between 1 and k, and the result will be either SAFE or BROKEN.

Output

Print, on a single line, two integers separated by a single space. The first integer should be thenumber of the lowest floor from which you can drop the egg and it could break and still be consistentwith the results. The second integer should be the number of the highest floor from which you candrop the egg and it might not break.

Sample Input

2 10

4 SAFE

7 BROKEN

Sample Output

5 6

Sample Input

3 5

2 SAFE

4 SAFE

3 SAFE

Sample Output

5 4

Sample Input

4 3

2 BROKEN

2 BROKEN

1 SAFE

3 BROKEN

Sample Output

2 1

题解:分别记录安全和破碎最大最小楼层,判断输出。

代码如下:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
    int m,n,a[101]={0};
    char b[101][10]={0};
    cin>>m>>n;
    int max=1,min=n;
    for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		if(b[i][0]=='S'&&max<a[i])
			max=a[i];
		else if(b[i][0]=='B'&&min>a[i])
			min=a[i];
	}
	if(max+1==min)
		cout<<min<<" "<<max<<endl;
	else
		cout<<max+1<<" "<<min-1<<endl;
    return 0;
}







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值