Code: Select all
Cut after AC.....
Moderator: Board moderators
Code: Select all
Cut after AC.....
Code: Select all
1
2
0 0 1 1
1 1 0 0
Code: Select all
Case 1: 0
Are you sure? I think the answer is 1 not 0. because two rectangles are the same.rio wrote:Try this.
INPUT:OUTPUT:Code: Select all
1 2 0 0 1 1 1 1 0 0
ADD : If you meet these kind of problems, try everything. Finding the trick is also the part of the problem.Code: Select all
Case 1: 0
----
Rio
Thanks sclo for your quick reply. Your method is much better than mine and it works correctly but I don't know why my method is wrong. My algorithms is:sclo wrote:All I did was to find the maximum x1, minimum x2, maximum y1 and minimum y2 over all input.saman_saadi wrote:Is there any tricky IO?
As a side effect, if x2<=x1 or y2<=y1 in any rectangle, the answer is 0
I think I handle all of these:sclo wrote:what happens when r.x1>r.x2 or r.y1>r.y2 in your algorithm?
Obviously, something is wrong with your logic somewhere. But I don't really see it.saman_saadi wrote:I think I handle all of these:sclo wrote:what happens when r.x1>r.x2 or r.y1>r.y2 in your algorithm?
1) r.x1 > r.x2 => r2.x1 > min(r1.x2, r2.x2)
we know r2.x1 < r2.x2 so we must have r1.x2 < r2.x1 that I handle this.
2) r.y1 > r.y2 => max(r1.y1, r2.y1) > min(r1.y2, r2.y2)
suppose that min(r1.y2, r2.y2) = r1.y2:
r1.y2 < max(r1.y1, r2.y1) => r1.y2 < r2.y1 that I handle this
now suppose min(r1.y2, r2.y2) = r2.y2:
r2.y2 < max(r1.y1, r2.y1) => r2.y2 < r1.y1 that I handle this.
So I handle all cases that you consider.
Code: Select all
code removed
Updated code (got WA)How did you fixed your code ?
Update your code, or erase it and post a new one.
Code: Select all
#include <stdio.h>
struct ractangle
{
int x1, y1, x2, y2 ;
} ;
int main ()
{
//freopen( "11345.in", "r", stdin ) ;
int T, kase, i, N, area ;
ractangle r[50], t ;
scanf( "%d", &T ) ;
kase = 1 ;
while( T-- )
{
scanf( "%d", &N ) ;
for( i = 1; i<= N; i++ )
{
scanf( "%d%d%d%d", &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2 ) ;
if( r[i].x1 >= r[i].x2 || r[i].y1 >= r[i].y2 )
{
area = 0 ; goto end ;
}
}
t = r[1] ;
for( i = 2; i <= N; i++ )
{
/*if( r[i].x2 <= t.x1 || t.x2 <= r[i].x1 || r[i].y2 <= t.y1 || t.y2 <= r[i].y1 )
{
area = 0 ; break ;
}*/
t.x1 = r[i].x1 > t.x1 ? r[i].x1 : t.x1 ;
t.x2 = r[i].x2 < t.x2 ? r[i].x2 : t.x2 ;
t.y1 = r[i].y1 > t.y1 ? r[i].y1 : t.y1 ;
t.y2 = r[i].y2 < t.y2 ? r[i].y2 : t.y2 ;
if( t.x2 >= t.x1 && t.y2 >= t.x1 )
area = ( t.x2 - t.x1 ) * ( t.y2 - t.y1 ) ;
else { area = 0 ; break ; }
}
end : ;
printf( "Case %d: %d\n", kase++, area ) ;
}
return 0 ;
}