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