![:evil:](./images/smilies/icon_evil.gif)
Any help?
Code: Select all
// Bernardo E. L
Moderator: Board moderators
Go back to the past few posts, you will find a lot said about inSquare/onSquare and inCircle/onCircle methods.Actually I used them as follows:_.B._ wrote:Well, I'm tired of WAs again
Any help?
Thanks in advance!Code: Select all
... [snip] /* How do you know, when this function returns true, that the point lies on the circle and not inside it? */ bool in_circle(objects objeto, bool &borde, sint x1, sint y1) { double aux_distancia = hipotenusa_al_cuadrado(objeto.x, objeto.y, x1, y1), radio_al_cuadrado = objeto.length * objeto.length; borde = false; if(aux_distancia < radio_al_cuadrado) return true; else if(aux_distancia == radio_al_cuadrado) borde = true; // Point lies on the edge. return false; }
Code: Select all
+ inCircle() checks if the point lies completely in the circle or not
+ onCircle() checks if the point lies on the circumference i.e circle's boundary or not.
Code: Select all
+ inSquare()
+ onSquare()
Both functions return true if the point is inside a figure, and will make borde = true if the point is on the edge of a figure.How do you know, when this function returns true, that the point lies on the circle and not inside it?
Code: Select all
//typedef unsigned int usint;
typedef long usint;
//typedef int sint;
typedef long int sint;
Code: Select all
bool in_square(objects objeto, bool &borde, sint x, sint y)
{ unsigned int longitud = objeto.length;
borde = false;
if(x > objeto.x && x < (objeto.x + longitud) && y > objeto.y && y < (objeto.y + longitud))
return true;
else
if((x == objeto.x || x == (objeto.x + longitud)) && y >= objeto.y && y <= (objeto.y + longitud))
borde = true; // Point lies on one vertical side.
else
if(x >= objeto.x && x <= (objeto.x + longitud) && (y == objeto.y || y == (objeto.y + longitud)))
borde = true; // Point lies on one horizontal side.
return false;
}
There are negative integers in the input. From the problem's statement: Each query point is denoted by an integer pair px and py (-1000 <= px,py <= +1000) ._.B._ wrote:Now I have 2 questions:
1- Why is it that when I use unsigned int for longitud in my in_square function I get a WA?? (by using int I get it ACed).
"short" is a 16-bit integer type on the judge's system, while "int" and "long" are both 32-bit._.B._ wrote: 2- Why is it that if I use short int instead of long int for my global variables it will solve the problem in twice the time??
objeto.length is the radius of the circle/length of each side of a square which by the problem statement lies in [0, 2000].So that is not a correct observation.mf wrote:There are negative integers in the input. From the problem's statement: Each query point is denoted by an integer pair px and py (-1000 <= px,py <= +1000) ._.B._ wrote:Now I have 2 questions:
1- Why is it that when I use unsigned int for longitud in my in_square function I get a WA?? (by using int I get it ACed).
Working with 16 bits will be fast on a 16 bit machine, 32 bits on a 32 bits"short" is a 16-bit integer type on the judge's system, while "int" and "long" are both 32-bit._.B._ wrote: 2- Why is it that if I use short int instead of long int for my global variables it will solve the problem in twice the time??
Code: Select all
#include <stdio.h>
int main()
{
int x;
unsigned u;
x = -2;
u = 1;
if ((x + u) > 0)
printf("%d + %u: positive\n", x, u);
else
printf("%d + %u: non-negative\n", x, u);
return 0;
}
Code: Select all
1
2 3
CIRCLE 0 0 5 100 100 100
CIRCLE 0 0 5 100 150 100
0 0
0 5
4 3
Code: Select all
Case 1:
(100, 125, 100)
(0, 0, 0)
(0, 0, 0)
sumankar wrote:Working with 16 bits will be fast on a 16 bit machine, 32 bits on a 32 bits...
Thanks a lot!, that's some really useful infomf wrote:The problem is because the code mixes signed and unsigned integers. The standard says that "if either operand is unsigned int, the other is converted to unsigned int." (quote from K&R C 1988 edition, section A.6.5)...