ural 2032 Conspiracy Theory and Rebranding (数学水题)

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 的边。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cmath>
 5 #include <cstring>
 6
 7 using namespace std;
 8 typedef long long ll;
 9 const int N = 1e5+7;
10 ll biao[N];
11 ll a, b, c;
12 int n;
13
14 ll rr, RR;
15
16 struct P{
17     ll x, y;
18     P(ll _x=0, ll _y=0) : x(_x), y(_y) {}
19     void out() {printf("%I64d %I64d\n", x, y); }
20 }p[N], v[N];
21 int ta, tb;
22
23 inline ll sqr(ll x) {return x*x;}
24
25 inline void init(ll av, ll r, int &t, P q[]) {
26     ll aa = av*av;
27     for(ll i = 0, j = av; i <= av; ++i) {
28         while(sqr(i) + sqr(j) > aa) --j;
29         if(sqr(i) + sqr(j) == aa) q[t++] = P(i, j);
30     }
31 }
32
33 inline ll dis(P d1, P d2) {
34     return sqr(d1.x - d2.x) + sqr(d1.y - d2.y);
35 }
36
37 void solve() {
38     ta = tb  = 0;
39     ll cc = c*c;
40     init(a, rr, ta, p);
41     init(b, RR, tb, v);
42     bool f = 0, ff;
43     int i, j;
44     P q;
45     for(i = 0; i < ta; ++i) {
46         for(j = 0; j < tb; ++j) {
47             ll d = dis(p[i], v[j]);
48             if(d == cc) {
49                 f = 1, ff = 0;
50                 break;
51             } else{
52                 q = P(v[j].x, -v[j].y);
53                 d = dis(p[i], q);
54                 if(d == cc) {
55                     f = ff = 1;
56                     break;
57                 }
58             }
59         }
60         if(f) break;
61     }
62     if(!f) { puts("-1"); return ; }
63     puts("0 0"); p[i].out();
64     if(!ff) v[j].out();
65     else q.out();
66     return ;
67 }
68
69 int main()
70 {
71 #ifdef PIT
72 freopen("i.in", "r", stdin);
73 #endif // PIT
74
75     while(~scanf("%I64d %I64d %I64d", &a, &b, &c)) {
76         rr = a*a, RR = b*b;
77         solve();
78     }
79     return 0;
80 }
时间: 2024-08-01 07:02:49

ural 2032 Conspiracy Theory and Rebranding (数学水题)的相关文章

URAL 2032 - Conspiracy Theory and Rebranding【本源勾股数组】

[题意] 给出三角形的三个边长,均是10^7以内的整数,问三角形的三个角的坐标是否能均是整数,输出其中任意一个解. [题解] 一开始想的是枚举一条边的横坐标,然后通过勾股定理以及算角度求出其他点的坐标,再判断是否符合条件. 亲测TLE 直到知道了本源勾股数组的构造方法... 每个本源勾股数组(a,b,c)满足a*a+b*b=c*c,其中a为奇数,b为偶数.. 枚举s,t(1<=t<s,且它们是没有公因数的奇数) a=st b=(s*s-t*t)/2 c=(s*s+t*t)/2 因为最大数c=(

URAL 1023 Buttons(巴什博弈水题)

1023. Buttons Time limit: 2.0 secondMemory limit: 64 MB Background As you surely already know, Yekaterinburg has gotten its right to hold The Summer Olympic Games of the 2032. It is planned that it will be allowed to Russia as a country-organizer to

hdu5387 Clock(数学水题)

题目: Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 709    Accepted Submission(s): 452 Problem Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute

FZU OJ 2147 A-B Game (数学水题)

Problem 2147 A-B Game Accept: 827    Submit: 1940 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on

HDU 1840 Equations (简单数学 + 水题)(Java版)

Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840 --每天在线,欢迎留言谈论. 题目大意: 给你一个一元二次方程组,a(X^2) + b(X) + c = 0 .求X解的个数. 思路: 分别讨论二次方程与一次方程的情况,再特殊处理下 a = b = c = 0 的情况. 感想: 是时候该水水题了. Java AC代码: 1 import java.math.*; 2 import java.util.Scanner; 3

URAL 1039 Anniversary Party 树形DP 水题

1039. Anniversary Party Time limit: 0.5 secondMemory limit: 8 MB Background The president of the Ural State University is going to make an 80'th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor rela

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

水题日记

一定要相信水题真的很水 POJ-2546 1 #include<iostream> 2 #include<stdio.h> 3 #include<cmath> 4 5 using namespace std; 6 7 #define PI acos(double(-1)) 8 9 int main() 10 { 11 double x1, y1, r1, x2, y2, r2; 12 cin>>x1>>y1>>r1>>x2

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive