ural 2032 Conspiracy Theory and Rebranding
链接:http://acm.timus.ru/problem.aspx?space=1&num=2032
题意:给定一个三角形的三条边 (a, b, c),问是否可放在二维坐标,使得3个顶点都是整数点。若可以,输出任意一组解,否则,输出 -1。
思路:暴力枚举:以 a 为半径做第一象限的 1/4 圆, 以 b 为半径做 一、四 象限的半圆,存储整数点的解,暴力枚举 a 整数点与 b 整数点是否构成长度为 c 的边。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring> using namespace std;
typedef long long ll;
const int N = 1e5+;
ll biao[N];
ll a, b, c;
int n; ll rr, RR; struct P{
ll x, y;
P(ll _x=, ll _y=) : x(_x), y(_y) {}
void out() {printf("%I64d %I64d\n", x, y); }
}p[N], v[N];
int ta, tb; inline ll sqr(ll x) {return x*x;} inline void init(ll av, ll r, int &t, P q[]) {
ll aa = av*av;
for(ll i = , j = av; i <= av; ++i) {
while(sqr(i) + sqr(j) > aa) --j;
if(sqr(i) + sqr(j) == aa) q[t++] = P(i, j);
}
} inline ll dis(P d1, P d2) {
return sqr(d1.x - d2.x) + sqr(d1.y - d2.y);
} void solve() {
ta = tb = ;
ll cc = c*c;
init(a, rr, ta, p);
init(b, RR, tb, v);
bool f = , ff;
int i, j;
P q;
for(i = ; i < ta; ++i) {
for(j = ; j < tb; ++j) {
ll d = dis(p[i], v[j]);
if(d == cc) {
f = , ff = ;
break;
} else{
q = P(v[j].x, -v[j].y);
d = dis(p[i], q);
if(d == cc) {
f = ff = ;
break;
}
}
}
if(f) break;
}
if(!f) { puts("-1"); return ; }
puts("0 0"); p[i].out();
if(!ff) v[j].out();
else q.out();
return ;
} int main()
{
#ifdef PIT
freopen("i.in", "r", stdin);
#endif // PIT while(~scanf("%I64d %I64d %I64d", &a, &b, &c)) {
rr = a*a, RR = b*b;
solve();
}
return ;
}