Laptops codeforces

来源:互联网 发布:淘宝秒杀开挂 编辑:程序博客网 时间:2024/05/16 06:35

A. Laptops
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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).

Sample test(s)
input
21 22 1
output
Happy Alex
题意:就是让你找出只要存在低价钱可以买高品质的东西,每行输入电脑的价钱和品质。题目很简单;
贴一个一般的做法:
/*#include <iostream>#include<cstdio>using namespace std;int main(){int n,f=0,x,y;    scanf("%d",&n);while(n--){scanf("%d %d",&x,&y);if(x!=y) f=1;}if(f) puts("Happy Alex");else puts("Poor Alex");return 0;}*//*#include <stdio.h>int x;int main(){scanf("%d",&x);putchar(x%4?48:52);return 0;}*//*#include <bits/stdc++.h>int main() {    long long a;    scanf("%lld", &a);    printf("%d", (a % 4 == 0) * 4);}*/#include<iostream>#include<algorithm>#include<cstdio>using namespace std;struct node{    int p,q;}a[100001];bool cmp(node i,node j){    return i.p<j.p;}int main(){    int n,i;    int out=1;    scanf("%d",&n);    for(i=0;i<n;i++)    {        scanf("%d %d",&a[i].p,&a[i].q);    }    sort(a,a+n,cmp);    for(i=1;i<n;i++)    {        if(a[i-1].q>a[i].q)//这是只要存在高价能买高质量的就行了        {            out=0;            break;        }    }    if(!out)        puts("Happy Alex");    else        puts("Poor Alex");    return 0;}

后面看了一些神牛的代码发现只要该种电脑的质量和价格不相等就一定能够得到高质量低价格的:
#include <iostream>#include<cstdio>using namespace std;int main(){int n,f=0,x,y;    scanf("%d",&n);while(n--){scanf("%d %d",&x,&y);if(x!=y) f=1;}if(f) puts("Happy Alex");else puts("Poor Alex");return 0;}
虽然说AC了但是两组代码得到的结果完全不同,我已经晕了。
个人推荐第一个代码LangVerdictTimeMemory74097532014-08-10 06:30:42 A - LaptopsGNU C++Accepted46 ms 
1 0