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;}
- Laptops codeforces
- Laptops CodeForces
- Codeforces 456 A. Laptops
- CodeForces 456A Laptops
- Codeforces 456A Laptops(水题)
- Laptops
- Codeforces Round #260 (Div. 2)A. Laptops
- Codeforces Round #260 (Div. 2)A. Laptops
- codeforces #260 A. Laptops(水)
- Codeforces Round #260 (Div. 2) A. Laptops
- Codeforces Round #260 (Div. 2) A. Laptops
- ACM篇:Codeforces 456A-- Laptops
- Codeforces Round #260 (Div. 2) A. Laptops【水】
- Codeforces Round #260 (Div. 2) A. Laptops(简单题)
- Codeforces Round #260 (Div. 2)456A - Laptops
- Codeforces Round #260 (Div. 2) 第一题A. Laptops
- A. Laptops
- A. Laptops
- 软件测试和开发的区别在哪里?
- Andoid命名规范个人笔记
- eclipse提示功能失效
- Sping不能自动注入
- 容器跨主机通信之NAT
- Laptops CodeForces
- 设置linux共享目录
- 解决Oracle 11g在用EXP导出时,空表不能导出
- 同步/异步,阻塞/非阻塞区别
- NV12 图像数据的旋转
- 2016年全面前端面试题总结
- Spring Security笔记
- width:100%和height:auto区别
- 日期转换错误