CCF Test (Java)-the largest rectangular __java

Source: Internet
Author: User
Tags first row

CCF Test (Java)-the largest rectangle

Questions:

Question number: 201312-3
Question Name: The largest rectangle
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: The problem description puts n adjacent rectangles on the horizontal axis, the width of each rectangle is 1, and the height of the first (1≤i≤n) rectangle is H i. These n rectangles form a histogram. For example, the height of the six rectangles in the following figure is 3, 1, 6, 5, 2, 3.



Find the largest rectangle that can be placed in a given histogram, with its edges parallel to the axis. For the example given above, the largest rectangle is the shaded part shown in the following figure, with an area of 10.
Input format the first row contains an integer n, the number of rectangles (1≤n≤1000).
The second row contains n integers h 1, H 2, ..., h N, and the adjacent numbers are separated by spaces. (1≤h i≤10000). H i is the height of the first rectangle. The output format outputs a row that contains an integer, which is the area of the largest rectangle within the given histogram. Sample Input 6
3 1 6 5 2 3 Example output 10

Answer:

import java.util.*;
		public class Main {public static void main (string[] args) {Scanner input = new Scanner (system.in);
		String str[] = new STRING[2];
		int e = 0;
		while (E<2) {str[e++] = Input.nextline ();
		int n = integer.parseint (str[0]);
		string[] numbers = Str[1].split ("");
		int[] Nums = new Int[numbers.length];
		for (int i = 0; i < nums.length i++) {Nums[i] = Integer.parseint (numbers[i));
		int result = 0,temp = 0;
		Boolean entry = true;
			for (int i = 0; i < nums.length i++) {int l=0,r=0;
				for (int p=i-1;p>=0;p--) {if (Nums[i]<nums[p]) {l++;
				}else{break;
				} for (int q=i+1;q<nums.length;q++) {if (Nums[i]<nums[q]) {r++;
				}else{break;
				} if (entry) {temp = result = nums[i]* (l+r+1);
			Entry = false;
				}else{temp = nums[i]* (l+r+1);
				if (temp > result) {result = temp;
	}} System.out.println (Result); }
}

Results (don't know why only 90 points):


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.