
476 - Points in Figures: Rectangles
Moderator: Board moderators
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
i cant find out any bugs. If you can please check it.
WA WA WA...
advanced thanks
WA WA WA...
Code: Select all
#include <stdio.h>
#include <string.h>
struct rect{
long double upp_left_x;
long double upp_left_y;
long double low_right_x;
long double low_right_y;
};
struct fig{
long double x;
long double y;
};
char c;
int main()
{
rect array[100];
int i = 1,k = 1;
int flag,j;
long double x,y;
while(1)
{
scanf("%c",&c);
if(c == '*')
break;
scanf("%Lf %Lf %Lf %Lf",&array[i].upp_left_x,&array[i].upp_left_y,&array[i].low_right_x,&array[i].low_right_y);
i++;
fflush(stdin);
}
while(scanf("%Lf %Lf",&x,&y)==2)
{
if(x == 9999.9 && y == 9999.9)
break;
flag = 1;
for(j = 1;j <= i;j++)
{
if((x > array[j].upp_left_x && x < array[j].low_right_x ) && ( y < array[j].upp_left_y && y > array[j].low_right_y))
{
printf("Point %d is contained in figure %d\n",k,j);
flag = 0;
}
}
if(flag)
printf("Point %d is not contained in any figure\n",k);
k++;
}
return 0;
}
advanced thanks
But now a new problem create,
inputs
outputs
but outputs should be
Beacause They are in Border
inputs
Code: Select all
0.0 0.0
2.5 2.5
12.5 12.5
Code: Select all
Point 1 is contained in figure 2
Point 2 is contained in figure 2
Point 2 is contained in figure 3
Point 3 is contained in figure 1
Point 3 is contained in figure 3
Code: Select all
Point 1 is not contained in any figure
Point 2 is contained in figure 2
Point 3 is contained in figure 1
Last edited by Bad Boy on Sat Aug 18, 2007 2:01 pm, edited 1 time in total.
For double calculations the comparisons should be changed.
a > b should be written a+eps > b. Change all the comparisons. Hope these help.
a > b should be written a+eps > b. Change all the comparisons. Hope these help.
Ami ekhono shopno dekhi...
HomePage
HomePage
476 why my code is WA !?
#include <iostream>
#include <cmath>
#define n 10
using namespace std;
struct rectangle{
double r1,r2,c1,c2;
char r;
};
int main()
{
rectangle a[n];
for(int i=0;i<n;i++)
{
cin>>a.r;
if(a.r == '*')
break;
cin>>a.c1>>a.r1>>a.c2>>a.r2;
}
double row,col;
int t=1;
int judge=0;
while(cin>>col>>row)
{
if( fabs(row-9999.9)< 0.1 && fabs(col-9999.9)<0.1)
break;
judge = 0;
for(int i=0;i<n&&a.r1;i++)
{
if((col > a.c1 && col< a.c2) && (row < a.r1 && row > a[i].r2) )
{
cout<<"Point "<<t<<" is contained in figure "<<i+1<<endl;
judge = 1;
}
}
if(judge == 0)
cout<<"Point "<<t<<" is not contained in any figure"<<endl;
t++;
}
return 0;
}
Can somebody give me some tips or give me some test data?
thanks a lot~
#include <cmath>
#define n 10
using namespace std;
struct rectangle{
double r1,r2,c1,c2;
char r;
};
int main()
{
rectangle a[n];
for(int i=0;i<n;i++)
{
cin>>a.r;
if(a.r == '*')
break;
cin>>a.c1>>a.r1>>a.c2>>a.r2;
}
double row,col;
int t=1;
int judge=0;
while(cin>>col>>row)
{
if( fabs(row-9999.9)< 0.1 && fabs(col-9999.9)<0.1)
break;
judge = 0;
for(int i=0;i<n&&a.r1;i++)
{
if((col > a.c1 && col< a.c2) && (row < a.r1 && row > a[i].r2) )
{
cout<<"Point "<<t<<" is contained in figure "<<i+1<<endl;
judge = 1;
}
}
if(judge == 0)
cout<<"Point "<<t<<" is not contained in any figure"<<endl;
t++;
}
return 0;
}
Can somebody give me some tips or give me some test data?
thanks a lot~
-
- New poster
- Posts: 4
- Joined: Fri Nov 14, 2008 12:41 pm
476 WA Can anyone tell me why?
Code: Select all
#include <stdio.h>
int main()
{
float x[10][2],y[10][2];
int i=0;
char r;
while(i<10)
{
scanf("%c",&r);
if(r=='*')
break;
else if(r=='r')
{
scanf("%f %f %f %f",&x[i][0],&y[i][0],&x[i][1],&y[i][1]);
i++;
}
}
double x1,y1;
int cout=1,judge=0;
int j=0;
while(scanf("%lf %lf",&x1,&y1)==2)
{
if(x1 >= 9999.9 && y1 >= 9999.9)
break;
for(j=0,judge=0;j<i;j++)
{
if(x1>x[j][0] && x1<x[j][1] &&y1>y[j][1] && y1<y[j][0] )
{
printf("Point %d is contained in figure %d\n",cout,(j+1));
judge=1;
}
}
if(judge==0 && x1!=9999.9)
{
printf("Point %d is not contained in any figure\n",cout);
}
cout++;
}
return 0;
}
Re: 476 WA Can anyone tell me why?
You can write like this
For doubles, you should use like this
Don't create new threads on same topic.
Code: Select all
if(judge==0 && x1!=9999.9)
Code: Select all
if (fabs(x1-9999.9)<EPS)
Solving for fun..
Re: 476 still WA
Hi! I am getting WA. Can someone tell me why?
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,flag,c;
double reacA[12][2],reacB[12][2],x,y;
char str[5];
for(i=0,c=0;i<10;i++)
{
scanf("%s",str);
if (strcmp(str,"*")==0) break;
c++;
if(strcmp(str,"r")==0) scanf("%lf %lf %lf %lf",&reacA[i][0],&reacA[i][1],&reacB[i][0],&reacB[i][1]);
}
for(j=0;;j++)
{
scanf("%lf %lf",&x,&y);
if(x==9999.9 && y==9999.9) break;
flag=0;
for(i=0;i<c;i++)
{
if(x>reacA[i][0] && x< reacB[i][0] && y<reacA[i][1] && y>reacB[i][1])
{
printf("Point %d is contained in figure %d\n",j+1,i+1);
flag=1;
}
}
if(flag==0)
printf("Point %d is not contained in any figure\n",j+1);
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 476 still WA
Change line 8 to:
for(i=0,c=0;;i++)
for(i=0,c=0;;i++)
Check input and AC output for thousands of problems on uDebug!
Re: 476 still WA
Its AC. Thanks a lot sir.
. But in the problem it is mentioned that there will be at most 10 inputs for the rectangles. Then why i have to take input for more than 10 rectangles ?
And again thanks sir. The problem was driving me crazy.

And again thanks sir. The problem was driving me crazy.

-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 476 still WA
Try an input with 10 rectangles. You don't need to handle more than that.
Check input and AC output for thousands of problems on uDebug!
476 - Points in Figures: Rectangles WA
Whats wrong with my code, Help............
Code: Select all
#include <stdio.h>
#include <math.h>
int main()
{
double gr[13][6], x, y;
int i, j, k, m, f;
char ch;
i = 0;
while(scanf("%c", &ch) == 1){
if(ch == '*') break;
if(ch == 'r'){
for(j = 0; j < 4; j++){
scanf("%lf", &gr[i][j]);
}
i++;
}
}
m = i;
for(k = 0;; k++){
scanf("%lf %lf", &x, &y);
if(x == 9999.9 && y == 9999.9) break;
f = 0;
for(i = 0; i < m; i++){
if((x >= gr[i][0] && x <= gr[i][2]) && (y >= gr[i][3] && y <= gr[i][1])){
printf("Point %d is contained in figure %d\n", k+1, i+1);
f = 1;
}
}
if(f == 0) printf("Point %d is not contained in any figure\n", k+1);
}
return 0;
}
Re: 476 - Points in Figures: Rectangles WA
Post in existing threads. Don't open new thread. Use search by problem number 476.Points coinciding with a figure border are not considered inside
http://acm.uva.es/board/search.php?keyw ... caf9f1d341
Don't forget to remove your code after getting accepted.

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman