Laptops codeforces
来源:互联网 发布:淘宝秒杀开挂 编辑:程序博客网 时间:2024/05/16 06:35
A. Laptops
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.
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.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
21 22 1
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了但是两组代码得到的结果完全不同,我已经晕了。
个人推荐第一个代码Accepted46 ms74097532014-08-10 06:30:42 A - LaptopsGNU C++
- 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
- 【leetcode】Add Two Numbers 解析以及拓展
- Oracle 11g 学习七:表的约束、集合和序列
- ios 中添加frameworok,实现软件声音和振动
- 创建一个静态数组
- AngularJS第四篇
- Laptops codeforces
- 优先级教训
- map, string 强大的STL
- centos 6.5 无线网络消失问题
- android学习--ExpandableListActivity和SimpleExpandableListAdapter的使用
- 程序猿生存定律——选公司
- 今天天气不错啊
- 王朝云
- BroadcastReceiver使用