815 - Flooded!

All about problems in Volume 8. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

815 - Flooded!

Post by jpfarias »

Hi, anyone knows any trick input? i think my solution is ok but I'm getting WA!!!



Any help will be thankful received!!



Thanks,



Jo
Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post by Ivor »

You do know that this problem has 0% acceptance rate. :roll:
Couldn't resist reminding. 8)

Ivor
afernandez
New poster
Posts: 1
Joined: Tue Aug 13, 2002 9:11 pm

same here!

Post by afernandez »

I have the same problem: it keeps replying WA. The problem is very simple and my program works fine with all special cases I tested.

I have the feeling that either there is a bad testcase or there is some particularity that has not been properly described in the problem statement.

:(
mmikla10
New poster
Posts: 1
Joined: Thu Aug 15, 2002 1:01 pm

Post by mmikla10 »

A few special cases I'm not sure about:
- What's the water level if there is no rain at all? (The same as the lowest point?)
- Is the landscape completly enclosed: may water level exceed the highest point in the region?
- Are the regions under the sea level already "flooded" by the sea even before any rain falls? (Although I don't believe so.)

Bye, Mojca
Carlos
System administrator
Posts: 1286
Joined: Sat Oct 13, 2001 2:00 am
Location: Valladolid, Spain
Contact:

Judge's answer

Post by Carlos »

> A few special cases I'm not sure about:
> - What's the water level if there is no rain at all? (The same as the lowest point?)

There is not such case on th input.

> - Is the landscape completly enclosed: may water level exceed the highest point in the region?

Of course it can, if there's a lot of water every point will be underwater.

> - Are the regions under the sea level already "flooded" by the sea even before any rain falls? (Although I don't believe so.)

No, they are not. There isn't sea on this land.


One hint, in some test cases, the exact answer may be:
1.235
you should print 1.24 instead of 1.23.

If you keep getting WA, mail us: problemset@acm.uva.es and send us your source code.

Ciao!!

Carlos.
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

marceh wrote:One hint, in some test cases, the exact answer may be:
1.235
you should print 1.24 instead of 1.23.
And if exact answer is -1.235 what we're need to output, -1.24 or -1.23?
...May be this problem needs correction program?

Also there is something wrong with limits -- problem's description states
Each begins with a pair of integers, m and n, each less than 30...
but this code gets assertion failed:

Code: Select all

 while (scanf("%d %d\n", &r, &c) == 2) {
   if (r == 0 && c == 0) break;
   assert(r >= 1 && r < 30);
   assert(c >= 1 && c < 30);
  ...
Changing this into

Code: Select all

   assert(r >= 1 && r < 60);
   assert(c >= 1 && c < 60);
gives me WA instead of RTE.
Santiago Zanella
New poster
Posts: 10
Joined: Tue Oct 01, 2002 11:37 pm

Post by Santiago Zanella »

Posts can't be deleted but edited? uh
Last edited by Santiago Zanella on Thu Oct 10, 2002 2:10 am, edited 1 time in total.
Santiago Zanella
New poster
Posts: 10
Joined: Tue Oct 01, 2002 11:37 pm

Help checking solution

Post by Santiago Zanella »

I wonder if someone that have already solved this problem could help me.
There must be some tricky input or something wrong with my solution.
Any help is welcome.

[c]
#include <stdio.h>
#include <search.h>
#include <math.h>

/* Although the statement says that m and n will be less than 30, they can actually reach 30 */
int i, j, m, n, w, r, A[901]; /* A[30*30+1] */

int compare(const void *, const void *);

void solve();

void main()
{
for(r=1;;r++) {
/* Get region dimensions */
scanf("%d %d", &m, &n);

/* Check for end of input */
if(m==0 && n==0) break;

/* Follow the output of each input with a blank line */
if(r>1) printf("\n");

/* Get elevations */
for(i=0; i<m*n; i++)
scanf("%d", &A);

/* Get water that collects in the region */
scanf("%d", &w);

/* Output answer */
solve();
}
}

int compare( const void *arg1, const void *arg2 )
{
return (*(int *)arg1 - *(int *)arg2);
}

void solve()
{
double h, t;
/* First sort the elevations in ascendant order */
qsort(A, m*n, sizeof(A[0]), compare);
/* Sentinel */
A[m*n] = 2147483647;

/* Then incrementally flood the squares until all water is distributed */
/* h = temporary water level */
/* t = water already distributed */
t = 0;
for(i=0; i<m*n; i++) {
for(j=i+1; A[j]<=A && j<=m*n; j++);
t += fabs(A[j]-A)*j*100.0;
if(t>=w) {
t -= fabs(A[j]-A)*j*100.0;
h = A+(w-t)/(j*100.0);
goto flooded;
}
}

flooded:
printf("Region %d\n", r);
printf("Water level is %.2f meters.\n", h);
printf("%.2f percent of the region is under water.\n", (j*100.0)/(m*n));
}
[/c]

:roll: What's wrong?
User avatar
cytse
Learning poster
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong
Contact:

Post by cytse »

I have tested your program with my testdata. Your program fails at this case:
2 2
1 1
1 2
301
0 0
Santiago Zanella
New poster
Posts: 10
Joined: Tue Oct 01, 2002 11:37 pm

Post by Santiago Zanella »

Thank you cytse!
There was a little big error that wasn't shown in my test cases.
ashutoshkorde
New poster
Posts: 6
Joined: Mon May 05, 2003 1:48 pm

Post by ashutoshkorde »

there has to be a special input case cos my program is working for all the inputs i can possiblly think of. just need that one special case ....
what if the water level equals the elevation of a region for e.g.
2 2
1 0
0 1
200
0 0

should this print area covered as 50% or 100% ???
bobi1978
New poster
Posts: 13
Joined: Tue Jul 22, 2003 1:57 pm
Location: Kavadarci, Macedonia
Contact:

Post by bobi1978 »

Here is the output for this case:

INPUT:
2 2
1 0
0 1
200

OUTPUT:
Region 1
Water level is 1.00 meters.
50.00 percent of the region is under water.
snick
New poster
Posts: 2
Joined: Sat Sep 27, 2003 5:30 am
Contact:

any special case?

Post by snick »

I got this output for this test case.
could anyone give some test cases for negative inputs??
is there any special cases?
thank you!~!

2 2
1 1
1 2
301
Region 1
Water level is 2.00 meters.
100.00 percent of the region is under water.

[/cpp]
snick
New poster
Posts: 2
Joined: Sat Sep 27, 2003 5:30 am
Contact:

Post by snick »

:evil:
I got WA still
anyone have special test cases for this question?
especially negative values
thank you!
Gazi Shaheen Hossain
New poster
Posts: 7
Joined: Fri Sep 03, 2004 6:47 pm

815 compile error

Post by Gazi Shaheen Hossain »

Can anyone help me?
the code given below (for 815 in c++) gives me compile error
[cpp]
#include <stdio.h>

void main()
{

int m,n,squr;
unsigned long i,j,region=1;

char flag=0;
double sqr[900],water,dif,under,count,lebel;

while(1)
{
scanf("%d %d",&m,&n);
if(m==0&&n==0)break;
if(flag)printf("\n");
flag=1;
squr=m*n;
for(i=0;i<squr;i++)
scanf("%lf",&sqr);
scanf("%lf",&water);
water/=100;

for(i=0;i<squr-1;i++)
for(j=i+1;j<squr;j++)
{
if(sqr>sqr[j])
{
dif=sqr;
sqr=sqr[j];
sqr[j]=dif;
}
}
printf("Region %lu\n",region++);
count=1;under=0;
for(i=1;i<squr;i++)
{
dif=sqr - sqr[i-1];
if((under + dif*count)<water )
under=under+dif*count;
else break;
count++;
}
lebel=sqr[count-1]+(water-under)/count;
printf("Water level is %.2lf meters.\n",lebel);
printf("%.2lf percent of the region is under water.\n",(count/squr*100));
}
}[/cpp]
Post Reply

Return to “Volume 8 (800-899)”