`
阿尔萨斯
  • 浏览: 4180728 次
社区版块
存档分类
最新评论

Codeforces 456A Laptops(水题)

 
阅读更多

题目链接:Codeforces 456A Laptops

题目大意:给定一些电脑的价格和质量,问是否存在两台电脑a和b,a的价格大于b,但是质量小于b。

解题思路:开一个数组,记录对应价格的最小质量,然后从价格大的开始枚举,维护质量出现的最低值,如果当前质量大于最低值,则存在。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1e5+5;
const int INF = 0x3f3f3f3f;

int n, p, q, c[maxn];

bool judge () {
    int ans = INF;
    for (int i = 1e5; i >= 0; i--) {
        if (c[i] == INF)
            continue;
        if (c[i] > ans)
            return true;
        ans = c[i];
    }
    return false;
}

int main () {
    scanf("%d", &n);
    memset(c, INF, sizeof(c));

    for (int i = 0; i < n; i++) {
        scanf("%d%d", &p, &q);
        c[p] = min(c[p], q);
    }

    printf("%s\n", judge() ? "Happy Alex" : "Poor Alex");
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics