# UVA Problem 12894 – Perfect Flag Solution

UVA Problem 12894 – Perfect Flag Solution:

Solving Technique:

Rank 38, Run time 9 ms ( 0.009 s ).

This problem may seem very hard if we don’t read it carefully. Also there is no need to use floating point numbers to solve this problem. Also no need to worry about negative length or widths. In case you forgot about Ratio.

Here are the key points,

###### 1. length (L) to width ratio of 10:6,
```>> length / width = 10 / 6
>> 6 * length = 10 * width
>> 3 * length = 5 * width
```

2. length (L) to radius ratio of 5:1,

```>> length / radius = 5 / 1
>> 1 * length = 5 * radius
```

3. Example: If the length is 10, then width should be 6 and radius should be 2.
Set these values in our equations above and check if both sides are equal.

4. Its center (Circle’s) will be placed on the intersecting point of thee perpendicular drawn from the nine-twentieth part of the length of the flag,

```>> nine-twentieth of length, ( 9 / 20 ) * length
>> Circles x distance on flag = given x position of circle - initial x position
>> 20 * (circle center x - initial x) = 9 * length
```

5. Horizontal line drawn through the middle of its width,

```>> Circle middle y distance = given circle y - initial y
>> middle of width, (1/2) * width
>> 2 * ( given circle y - initial y ) = width
```

Important:  Be sure to add or print a new line after each output unless otherwise specified. The outputs should match exactly because sometimes even a space character causes the answer to be marked as wrong answer.

Input:

```4
0 0 20 12 9 6 4
0 0 10 6 4 3 2
1 1 21 13 10 7 4
0 0 20 20 9 10 4```

Output:

```YES
NO
YES
NO```

### Code (with given Formula):

```/*
* Author: Quickgrid ( Asif Ahmed )
* Site: https://quickgrid.wordpress.com
* Problem: UVA 12894 ( Perfect Flag )
*/

#include<stdio.h>

int main(){
register unsigned n;
scanf("%u", &n);

while (n--){
int x0, y0, x1, y1, cx, cy, r;
scanf("%u%u%u%u%u%u%u", &x0, &y0, &x1, &y1, &cx, &cy, &r);

unsigned len = x1 - x0;
unsigned wid = y1 - y0;

if (( 5 * wid == 3 * len ) && ( len == 5 * r ) && 20 * ( cx - x0 ) == 9 * len && 2 * ( cy - y0 ) == wid)
printf("YES\n");
else
printf("NO\n");

}
return 0;
}
```

### Another in C++ ( Without Optimization ):

```/*
* Author: Quickgrid ( Asif Ahmed )
* Site: https://quickgrid.wordpress.com
* Problem: UVA 12894 ( Perfect Flag )
*/

#include<iostream>

int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);

register unsigned n;
unsigned int x0, y0, x1, y1, cx, cy, r;

std::cin >> n;
while (n--){
std::cin >> x0 >> y0 >> x1 >> y1 >> cx >> cy >> r;
unsigned len = x1 - x0, wid = y1 - y0;
(( 5*wid == 3*len ) && ( len == 5*r ) && (20*( cx - x0 ) == 9*len) && ((( cy-y0 ) << 1) == wid) ) ? std::cout << "YES\n" : std::cout << "NO\n";
}

return 0;
}
```

### Code (Strength Reduction Optimization based on the first code):

```/*
* @author Quickgrid ( Asif Ahmed )
* Problem UVA 12894 ( Perfect Flag )
*/
#include<stdio.h>

int main(){
unsigned n, x0, y0, cx, cy, r;
scanf("%u", &n);

while (n--){
scanf("%u%u%*u%*u%u%u%u", &x0, &y0, &cx, &cy, &r);

if (2 * ( cx - x0 ) + ( y0 - cy ) == 3 * r)
printf("YES\n");
else
printf("NO\n");

}
return 0;
}
```