HDU 2042 not Easy series of two (Java)

Source: Internet
Author: User

Problem:

Recursion.


Not easy series of twoTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 19451 Accepted Submission (s): 15659


Problem description You live not easy, I live not easy, he is not easy to live. However, if you read the following story, you will know that there is an old man than you are not easy.

Chongqing suburb Yellow Mud Board village Xu Old man (large Xudonghai, abbreviation XDH) These two years hard to raise a lot of sheep, to this summer, because the well-known high temperature and drought, there is no way to solve the problem of livestock drinking water, decided to bring these sheep to market to sell. From the yellow mud plate village to the trading place to go through the N toll station, ordinarily this toll station and Xu Old no relationship, but the fact that Xu old man to cry no Tears:

(Lens playback)

Close-up: Old man, flock of sheep
Vision: Highways, toll stations

......

Fee-paying staff (polite + professional Smile): "Old comrade, please pay the tolls!" ”

Xu Old man (stunned, unresponsive): "Pot, pot, pot, pot--stove--fee?" My house does not burn the boiler? ”

Toll Clerk (Professional smile still): "Old comrade, I said is over-road-fee, is your sheep to cross this intersection must pay, understand?"

Old man Xu (near the lens 10 seconds, mouth open): "I-i-I know the car tolls, this sheep also charge ah?" ”

Toll Clerk (condescending + puzzled): "Old comrade, how do you not understand it, then I ask you, car several wheels?" ”

Xu Old man (slightly relaxed): "This I know, today at home my grandson also asked me this question, 4!" ”

Toll-Teller (angry, standing up): "Hey! Old man, you also curse without dirty word, since know car four wheels, don't know this sheep have several legs?! ”

Xu Old man (embarrassed, still puzzled like): "Also, also, is also 4 ah, it has relations?" ”

Toll-Teller (angry, standing up): "How does it matter!" Our head said, as long as the 4 legs are charged! ”

......

(external tone)

As Xu Old man has no money, the charge will be his sheep take half, see the old tears ripple, hesitated, and back to the old one. Coincidentally, every time after a toll station, is to take half of the sheep, and then return one, until the old man arrived at the market, there are only 3 sheep left.

You, the contemporary conscience of youth, can help calculate the old man how many sheep originally?

Input data The first line is an integer n, which consists of n rows, each containing an integer a (0<a<=30), indicating the number of toll stations.

Output for each test instance, print the number of the original sheep, one row for each test instance output.

Sample Input
212

Code:

Import java.util.*;p ublic class main{public static void Main (string[] args) {Scanner cin=new Scanner (system.in); int n=cin . Nextint (); for (int i=0;i<n;i++) {int m=cin.nextint (); int[] a=new int[31];for (int j=1;j<=m;j++) {a[0]=3;a[j]= (a[ J-1]-1) * *;} System.out.println (A[m]);}}


Hdu 2042 not Easy Series II (Java)

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.