Exercise 4-10 Flood Uva815__noip

Source: Internet
Author: User
Algorithm Contest Introduction Classic (2nd edition) Chapter 4th function and recursion

Exercise 4-10 Flood UVa815

Sentiment.

1, download the original English topic from the website, focusing on the input and output data and format.

2, repeated in English and Chinese, Leng did not understand the sample water level is 46.67 meters.

3, no understanding, programming can not start.

4, search or search http://blog.csdn.net/code4101/article/details/38540759, see this map, immediately understand that the subject will soon be able to understand, in the final analysis, or the English level of the point. However, there is no next picture, read English repeatedly, still can not read.


5, Start coding. There is a question that the water level is exactly the same as the area, which is not submerged. No, the problem mentioned under water.

6, many times to submit WA, the border for many changes, no water, water will be the entire grid submerged, but WA.

7, from the http://blog.csdn.net/code4101/article/details/38540759 copy code, to Pat, only to find, is the output format problem, this problem is different from the past, the past is an example of a blank line, the topic is each example after the empty line, Follow
The output for each region with a blank line. Modify, submit AC.

8, the subject of water for 0 should not be processed, I have been tested. Look at the time 2016-11-13 21:50

9, the subject is easy to jam there are two places, one is the water is partially submerged or submerged grid, otherwise WA, the second is each example to follow a blank line, otherwise WA. 2nd, not through the PAT, is not to be found out.

10, very happy, the fourth chapter of the end, that is why I do a more urgent reason, to the fifth chapter really good, and so long.

Attach the AC code, compile the Environment dev-c++4.9.9.2

#include <stdio.h>

const int MAXN=40;
int ELEVATION[MAXN*MAXN];
int CUBIC[MAXN*MAXN];
int main () {
int row,col;
int i,j;
int water;
float level;
int count;
int tmp;
int elevationsum;
int Kase;
float percent;
kase=0;
while (scanf ("%d%d", &row,&col) &&row&&col) {
count=0;
for (i=0;i<row;i++) {
for (j=0;j<col;j++) {
scanf ("%d", &elevation[count]);/area elevation
count++;
}
}
scanf ("%d", &water);//Water quantity

for (i=0;i<count;i++) {//bubble sort, area altitude from childhood to large
for (j=i+1;j<count;j++) {
if (Elevation[i]>elevation[j]) {
Tmp=elevation[i];
ELEVATION[I]=ELEVATION[J];
elevation[j]=tmp;
}
}
}

The total amount of water that drowns a region
for (i=0;i<count-1;i++) {
CUBIC[I]=10*10* ((Elevation[i+1]-elevation[i]) * (i+1));
}
cubic[i]=0;

for (i=1;i<count;i++) {
CUBIC[I]+=CUBIC[I-1];
}

Find areas where water is flooded
for (i=0;i<count;i++) {
if (Water<=cubic[i]) {
Break
}
}

if (i==count) {//water will overwhelm the grid
elevationsum=0;
for (j=0;j<count;j++) {
ELEVATIONSUM+=ELEVATION[J];
}
Level= (water*1.0/100+elevationsum)/count;
percent=100.00;
}else{//water does not overwhelm the grid
elevationsum=0;
for (j=0;j<=i;j++) {
ELEVATIONSUM+=ELEVATION[J];
}
Level= (water*1.0/100+elevationsum)/(i+1);
Percent= (i+1) *1.0/count*100;
}

if (kase>0)//If add these two lines, immediately WA 2016-11-13 21:48
printf ("\ n");
kase++;

printf ("Region%d\n", Kase);
printf ("Water level are%.2f meters.\n", level);
printf ("%.2f percent of the region is under water.\n", percent);
printf ("\ n");
}
return 0;
}

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.