Hdoj (HDU) 2304 electrical Outlets (sum,,)

Source: Internet
Author: User

Problem Description
Roy had just moved into a new apartment. Well, actually the apartment itself isn't very new, even dating back to the days before people had electricity in their h Ouses. Because of this, Roy's apartment have only one single wall outlet, so Roy can only power one of his electrical appliances a T a time.
Roy likes to watch TV as he works on his computer, and to listen to his HiFi system (on high volume) while he vacuums, so Using just the single outlet was not a option. Actually, he wants to has all his appliances connected to a powered outlet, all the time. The answer, of course, is power strips, and Roy have some old ones that he used in his old apartment. However, that's apartment had many more wall outlets, so he's not sure whether he power strips would provide him with Enoug H outlets now.
Your task is to help Roy compute how many appliances he can provide with electricity, given a set of power strips. Note that without any power strips, Roy can power one single appliance through the wall outlet. Also, remember that a power strip have to is powered itself to is of any use.

Input
Input would start with a single integer 1 <= N <=, indicating the number of the test cases to follow. Then follow N lines, each describing a test case. Each test case is starts with a integer 1 <= K <=, indicating the number of the power strips in the test case. Then follow, on the same line, K-integers separated by single spaces, O1 O2 ... OK, where 2 <= Oi <=, indicating the number of outlets in each power strip.

Output
Output one line per test case, with the maximum number of appliances that can is powered.

Sample Input
3
3 2 3 4
10 4 4 4 4 4 4 4 4 4 4
4 10 10) 10 10

Sample Output
7
31
37

This is about the problem of drainage, is to give you M row, each row has x hole, the first only one wall can plug in a row, ask how many electrical appliances, an electrical appliance to occupy a hole.

That is to put these rows to string up, string up the row plug also need to occupy a hole, and then because the last row plug not to be inserted into a hole, so do not lose one,
So the answer is: M-row hole all add up, and then subtract (m-1);

Import Java.util.Scanner; Public classmain{ Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch);intT =sc.nextint (); while(t-->0){intn =sc.nextint ();intsum=0;intA for(intI=0; i<n;i++) {a=sc.nextint ();            Sum+=a; } sum=sum-n+1; System. out. println (sum); }    }}

Hdoj (HDU) 2304 electrical Outlets (sum,,)

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.