POJ 3664 Election Time

Election Time

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7845   Accepted: 4176

Description

The cows are having their first election after overthrowing the tyrannical Farmer John, and Bessie is one of N cows (1 ≤ N ≤ 50,000) running for President. Before the election actually happens, however, Bessie wants to determine who has
the best chance of winning.

The election consists of two rounds. In the first round, the K cows (1 ≤ K ≤ N) cows with the most votes advance to the second round. In the second round, the cow with the most votes becomes President.

Given that cow i expects to get Ai votes (1 ≤ Ai ≤ 1,000,000,000) in the first round and Bi votes (1 ≤ Bi ≤ 1,000,000,000) in the second round (if he or she makes it),
determine which cow is expected to win the election. Happily for you, no vote count appears twice in the Ai list; likewise, no vote count appears twice in the Bi list.

Input

* Line 1: Two space-separated integers: N and K

* Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi

Output

* Line 1: The index of the cow that is expected to win the election.

Sample Input

5 3
3 10
9 2
5 6
8 4
6 5

Sample Output

5

水题,结构体排序,要按第一次得票和第二次得票排两次序,第一次对n个排序,第二次对前k个排序。

#include <stdio.h>
#include <algorithm>
using namespace std;
typedef __int64 ll;

const int maxn=50000+10;

struct pp
{
	ll first,second;
	int id;
}s[maxn];

int cmp1(const pp &x,const pp &y){
	return x.first>y.first;
}

int cmp2(const pp &x,const pp &y){
	return x.second>y.second;
}

int main()
{
	int n,k,i,j,ans;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%I64d%I64d",&s[i].first,&s[i].second);
		s[i].id=i+1;
	}
	sort(s,s+n,cmp1);
	sort(s,s+k,cmp2);		//注意第二次是前k个
	printf("%d\n",s[0].id);
	return 0;
}
时间: 2024-10-14 21:35:42

POJ 3664 Election Time的相关文章

POJ 3664 Election Time 题解

http://www.xiashuw.com/xs/0/906/3042958.htmlhttp://www.xiashuw.com/xs/0/906/3042960.htmlhttp://www.xiashuw.com/xs/0/906/3042961.htmlhttp://www.xiashuw.com/xs/0/906/3042963.htmlhttp://www.xiashuw.com/xs/0/906/3042964.htmlhttp://www.xiashuw.com/xs/0/90

POJ 3664

水水更健康 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int N=50100; struct COW{ int f,s,d; }cows[N]; bool cmp1(COW a,COW b){ if(a.f>b.f) return true;

POJ 3905 Perfect Election(2-sat)

POJ 3905 Perfect Election 题目链接 思路:很裸的2-sat,就根据题意建边即可 代码: #include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; const int MAXNODE = 2005; struct TwoSet { int n; vec

POJ 3905 Perfect Election (初学2-Sat)

这篇从原理上理解2-sat如何转化成图论问题简述了如何了实现算法:http://wenku.baidu.com/view/31fd7200bed5b9f3f90f1ce2.html 总的来说2-sat有两种算法,一种用dfs染色搜索出一种解,一种用tarjan(判定是否有解)+拓扑排序构造出任意一个可行解. dfs从理论上复杂度很高,但是实际上远远达不到上界,而且可以按字典序搜索,实现也简单多了 大致题意: 有n个候选人,m组要求,每组要求关系到候选人中的两个人,"+i +j"代表i和

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

POJ 2528 Mayor&#39;s posters(离散化线段树)

Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for

Poj 2528-Mayor&#39;s posters 线段切割

题目:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55156   Accepted: 16000 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have

【POJ】 2528 - Mayor&#39;s posters 【线段树+离散化】

题目: Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47228   Accepted: 13719 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral

POJ 2528——Mayor&#39;s posters——————【线段树区间替换、找存在的不同区间】

Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2528 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been plac