Laptops CodeForces

来源:互联网 发布:应用数学就业前景知乎 编辑:程序博客网 时间:2024/06/05 10:48

Laptops CodeForces - 456A

题目描述
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).

Example

Input
2
1 2
2 1

Output
Happy Alex

大致题意
每个笔记本有一个价格x和质量y,输入一个数n,表示有n台笔记本,接下来输入n个笔记本的价格和质量。而且1<=x,y<=n 每个笔记本的价格和质量是唯一的。问是否有这么两个笔记本,他们中价格更高的那个质量反而更低,如果有则输出Happy Alex,否则输出Poor Alex。

思路:
1. 用结构体来保存每个笔记本i的x,y。然后根据x从小到大排序,然后再比较相邻两个数的y值大小如果存在i.y>i+1.y则输出Happy Alex。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<vector>#include<cmath>#include<string>#define LL long long  #define maxn 100000using namespace std;struct node{    int x;    int y;};node b[100005];bool cmp(node a,node b){    return a.x<b.x;}int n;int main(){    std::ios::sync_with_stdio(false);    cin>>n;    for(int i=0;i<n;i++){        cin>>b[i].x>>b[i].y;    }    sort(b,b+n,cmp);    int flag=0;    for(int i=1;i<n;i++)    {        if(b[i].y<b[i-1].y)        {            flag=1;            break;        }    }    if(flag==0)    cout<<"Poor Alex" ;    else     cout<<"Happy Alex";    return 0;}

2.因为有n个笔记本,且1<=x,y<=n,所以只有当每个笔记本的x==y时,才不会出现逆序对。所以比较每个电脑的x,y是否相等即可。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<vector>#include<cmath>#include<string>#define LL long long  #define maxn 100000using namespace std;int n;int main(){    int flag=0;     int x,y;    std::ios::sync_with_stdio(false);    cin>>n;    for(int i=1;i<=n;i++)    {        cin>>x>>y;        if(x!=y)        {            flag=1;            break;        }    }    if(flag==0)    cout<<"Poor Alex" ;    else     cout<<"Happy Alex";    return 0;}
0 0
原创粉丝点击