poj 2370 Democracy in danger

题目链接:http://poj.org/problem?id=2370

题意:大意好像是类似选举,给出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 0x3f3f3f3f
typedef 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);
}

时间: 2024-10-27 00:40:09

poj 2370 Democracy in danger的相关文章

POJ 2370 Democracy in danger(简单贪心)

Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 2508 Description In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citize

POJ2370 Democracy in danger

题目超级水,但题目意思不好理解(英语太差...),排个序,然后答案就出来了. Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3136   Accepted: 2311 Description In one of the countries of Caribbean basin all decisions were accepted by the simple majority of

URAL 1025. Democracy in Danger (贪心)

1025. Democracy in Danger Time limit: 1.0 second Memory limit: 64 MB Background In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citizens (fortunately, there were no lots

11 URAL1025 Democracy in Danger

选择人数较少的m/2只队,每只队中半数人投票. #include<cstdio> #include<algorithm> using namespace std; int main() { int i,n,ans,s[110]; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d",&s[i]); sort(s,s+n); ans=0; for(i=0;i<=n/

URAL 1025 Democracy in Danger

排个序 1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class P1025 5 { 6 public static void main(String args[]) 7 { 8 try (Scanner cin = new Scanner(System.in)) 9 { 10 while (cin.hasNext()) 11 { 12 int n = cin.nextInt(); 13 int a[] = n

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

poj题库分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目(转)

http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (