476 - Points in Figures: Rectangles

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

Moderator: Board moderators

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Sat Mar 10, 2007 6:22 pm

If you got AC, remove you code plz.. :-)

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton » Tue Aug 07, 2007 6:21 am

i cant find out any bugs. If you can please check it.
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

Bad Boy
New poster
Posts: 4
Joined: Fri Jul 13, 2007 5:17 am
Location: CSE, DU(13th)

Post by Bad Boy » Thu Aug 16, 2007 7:31 pm

But now a new problem create,
inputs

Code: Select all

0.0 0.0
2.5 2.5
12.5 12.5
outputs

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
but outputs should be

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
Beacause They are in Border
Last edited by Bad Boy on Sat Aug 18, 2007 2:01 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Fri Aug 17, 2007 10:14 am

For double calculations the comparisons should be changed.

a > b should be written a+eps > b. Change all the comparisons. Hope these help.
Ami ekhono shopno dekhi...
HomePage

adam0806
New poster
Posts: 1
Joined: Thu Feb 15, 2007 3:23 pm

476 why my code is WA !?

Post by adam0806 » Sat Feb 02, 2008 3:57 pm

#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~

peterwen1990
New poster
Posts: 4
Joined: Fri Nov 14, 2008 12:41 pm

476 WA Can anyone tell me why?

Post by peterwen1990 » Sat Nov 22, 2008 7:03 am

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;
}

User avatar
linux
Learning poster
Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm
Location: CA-95054
Contact:

Re: 476 WA Can anyone tell me why?

Post by linux » Wed Jan 07, 2009 4:37 pm

You can write like this

Code: Select all

if(judge==0 && x1!=9999.9)
For doubles, you should use like this

Code: Select all

if (fabs(x1-9999.9)<EPS)
Don't create new threads on same topic.
Solving for fun..

Ovro
New poster
Posts: 12
Joined: Mon Nov 11, 2013 8:30 am

Re: 476 still WA

Post by Ovro » Thu Nov 21, 2013 8:42 am

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 476 still WA

Post by brianfry713 » Thu Nov 21, 2013 9:29 pm

Change line 8 to:
for(i=0,c=0;;i++)
Check input and AC output for thousands of problems on uDebug!

Ovro
New poster
Posts: 12
Joined: Mon Nov 11, 2013 8:30 am

Re: 476 still WA

Post by Ovro » Fri Nov 22, 2013 7:17 am

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. :D

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 476 still WA

Post by brianfry713 » Fri Nov 22, 2013 9:37 pm

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!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

476 - Points in Figures: Rectangles WA

Post by NAbdulla » Mon Aug 18, 2014 9:34 pm

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;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 476 - Points in Figures: Rectangles WA

Post by lighted » Wed Aug 20, 2014 5:15 pm

Points coinciding with a figure border are not considered inside
Post in existing threads. Don't open new thread. Use search by problem number 476.
http://acm.uva.es/board/search.php?keyw ... caf9f1d341

Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 4 (400-499)”