Laptops

来源:互联网 发布:定位技术知乎 编辑:程序博客网 时间:2024/06/05 03:42

原题链接
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 0