## 476 - Points in Figures: Rectangles

Moderator: Board moderators

kallal
New poster
Posts: 4
Joined: Wed Jun 11, 2003 7:11 pm
Contact:

I just can't find why my code is not getting accepted !

Is there any exception in this problem? Hi to all from Kallal !
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Contact:
i don't think there is any `exception' in this problem... i just got it accepted at first try... so you better check your code again.. tell us if you still got problem...
Greetings
Istiaque Ahmed [the LA-Z-BOy]
decken kang
New poster
Posts: 4
Joined: Sat Aug 02, 2003 9:23 am

### WA!476

/* @JUDGE_ID: 476 C++ */
#include<iostream.h>
void main()
{
char s;
int j,k,n_figure=0,n_dot=0;
bool test;
double x,y,figure={0};
while(cin>>s)
{
if(s=='r')
{
n_figure++;
for(j=1;j<3;j++)
for(k=1;k<3;k++) cin>>figure[n_figure][k][j];
}
else if(s=='*')
{
while(cin>>x>>y)
{
if(x==9999.9 && y==9999.9)
goto over;
test=false;
n_dot++;
for(j=1;j<=n_figure;j++)
if(x>figure[j] && x<figure[j] && y<figure[j] && y>figure[j])
{
cout<<"Point "<<n_dot<<" is contained in figure "<<j<<endl;
test=true;
}
if(test==false)
cout<<"Point "<<n_dot<<" is not contained in any figure"<<endl;
}
}
}
over:;
}
/* @END_OF_SOURCE_CODE */

I've test many times.
I think my answer is correct.
But it ayways gets "WA".
I really don't know why.
Anyone could help me.
Thank you very much.
joydip
New poster
Posts: 4
Joined: Tue Sep 23, 2003 2:33 pm

### Easy way

Cheak out the question again, Take four data in 4 double variable,
and put them in 4 arrays then cheak...........
I think you get the max array size Morning
Experienced poster
Posts: 134
Joined: Fri Aug 01, 2003 2:18 pm
Location: Shanghai China

### 476 why compile error?[java]

[java]
import java.io.*;
import java.util.*;

class Main
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}

public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}

void Begin()
{
String input;
StringTokenizer idata;
float x,y;
float [][] matrix=new float ;
int numOfRec=0;
int numOfPoint=0;
int loop;
String temp;
boolean ifBeCon;

while ((input = Main.ReadLn (255)) != null)
{
if(input.charAt(0)=='*') break;
if(input.charAt(0)=='r')
{
numOfRec++;
idata = new StringTokenizer (input);
idata.nextToken();
{
matrix[numOfRec-1] = Float.parseFloat (idata.nextToken());
matrix[numOfRec-1] = Float.parseFloat (idata.nextToken());
matrix[numOfRec-1] = Float.parseFloat (idata.nextToken());
matrix[numOfRec-1] = Float.parseFloat (idata.nextToken());
}
}
}

while ((input = Main.ReadLn (255)) != null)
{
numOfPoint++;
idata = new StringTokenizer (input);
ifBeCon=false;
x=Float.parseFloat (idata.nextToken());
y=Float.parseFloat (idata.nextToken());
if((x==9999.9)&&(y==9999.9)) break;
for(loop=0;loop<numOfRec;loop++)
{
if((x>matrix[loop])&&(x<matrix[loop])&&(y<matrix[loop])&&(y>matrix[loop]))
{
ifBeCon=true;
System.out.println("Point "+numOfPoint+" is contained in figure "+(loop+1));
}
}
if(ifBeCon==false)
System.out.println("Point "+numOfPoint+" is not contained in any figure");

}
}
}[/java][/java]
"Learning without thought is useless；thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

### 476 WA help

it Give's WA i don't no what is wrong.help please.
[pascal]program acm476;
label 1,2;
var a,a1,a2,a3:array[1..10000] of real;
number,i,j,k,n:integer;
c:char;
b,bb:real;
t:boolean;
begin
while not eof do
begin
i:=0;
repeat
i:=i+1;
if c='*' then goto 1;
until 1=2;
1: n:=i;
number:=0;
repeat
number:=number+1;
if (b=9999.9) and (bb=9999.9) then goto 2;
t:=false;
for i:=1 to n do
if (b>=a) and (b<=a2) and (bb<=a1) and (bb>=a3) then begin t:=true;
writeln('Point ',number,' is contained in figure ',i) end;
if t=false then writeln('Point ',number,' is not contained in any figure');
until 1=2;
2:
end;
end.[/pascal]
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

