Jersey Politics POJ
来源:互联网 发布:网络电视机顶盒功能 编辑:程序博客网 时间:2024/05/16 14:03
传送门
In the newest census of Jersey Cows and Holstein Cows, Wisconsin cows have earned three stalls in the Barn of Representatives. The Jersey Cows currently control the state's redistricting committee. They want to partition the state into three equally sized voting districts such that the Jersey Cows are guaranteed to win elections in at least two of the districts.
Wisconsin has 3*K (1 <= K <= 60) cities of 1,000 cows, numbered 1..3*K, each with a known number (range: 0..1,000) of Jersey Cows. Find a way to partition the state into three districts, each with K cities, such that the Jersey Cows have the majority percentage in at least two of districts.
All supplied input datasets are solvable.
Wisconsin has 3*K (1 <= K <= 60) cities of 1,000 cows, numbered 1..3*K, each with a known number (range: 0..1,000) of Jersey Cows. Find a way to partition the state into three districts, each with K cities, such that the Jersey Cows have the majority percentage in at least two of districts.
All supplied input datasets are solvable.
* Line 1: A single integer, K
* Lines 2..3*K+1: One integer per line, the number of cows in each city that are Jersey Cows. Line i+1 contains city i's cow census.
* Lines 2..3*K+1: One integer per line, the number of cows in each city that are Jersey Cows. Line i+1 contains city i's cow census.
* Lines 1..K: K lines that are the city numbers in district one, one per line
* Lines K+1..2K: K lines that are the city numbers in district two, one per line
* Lines 2K+1..3K: K lines that are the city numbers in district three, one per line
* Lines K+1..2K: K lines that are the city numbers in district two, one per line
* Lines 2K+1..3K: K lines that are the city numbers in district three, one per line
2510500500670400310
123654
Other solutions might be possible. Note that "2 3" would NOT be a district won by the Jerseys, as they would be exactly half of the cows.
题意:给你一个3*k大小的数组
找出一个序列使得至少其中两组k大小的数组的总和>500*k;
先排序找出最小的序列号。
再在剩下的2*k里随机
#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <cstdio>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <time.h>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0);typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;//const int dx[]={-1,0,1,0,-1,-1,1,1};//const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e6+100;const double EPS=1e-7;const int MOD=1000000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;/*lch[root] = build(L1,p-1,L2+1,L2+cnt); rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*//*lch[root] = build(L1,p-1,L2,L2+cnt-1); rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}int a[200],c[200];bool cmp(int x,int y){ return a[x]>a[y];}int main(){ int k; scanf("%d",&k); for(int i=1;i<=3*k;i++) { scanf("%d",&a[i]); c[i]=i; } sort(c+1,c+3*k+1,cmp); while(1) { int cnt1=0,cnt2=0; for(int i=1;i<=k;i++) cnt1+=a[c[i]]; for(int i=(k+1);i<=2*k;i++) cnt2+=a[c[i]]; if(cnt1>k*500&&cnt2>k*500) { for(int i=1;i<=3*k;i++) cout<<c[i]<<endl; return 0; } int x=rand()%k+1,y=rand()%k+k+1; swap(c[x],c[y]); }}
0 0
- POJ 2454 Jersey Politics
- POJ 2454--Jersey Politics
- poj 2454 Jersey Politics
- Jersey Politics POJ
- poj 2454 Jersey Politics dfs
- poj 2454 Jersey Politics(贪心+随机化)
- POJ 2454 Jersey Politics 解题报告(随机化)
- 【POJ 2454】Jersey Politics(RPの神Rand)
- POJ 2454 Jersey Politics 分组问题 随机化算法
- POJ2454--Jersey Politics
- POJ2454:Jersey Politics(贪心+随机化)
- poj2454--Jersey Politics(随机化算法)
- poj_2454 Jersey Politics(贪心+随机)
- Politics
- POJ2454 Jersey Politics ——贪心+随机化算法
- bzoj1732[usaco2005 feb]Jersey Politics 牛的政治 随机化
- Everywhere politics
- jersey
- Incomplete history of a file in git (git-svn)
- UML序列图
- 大数据是什么和大数据技术十大核心原理详解
- Redis与Tomcat 简单Session共享
- 多线程:为什么在while循环中加入System.out.println,线程可以停止
- Jersey Politics POJ
- PHP中error_reporting()用法详解
- hrbust 哈理工 oj 1585 公主之魔镜魔镜 (优先队列)
- NA阶段七种LSA
- 题目1190:大整数排序 九度OJ
- 企业背后的推手—数据可视化软件
- POJ
- C51单片机 AT89S52 定时器使用方法及总结
- 大数据学习网站