POJ 2370 Democracy in danger

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=2370

Test instructions: The effect seems to be similar to the election, given K, the total K group, and then give the K group of people per group, are odd. More than half of each group agreed that the Group agreed that more than half of the groups agreed on the decision to pass, and at least how many people agreed to decide to pass.

Analysis: Greed. (water) in each group according to the order from small to large, select the front (k)/2+1 Group of people each group of a[i]/2+1 agree on the good.

Code:

#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 namespacestd;#defineINF 0x3f3f3f3ftypedefLong Longll;#defineMax (A, B) (a>b)? a:b#defineLowbit (x) x& (-X)intMain () {intN; scanf ("%d",&N); inta[100005];  for(intI=0; i<n;i++) {scanf ("%d",&A[i]); }    intsum=0; Sort (A,a+N);  for(intI=0; i<n/2+1; i++) {sum+=a[i]/2+1; } printf ("%d\n", sum);}
View Code

POJ 2370 Democracy in danger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.