## 10242 - Fourth Point !!

Moderator: Board moderators

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

### 10242 - Fourth Point !!

I don't know what's wrong with tihs code. I'm trying to get better at C, so any help would be appreciated.
[c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
double x1, x2, x3, x4, y1, y2, y3, y4;

while( 8 == ( scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4 ) ) ){
printf("%.3lf %.3lf\n", x1 + ( x4 - x2 ), y1 + ( y4 - y2 ) );
}
}[/c][/c]

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:
you dont know for sure that (x2,y2) and (x3,y3) are the common point.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:
ah. Whoops. Thanks.

karl
New poster
Posts: 11
Joined: Tue Jul 16, 2002 1:03 pm

### 10242 WA

Hello, great helpers and gurus, where are you???

I wrote a nice program but judge doesn't like it. May you explain me the reason why?
Here's source:

[cpp]#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

float x[4],y[4];
int a,b,c;
int takes[4];
float x1,y1;

void find_doublette()
{
int a,b;

for(a=0;a<3;a++)
for(b=a+1;b<4;b++)
if ((x[a]==x[b])&&(y[a]==y[b]))
{
takes[a]=-1;
takes[b]=0;
return;
}
}

int main()
{

while (cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3])
{
for (c=0;c<4;c++)
takes[c]=1;
find_doublette();
x1=0;
y1=0;
for(c=0;c<4;c++)
{
x1=x1+(x[c]*takes[c]);
y1=y1+(y[c]*takes[c]);
}
printf("%0.3f %0.3f\n",x1,y1);
}
return 0;
}[/cpp]

Karl

Even
Learning poster
Posts: 75
Joined: Thu Nov 22, 2001 2:00 am
Location: Taiwan
replace float with double...

off_algos
New poster
Posts: 29
Joined: Wed Nov 13, 2002 11:37 am
Location: india

### 10242 WA help!!!

the following program gave wrong answer for me .. kindly help me out

Code: Select all

``````#include <stdio.h>

int main()
{
struct point
{
double x,y;
};
point a,b,c,temp;
while(scanf("%f %f %f %f %f %f %f %f",&a.x,&a.y,&b.x,&b.y,&temp.x,&temp.y,&c.x,&c.y)>0)
{
if(temp.x==a.x&&temp.y==a.y)
{
temp.x=(b.x+c.x)/2;
temp.y=(b.y+c.y)/2;
printf("%.3f %.3f\n",2*temp.x-a.x,2*temp.y-a.y);
continue;
}
if(temp.x==b.x&&temp.y==b.y)
{
temp.x=(a.x+c.x)/2;
temp.y=(a.y+c.y)/2;
printf("%.3f %.3f\n",2*temp.x-b.x,2*temp.y-b.y);
continue;
}
point x=temp;
temp=c;
c=x;
if(temp.x==a.x&&temp.y==a.y)
{
temp.x=(b.x+c.x)/2;
temp.y=(b.y+c.y)/2;
printf("%.3f %.3f\n",2*temp.x-a.x,2*temp.y-a.y);
continue;
}
if(temp.x==b.x&&temp.y==b.y)
{
temp.x=(a.x+c.x)/2;
temp.y=(a.y+c.y)/2;
printf("%.3f %.3f\n",2*temp.x-b.x,2*temp.y-b.y);
continue;
}
}
return 0;
}
``````

Amir Aavani
New poster
Posts: 30
Joined: Wed Oct 23, 2002 6:53 am
dear karl

i think your program may be get WA because of using x[a]== x.
i am not sure but as i remember floating point number can not be compared using == operator. i in mycode use fabs (x [a] - x)<0.0001 and got AC.

pavelph
Learning poster
Posts: 57
Joined: Wed Dec 10, 2003 7:32 pm
Location: Russia, Saint-Petersburg

### I`m confused...

I don`t know why it gets me Runtime Error.
[pascal]{\$N+}
var i, j, ii, jj, n: integer;
x, y: array [1..4] of double;
v: array [1..4] of integer;
x1, y1: double;

procedure similar; {find 2 similar points}
begin {i & j - numbers of this points}
i:=1;
while i<4 do begin
j:=i+1;
while j<=4 do begin
if ( abs(x - x[j]) < 0.0001) and ( abs(y-y[j]) < 0.0001) then exit;
inc(j);
end;
inc(i);
end;
end;

begin
while true {and not eof} do begin
readln(x[1], y[1], x[2], y[2], x[3], y[3], x[4], y[4]);
similar;
jj:=0;
for ii:=1 to 4 do
if (ii<>i) and (ii<>j) then begin inc(jj); v[jj]:=ii; end;
x1:=x[v[1]]+x[v[2]]-x;
y1:=y[v[1]]+y[v[2]]-y;
writeln(x1:0:3, ' ', y1:0:3);
end;
end.
[/pascal]
It get me WA on 0.002 sec when use cycle [pascal]while true[/pascal].
It mean that my program get RE. But why? Help me please finding bug.

lky
New poster
Posts: 21
Joined: Fri Dec 05, 2003 5:59 pm
Contact:

### 10242 WA

the problem seems to be simple but i dunno why i get WA , someone pls help
program q10242;
var x1,y1,x2,y2,x3,y3,x4,y4,xa,ya,xt,yt:double;
begin
while not eof do
begin
if (x1=x3)and(y1=y3)
then begin
xt:=x4-x3;
yt:=y4-y3;
xa:=x2+xt;
ya:=y2+yt
end;
if (x1=x4)and(y1=y4)
then begin
xt:=x3-x4;
yt:=y3-y4;
xa:=x2+xt;
ya:=y2+yt
end;
if (x2=x3)and(y2=y3)
then begin
xt:=x4-x3;
yt:=y4-y3;
xa:=x1+xt;
ya:=y1+yt
end;
if (x2=x4)and(y2=y4)
then begin
xt:=x3-x4;
yt:=y3-y4;
xa:=x1+xt;
ya:=y1+yt
end;
writeln(xa:0:3,' ',ya:0:3)
end
end.

pavelph
Learning poster
Posts: 57
Joined: Wed Dec 10, 2003 7:32 pm
Location: Russia, Saint-Petersburg

### 10242 - Fourth point of parallelogram

I can`t understand why I get RTE. This is problem 10242 about parallelogram.
[pascal]{\$N+}
program acm10242; {Fourth point of parallelogram}
var i, j, ii, jj, n, same1, same2: integer;
x, y: array [1..4] of double;
v: array [1..4] of integer;
x1, y1: double;

