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

User avatar
kallal
New poster
Posts: 4
Joined: Wed Jun 11, 2003 7:11 pm
Location: Bangladesh
Contact:

Re: About 476

Post by kallal »

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

Is there any exception in this problem? :roll:
Hi to all from Kallal !

the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

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

Post by decken kang »

/* @JUDGE_ID: 476 C++ */
#include<iostream.h>
void main()
{
char s[2];
int j,k,n_figure=0,n_dot=0;
bool test;
double x,y,figure[10000][3][3]={0};
while(cin>>s)
{
if(s[0]=='r')
{
n_figure++;
for(j=1;j<3;j++)
for(k=1;k<3;k++) cin>>figure[n_figure][k][j];
}
else if(s[0]=='*')
{
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][1][1] && x<figure[j][1][2] && y<figure[j][2][1] && y>figure[j][2][2])
{
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

Post by joydip »

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]

Post by Morning »

[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)
{
car = System.in.read();
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 [10][4];
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][0] = Float.parseFloat (idata.nextToken());
matrix[numOfRec-1][1] = Float.parseFloat (idata.nextToken());
matrix[numOfRec-1][2] = Float.parseFloat (idata.nextToken());
matrix[numOfRec-1][3] = 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][0])&&(x<matrix[loop][2])&&(y<matrix[loop][1])&&(y>matrix[loop][3]))
{
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

Post by Eduard »

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
read(c);
i:=i+1;
if c='*' then goto 1;
readln(a,a1,a2,a3)
until 1=2;
1: n:=i;
number:=0;
repeat
number:=number+1;
read(b);
readln(bb);
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

about 476

Post by Eduard »

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
read(c);
if c='*' then goto 1;
if c='r' then
begin
i:=i+1;
for j:=1 to 4 do
read(a[j,i]);
end;
until 1=2;
1: n:=i;
number:=0;
repeat
number:=number+1;
readln(x,y);
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)

about help 476

Post by mohiul alam prince »

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

Post by shamim »

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

Post by Eduard »

Help please.
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

Post by aakash_mandhar »

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

I hope it answers any doubts you have about the problem...

Aakash :D
...I was born to code...

aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

Post by aakash_mandhar »

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 :D
...I was born to code...

mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince »

thanks akash i got AC.

Salmin Sultana
New poster
Posts: 16
Joined: Sun Mar 07, 2004 12:19 pm
Location: Dhaka

help about 476

Post by Salmin Sultana »

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

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

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!

Post by sohel »

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[0] ==.

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

Hope it helps.

Post Reply

Return to “Volume 4 (400-499)”