Hdu2535: Vote

Source: Internet
Author: User
Problem description the U.S. election determines the final result based on the voting results of each State. If more than half of the States support the final result, they can be elected, the voting results in each State are produced by the state's voters. If more than half of the state's voters support Hillary Clinton, she will win the State's support. The number of voters in each State is provided. How many voters does Hillary need to win at least to be elected?

Multiple Input groups
The first row of each group of data contains an integer N (1 <= n <= 101), indicating the number of states in the United States, and n = 0 indicates that the input ends.
The next line contains n positive integers, indicating the number of voters in each state. The number of voters in each State cannot exceed 100.

Output outputs a line for each group of data, indicating that Hillary needs to win at least the number of voters

Sample Input

 
35 7 50

Sample output

 
6

 

 

# Include <iostream> using namespace STD; int main () {int N; while (CIN> N & N) {int I, j, sum = 0, T, k, a [105] = {0}; for (I = 1; I <= N; I ++) {CIN> A [I];} for (I = 1; I <n; I ++) // sort the array from small to large by the selection method {k = I; for (j = I; j <= N; j ++) {if (a [k]> A [J]) k = J;} t = A [k]; A [k] = A [I]; A [I] = T;} for (I = 1; I <= n/2 + 1; I ++) // calculate the minimum number of first few tickets, that is, sum = A [I]/2 + 1 + sum; cout <sum <Endl;} return 0 ;}

 

Related Article

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.