procedure similar; {find 2 similar points}
begin {i & j - numbers of this points}
i:=1;
while i<4 do begin
j:=i+1;
while j<=4 do begin
if ( abs(x - x[j]) < 0.0001) and ( abs(y-y[j]) < 0.0001) then begin
same1:=i;
same2:=j;
end;
inc(j);
end;
inc(i);
end;
end;

begin
{ assign(input, 'input.txt');
reset(input);}
while not eof do begin
readln(x[1], y[1], x[2], y[2], x[3], y[3], x[4], y[4]);
similar;
jj:=0;
for ii:=1 to 4 do
if (ii<>same1) and (ii<>same2) then begin inc(jj); v[jj]:=ii; end;
x1:=x[v[1]]+x[v[2]]-x[same1];
y1:=y[v[1]]+y[v[2]]-y[same1];
writeln(x1:0:3, ' ', y1:0:3);
end;
{ while true do writeln; } {<--I haven't Time Limit Exceed or Output Limit Exceed with this line}
end.
[/pascal]
Really judge answer is WA in 0.002 sec, but I have WA after inserting line [pascal] while true do writeln; [/pascal]
It means that program exits with RE before this line.
On my Free Pascal and Borland Pascal all works. I'm confused, Help me please

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

### 10242 WA

Help me please i don't know what is wrong.
Here is my code.
[pascal]var x,y:array[0..6] of double;
i,j,k,n,i1,j1:longint;
procedure solve;
begin
x[5]:=(x[1]+x[4])/2;
y[5]:=(y[1]+y[4])/2;
x[0]:=2*x[5]-x[2];
y[0]:=2*y[5]-y[2];
end;
procedure swap(i,j:longint);
var r:double;
begin
r:=x;
x:=x[j];
x[j]:=r;
r:=y;
y:=y[j];
y[j]:=r;
end;
begin
while not eof do
begin
for i:=1 to 4 do
for i:=1 to 4 do
for j:=1 to 4 do
if (i<>j) then
if (abs(x-x[j])<0.0001)
and (abs(y-y[j])<0.0001) then
begin
i1:=i;
j1:=j;
end;
if ((i1=1) and (j1=3)) or ((j1=1) and (i1=3)) then swap(1,2);
if ((i1=1) and (j1=4)) or ((j1=1) and (i1=4)) then
begin
swap(1,2);
swap(3,4);
end;
if ((i1=2) and (j1=4)) or ((j1=2) and (i1=4)) then swap(3,4);
solve;
writeln(x[0]:0:3,' ',y[0]:0:3);
end;
end.[/pascal]
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

mlvahe
New poster
Posts: 23
Joined: Wed Jul 30, 2003 6:54 am
Location: Yerevan, Armenia
Hello Eduard.

After changing your code to this you will get accepted.
The idea is that lines
[pascal]
if (eoln) then
begin
continue;
end[/pascal]
will eat empty lines.
[pascal]
var x,y:array[0..6] of double;
i,j,k,n,i1,j1:longint;
procedure solve;
begin
x[0]:=x[1]+x[4]-x[2];
y[0]:=y[1]+y[4]-y[2];
end;
procedure swap(i,j:longint);
var r:double;
begin
r:=x;
x:=x[j];
x[j]:=r;
r:=y;
y:=y[j];
y[j]:=r;
end;
begin
while not eof do
begin
if eoln then
begin
continue;
end;
for i:=1 to 4 do
for i:=1 to 2 do
for j:=3 to 4 do
if (i<>j) then
if (x=x[j]) and (y=y[j]) then
begin
i1:=i;
j1:=j;
end;
if ((i1=1) and (j1=3)) or ((j1=1) and (i1=3)) then swap(1,2);
if ((i1=1) and (j1=4)) or ((j1=1) and (i1=4)) then
begin
swap(1,2);
swap(3,4);
end;
if ((i1=2) and (j1=4)) or ((j1=2) and (i1=4)) then swap(3,4);
solve;
writeln(x[0]:0:3,' ',y[0]:0:3);

end;
end.
[/pascal]

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan
Thank you Vahe.
You are rigth!!!And I think i have the same problem in some another problems too.
And in procedure solve,I write it automaticaly without whatching that i write too long(Thank you for correcting that too ).
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### O.M.G.!!.

Well mlvahe, thanks for the tip!!.
I don't know why, but I just added some
[pascal]while eoLn and not eoF do
and a
[pascal]if not eoF then
begin[/pascal]
to my code, and got AC!!.
Why would that freaking input have empty lines????
Keep posting!!.
_.

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### Go to...

Greetings!.
Go to:
http://online-judge.uva.es/board/viewtopic.php?t=5466
It might be of help for you.

P.S.: I used "double" and got AC in 0:00.002, then used "real" and got AC in 0:00.000. The problem says:
All coordinates are between -10000 and +10000.
So I believe that's why "real" is enough.
_.