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.
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops.
Next n lines contain two integers each,ai andbi(1 ≤ ai, bi ≤ n), whereai is the price of thei-th laptop, and bi is the number that represents the quality of thei-th laptop (the larger the number is, the higher is the quality).
All ai are distinct. Allbi are distinct.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
2 1 2 2 1
Happy Alex
水题:
#include<bits/stdc++.h> #define MAX 100010 struct node { int a,b; }hh[MAX]; int cmp(const void *a,const void *b) { node *p1=(node *)a,*p2=(node *)b; if(p1->a!=p2->a) return p1->a-p2->a; else { return p1->b-p2->b; } } int main() { int n,i; bool flag; while(~scanf("%d",&n)) { flag=false; for(i=0;i<n;i++) { scanf("%d%d",&hh[i].a,&hh[i].b); } qsort(hh,n,sizeof(hh[0]),cmp); for(i=0;i<n-1;i++) { if(hh[i+1].b<hh[i].b) { flag=true; break; } } if(flag) printf("Happy Alex\n"); else printf("Poor Alex\n"); } return 0; }