POJ 3664
来源:互联网 发布:python 自动完成 编辑:程序博客网 时间:2024/05/21 07:56
[NWPU][2014][TRN][1]水题堆
7:30:00
//@auther Yang Zongjun#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <string>using namespace std;#define PI acos(-1.0)#define EPS 1e-8const int MAXN = 50005;const int INF = 2100000000;pair<int, int> p[MAXN];pair<int, int> a[MAXN];int n, k;int main(){ freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin); scanf("%d%d", &n, &k); for(int i = 1; i <= n; i++) { scanf("%d%d", &p[i].first, &p[i].second); a[i].first = p[i].first; a[i].second = p[i].second; } sort(p + 1, p + n + 1); //由于sort排序之后,p的顺序,即牛的编号变了,所以我用 //了两个数组p和a //for(int i = 1; i <= n; i++) //printf("%d %d\n", p[i].first, p[i].second); int maxa = p[n].second; for(int i = n; i > n-k; i--) { maxa = max(maxa, p[i].second); } int j; for(int i = 1; i <= n; i++) { if(a[i].second == maxa) { j = i;break; } } printf("%d\n", j); return 0;}
由于sort排序之后,p的顺序,即牛的编号变了,要开两个数组,而下面的代码用结构体,将牛的编号也设置成牛的属性,这样即使排序后每个牛的属性不变
//@auther Yang Zongjun#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <string>using namespace std;#define PI acos(-1.0)#define EPS 1e-8const int MAXN = 50005;const int INF = 2100000000;int n, k;struct Cow{ int f,s,num;}cow[MAXN];bool cmp1(const Cow& a, const Cow& b){ return a.f > b.f;}bool cmp2(const Cow& a, const Cow& b){ return a.s > b.s;}int main(){// freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin); scanf("%d%d", &n, &k); for(int i = 0; i < n; i++) { scanf("%d%d", &cow[i].f, &cow[i].s); cow[i].num = i + 1; } sort(cow, cow + n, cmp1); sort(cow, cow + k, cmp2); printf("%d\n", cow[0].num); return 0;}
0 0
- POJ 3664
- poj-3664
- POJ 3664
- poj 3664
- POJ 3664 排序,水题
- poj 3664 Election Time
- poj 3664 Election Time
- POJ 3664 Election Time
- POJ 3664----Election Time
- POJ 3664 Election Time
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- 3.2 使用不可变数据结构
- 彻底弄清Jquery中html(), text(), val() 的区别.
- c++11之初始化列表
- C4.5算法详解(至今见过写的最好的算法详解)
- acm_icpc网络赛第二站:鞍山赛区
- POJ 3664
- 我的博客第一天
- Lost Cows(树状数组+二分)
- HDU 4998 Rotate
- 黑马程序员--Set集合
- 实现301页面永久重定向
- phpmyadmin安装教程及配置设置
- 线性表之顺序表 源代码
- 在Windows 2008 R2高端机器上运行SQL Server 2008时,CPU个数的考量