POJ2454 Jersey Politics
Description
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.
Input
* 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.
Output
* 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
Sample Input
2
510
500
500
670
400
310
Sample Output
1
2
3
6
5
4
Hint
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctime>
using namespace std;
struct ZYYS
{
int x,id;
}a[];
int k,sum1,sum2;
bool cmp(ZYYS a,ZYYS b)
{
return a.x>b.x;
}
int main()
{int i,j;
cin>>k;
for (i=;i<=*k;i++)
{
scanf("%d",&a[i].x);
a[i].id=i;
}
sort(a+,a+*k+,cmp);
for (i=;i<=k;i++)
sum1+=a[i].x,sum2+=a[i+k].x;
srand(time());
while (!(sum1>*k&&sum2>*k))
{
int x1=rand()%k+,x2=rand()%k++k;
sum1=sum1-a[x1].x+a[x2].x;
sum2=sum2-a[x2].x+a[x1].x;
swap(a[x1],a[x2]);
}
for (i=;i<=*k;i++)
printf("%d\n",a[i].id);
}
POJ2454 Jersey Politics的更多相关文章
- POJ2454——Jersey Politics
POJ2454——Jersey Politics 题目大意: 在泽西奶牛和荷斯坦奶牛的最新普查中,威斯康星奶牛在谷仓中获得了三个档位. 泽西奶牛目前控制着国家重新分配委员会. 他们想将国家分为三个相当 ...
- [USACO2005][POJ2454]Jersey Politics(随机化)
题目:http://poj.org/problem?id=2454 题意:给你3*k(k<=60)个数,你要将它们分成3个长度为k的序列,使得其中至少有两个序列的和大于k*500 分析:以为有高 ...
- 【数学】Jersey Politics
Jersey Politics Time Limit: 1000MS Memory ...
- Jersey Politics
poj2454:http://poj.org/problem?id=2454 题意:给你3*k个数,然后让你分成三堆,使得至少其中的两堆中的数字之和大于500*k.题解:这道题一开始我并不知道怎么做, ...
- poj 2454 Jersey Politics 随机化
随机化算法+贪心! 将3*k排序后分成3分,将第二第三份的和分别加起来,让和与500*k比较,都大于则输出,否则,随机生成2个数,在第二第三份中交换! 代码如下: #include<iostre ...
- poj 2454 Jersey Politics dfs
这个题目第一步还是比较明显的,先把最小的n个值去掉,剩下的问题就是能不能把数据分成两半,使得每一半和都大于n*500,这个刚开始考虑了下dp的做法,但是复杂度不满足要求. 那么能想到的就是搜索了,实际 ...
- POJ.2454.Jersey Politics(随机化算法)
题目链接 \(Description\) 将长为\(3n\)的序列划分成\(3\)个子序列,要求至少有两个子序列的和都\(\geq 500*n\),输出任一方案.保证有解. \(Solution\) ...
- 【POJ】2454.Jersey Politics
题解 有种迷一样的讽刺效果 每个城市有1000头牛,然后你现在知道对于自己政党每个城市的选票,把城市划分成三个州,保证在至少两个州内获胜 找出前2K大的然后random_shuffle,直到前K个加起 ...
- 浅浅地谈一下随机算法【poj2454】【poj3318】
随机算法我也只是稍微接触了一下,就是想写篇博客自己稍微总结一下 其实随机算法也算是一个玄学吧,运气不好还是会wa.但是我们知道,计算机可以在短时间内计算大量的数据,所以碰到正确答案的概率还是挺大的. ...
随机推荐
- alpha-咸鱼冲刺day5
一,合照 emmmmm.自然还是没有的. 二,项目燃尽图 三,项目进展 !!!QAQ可以做到跟数据库交互了!!!!先来撒花花!(然后继续甲板) 四,问题困难 日常啥都不会,百度真心玩一年. 还得自学n ...
- Beta敏捷冲刺每日报告——Day3
1.情况简述 Beta阶段Scrum Meeting 敏捷开发起止时间 2017.11.4 00:00 -- 2017.11.5 00:00 讨论时间地点 2017.11.4 晚9:30,电话会议会议 ...
- C语言Linix服务器网络爬虫项目(一)项目初衷和网络爬虫概述
一.项目初衷和爬虫概述 1.项目初衷 本人的大学毕设就是linux上用c写的一个爬虫,现在我想把它完善起来,让他像一个企业级别的项目.为了重复发明轮子来学习轮子的原理,我们不使用第三方框架(这里是说的 ...
- php的api及登录的权限验证
类,库,接口(APi),函数,这些概念都是根据问题规模的大小来界定的.一个很小的问题肯定没有必要写成一个库,只需要写几句话就行了. 但是比如一个登录验证,这个功能很强大,很通用,可能前台后台都需要用到 ...
- 版本名称GA的含义:SNAPSHOT->alpha->beta->release->GA
SNAPSHOT->alpha->beta->release->GA ----------------------------------------------------- ...
- Spring Security入门(2-3)Spring Security 的运行原理 4 - 自定义登录方法和页面
参考链接,多谢作者: http://blog.csdn.net/lee353086/article/details/52586916 http元素下的form-login元素是用来定义表单登录信息的. ...
- 实现GridControl的行单元格非顺序跳转
用GridControl控件添加数据的时候发现,有一些字段过多但是并不是每个字段都需要用户输入,每个单元格都回车跳转的时候不仅浪费时间,而且用户体验也不好,就需要单元格跳转的时候,不需要的字段可以隔过 ...
- java将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
首先我们的算法是:例如 输入的是 90 1.找到90的最小公约数(1除外)是 2 2.然后把公约数 2 输出 3.接着用 90 / 2 = 45 (如果这里是素数,就结束,否则继续找最小公约数) 4. ...
- java中数组、list、泛型集合的长度
1 java中的length属性是针对数组说的,比如说你声明了一个数组,想知道这个数组的长度则用到了length这个属性. 2 java中的length()方法是针对字符串String说的,如果想看这 ...
- Pymsql
Pymsql 1.创建数据库连接 pymsql connect conn=pymysql.connect(host="localhost",user="root" ...