您的位置:首页 > 运维架构

Codeforces 456A Laptops(水题)

2014-08-09 11:32 274 查看
题目链接: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: