Laptops

原题链接
A. Laptops
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.

Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.

Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops.

Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality).

All ai are distinct. All bi are distinct.

Output
If Alex is correct, print “Happy Alex”, otherwise print “Poor Alex” (without the quotes).

Examples
input
2
1 2
2 1
output
Happy Alex

这个题的关键就是要构造一个结构体用来保存价格p和质量q,然后按照价格排序,若是在排序中相邻的两个元素出现题目中的情况,那么就是找到了。原理就是若是i电脑和i+1电脑不逆序,那么可以视为i电脑和i+1电脑具有相同的性质,但是若是i+2电脑和i+1电脑不一样,那么i+2电脑也必然和i电脑不一样

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 10;
typedef struct com{
        int p,q;
}com;
com a[maxn];
bool cmp(com x,com y){
        return x.p<y.p;
}
int main(){
        freopen("input.txt","r",stdin);
        int T;scanf("%d",&T);
        for(int i=0;i<T;i++) scanf("%d%d",&a[i].p,&a[i].q);
        sort(a,a+T,cmp);
        bool flag = false;
        for(int i=1;i<T;i++){
                if(a[i].q < a[i-1].q){//这里为什么只需要找出一个逆序就可以了,因为如果两个相邻的元素不逆序,那么他们对于后面的元素表现的性质是一样的
                        flag = true;
                        break;
                }
        }
        if(flag) printf("Happy Alex\n");
        else printf("Poor Alex\n");
        return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

门豪杰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值