poj 2370 Democracy in danger
来源:互联网 发布:软件购销合同书范本 编辑:程序博客网 时间:2024/05/18 23:12
题目链接:http://poj.org/problem?id=2370View Code
题意:大意好像是类似选举,给出K,表示一共K组,然后给出K组人每组的人数,都是奇数。每组人有超过一半的人同意就认为那一组人同意,有超过半数的组同意就决定通过,看最少要多少人同意能决定通过。
分析:贪心。(水)将每组人数按照从小到大排序,选择前面(k)/2+1组人每组a[i]/2+1的人同意就好。
代码:
#include<cstdio>#include<cmath>#include<cstring>#include<queue>#include<stack>#include<cstdlib>#include<string>#include<vector>#include<map>#include<string>#include<iostream>#include<algorithm>using namespace std;#define INF 0x3f3f3f3ftypedef long long ll;#define Max(a,b) (a>b)?a:b#define lowbit(x) x&(-x)int main(){ int n; scanf("%d",&n); int a[100005]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } int sum=0; sort(a,a+n); for(int i=0;i<n/2+1;i++) { sum+=a[i]/2+1; } printf("%d\n",sum);}
0 0
- POJ 2370 Democracy in danger
- POJ 2370 Democracy in Danger
- poj 2370 Democracy in danger
- Overcome ACM POJ 2370 - Democracy in danger
- poj2370 Democracy in danger!
- 1025. Democracy in Danger
- URAL 1025. Democracy in danger
- ural 1025 Democracy in Danger
- 11 URAL1025 Democracy in Danger
- Ural-1025. Democracy in Danger(水题)
- Timus 1025. Democracy in Danger 题解
- URAL 1025 — Democracy in Danger
- URAL 1025. Democracy in Danger (贪心)
- Ural 1025 Democracy in Danger 解题报告
- URAL 1025 Democracy in Danger 贪心
- (贪心5.2.7)URAL 1025 Democracy in Danger
- POJ 1781 In Danger
- poj 1781 In Danger
- poj 2366 Sacrament of the sum
- poj 2367 Genealogical tree
- Apple Mach-O Linker (ld) Error Group
- poj 2368 Buttons
- poj 2369 Permutations
- poj 2370 Democracy in danger
- jmeter通过jmeter-plugins、jconsole对系统资源进行监控
- poj 2371 Questions and answers
- poj 2372 D++ Again
- HDU 5857 Median (2016 多校训#10 1001)
- HDU 5858 Hard problem (2016 多校训练#10 1002)
- HDU 5867 Water problem (2016 多校训练#10 1011)
- CodeForces 13A Numbers
- CodeForces 14A Letter