it gives WA help please i really don't know what is wrong
[pascal]program acm476;
label 1,2;
var a:array[1..4,1..100] of real;
x,y:real;
i,j,k,n,number:longint;
c:char;
procedure solve(x,y:real;number:longint);
var i,j,k:longint;
t:boolean;
begin
t:=false;
for i:=1 to n do
begin
if
(x>a[1,i]) and
(x<a[3,i]) and
(y<a[2,i]) and
(y>a[4,i]) then
begin
t:=true;
writeln('Point ',number,' is contained in figure ',i);
end;
end;
if t=false then writeln('Point ',number,' is not contained in any figure');
end;
begin
i:=0;
repeat
if c='*' then goto 1;
if c='r' then
begin
i:=i+1;
for j:=1 to 4 do
end;
until 1=2;
1: n:=i;
number:=0;
repeat
number:=number+1;
if (x=9999.9) and (y=9999.9) then goto 2;
solve(x,y,number);
until 1=2;
2:
end.[/pascal]
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

int rectangle(double x,double y)
{
if(x>=a1 && x<=a3 && y>=a4 && y<=a2)
{
i++;
return 1;
}
else {i++; return 0; }
}

this is my function i have use this function in 477 & got AC
but in problem 476 i got WA what is my funtions problem any body can
help me??

prince
23-12-2003
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
Please specify what does a1 contain.

Why are u using the variable i when you have never initialized it.
Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore
Hi mohiul,
You do not have to create an array and fill it up to create a rectangle.. This problem is easy. keep an array like you are keeping and when a pt is given just compare if the point lies in bound..
Eg. l=left r=right t=top b=bottom x,y is the point

if(x>l && x<r && y>b && y<t) cout<<"In figure";

if it fails for all figures then it obviously does not lie in any figure....

Aakash ...I was born to code...
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore
Your idea seems right but am no good with pascal..
if t=top l=left r=right b=botom and x,y is the point

if(x>l && x<r && y<t && y>b) then pt in figure

if it fails for all figures then point not in any figure.

Aakash ...I was born to code...
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)
thanks akash i got AC.
Salmin Sultana
New poster
Posts: 16
Joined: Sun Mar 07, 2004 12:19 pm
Location: Dhaka

why this is wa?my code is here
#include<stdio.h>

class rect
{
public:
long double left,right,top,bottom;
}a;

int main()
{
char ch;
long double p1x,p1y,p2x,p2y,temp;
long int num=0,i,p=1,flag;

while(1){

scanf("%c",&ch);
if(ch=='*')
break;

scanf("%Lf %Lf %Lf %Lf",&p1x,&p1y,&p2x,&p2y);
fflush(stdin);

if(p1x>p2x){
temp=p1x;
p1x=p2x;
p2x=temp;
}
if(p1y<p2y){
temp=p1y;
p1y=p2y;
p2y=temp;
}
a[num].left=p1x;
a[num].right=p2x;
a[num].top=p1y;
a[num].bottom=p2y;
num++;
}
for(p=1;;p++){

scanf("%Lf %Lf",&p1x,&p1y);
p2x=p1x-0.9;
p2y=p1y-0.9;
if(p2x==9999&&p2y==9999)
break;

flag=0;
for(i=0;i<num;i++){
if((p1x>(a.left))&&(p1x<(a.right))&&
(p1y>(a.bottom))&&(p1y<(a.top)))
{
flag=1;
printf("Point %ld is contained in figure %ld\n",p,i+1);
}
}
if(flag==0)
printf("Point %ld is not contained in any figure\n",p);
}
return 0;
}[/cpp][/code]
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### minor mistake!

your program is perfectly alright but your input taking format is not quite correct.

try avoid scanf("%c",&ch) ,
use scanf("%s",str) and then str ==.

I have changed this part of your code and removed fflush(stdin) and got Ac.

Hope it helps.