Codeforces Round #260 (Div. 2)A. Laptops

2437 단어
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
2
1 2
2 1

Output
Happy Alex

제목은 n개의 컴퓨터를 제시하고, 컴퓨터마다 가격과 가치가 있으며, 가격이 더 낮고, 가치가 더 높은sad가 존재하느냐고 묻는다...처음에는 신마의 순서를 정하려고 했는데 생각할수록 혼란스러워졌다. 마지막에 입력한ai와bi는 모두 다르고 1에서 n의 범위 안에 있다는 것을 발견했다. 즉, 숫자마다 한 번만 나타날 수 있다는 것이다. 그러면 a[1]=1a[2]=2가 있어야만 가격이 낮고 가치가 높은 것이 나타나지 않는다. 하시는 한 번에 훑어보면 된다.sad...15분밖에 안 지났는데...
 
 
#include <cstdio>
#include <cstring>
#include <cstring>
#define INF 0x3f3f3f3f
using namespace std;
int p[110000] ;
int main()
{
    int i , n , a , b ;
    while(scanf("%d", &n)!=EOF)
    {
        memset(p,-1,sizeof(p));
        for(i = 1 ; i <= n ; i++)
        {
            scanf("%d %d", &a, &b);
            p[a] = b ;
        }
        for(i = 1 ; i <= n ; i++)
            if( p[i] != i )
                break;
        if(i <= n)
            printf("Happy Alex
"); else printf("Poor Alex
"); } return 0; }

좋은 웹페이지 즐겨찾기