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 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.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
2 1 2 2 1
Happy Alex
解题思路:
题意是说输入n,然后n行,每行两个数a和b,代表笔记本的价格和质量。Alex认为价格便宜的质量也有可能高,
如果Alex说得对,输出Happy Alex,否则输出Poor Alex。
开个结构体,输入完后把价格a按从小到大排个序,然后遍历,如果发现后者的质量比前者的小,那么flag置为
1,说明Alex说得对。
完整代码:
#include <functional> #include <algorithm> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <numeric> #include <cstring> #include <climits> #include <cassert> #include <complex> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; #define REP(i, n) for (int i=0;i<n;++i) #define FOR(i, a, b) for (int i=a;i<b;++i) #define DWN(i, b, a) for (int i=b-1;i>=a;--i) #define REP_1(i, n) for (LL i=1;i<=n;++i) #define FOR_1(i, a, b) for (int i=a;i<=b;++i) #define DWN_1(i, b, a) for (LL i=b;i>=a;--i) #define REP_C(i, n) for (int n____=n,i=0;i<n____;++i) #define FOR_C(i, a, b) for (int b____=b,i=a;i<b____;++i) #define DWN_C(i, b, a) for (int a____=a,i=b-1;i>=a____;--i) #define REP_N(i, n) for (i=0;i<n;++i) #define FOR_N(i, a, b) for (i=a;i<b;++i) #define DWN_N(i, b, a) for (i=b-1;i>=a;--i) #define REP_1_C(i, n) for (int n____=n,i=1;i<=n____;++i) #define FOR_1_C(i, a, b) for (int b____=b,i=a;i<=b____;++i) #define DWN_1_C(i, b, a) for (int a____=a,i=b;i>=a____;--i) #define REP_1_N(i, n) for (i=1;i<=n;++i) #define FOR_1_N(i, a, b) for (i=a;i<=b;++i) #define DWN_1_N(i, b, a) for (i=b;i>=a;--i) #define REP_C_N(i, n) for (int n____=(i=0,n);i<n____;++i) #define FOR_C_N(i, a, b) for (int b____=(i=0,b);i<b____;++i) #define DWN_C_N(i, b, a) for (int a____=(i=b-1,a);i>=a____;--i) #define REP_1_C_N(i, n) for (int n____=(i=1,n);i<=n____;++i) #define FOR_1_C_N(i, a, b) for (int b____=(i=a,b);i<=b____;++i) #define DWN_1_C_N(i, b, a) for (int a____=(i=b,a);i>=a____;--i) #define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it) #define REP_S(i, str) for (char*i=str;*i;++i) #define REP_L(i, hd, suc) for (int i=hd;i;i=suc[i]) #define REP_G(i, u) REP_L(i,hd[u],suc) #define REP_SS(x, s) for (int x=s;x;x=(x-1)&s) #define DO(n) for ( int ____n = n; ____n-->0; ) #define REP_2(i, j, n, m) REP(i, n) REP(j, m) #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) #define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) #define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) #define ALL(A) A.begin(), A.end() #define LLA(A) A.rbegin(), A.rend() #define CPY(A, B) memcpy(A, B, sizeof(A)) #define INS(A, P, B) A.insert(A.begin() + P, B) #define ERS(A, P) A.erase(A.begin() + P) #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define UBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define CTN(T, x) (T.find(x) != T.end()) #define SZ(A) int((A).size()) typedef long long LL; //typedef long double DB; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); //M_PI; struct node { int a , b; }q[1000010]; bool cmp(node x , node y) { return x.a < y.a; } int main() { #ifdef DoubleQ freopen("in.txt","r",stdin); #endif int n; while(~scanf("%d",&n)) { for(int i = 0 ; i < n ; i ++) scanf("%d%d",&q[i].a , &q[i].b); sort(q , q + n , cmp); int flag = 0; for(int i = 1 ; i < n ; i ++) { if(q[i - 1].b > q[i].b ) { flag = 1; break; } } if(flag) printf("Happy Alex\n"); else printf("Poor Alex\n"); } }