URAL_2032_Conspiracy Theory and Rebranding(暴力枚举)
来源:互联网 发布:西安交大软件学院院长 编辑:程序博客网 时间:2024/06/04 08:54
题型:计算几何
题意:给出三角形的三条边,问该三角形的三个顶点能否是直角坐标系中的整数格点。
分析:
设一个顶点在原点,然后作一个长度为a的圆和一个长度为b的圆,暴力求解圆上有多少个整数格点。然后枚举圆a上的整数格点和圆b上的整数格点,看距离是否为c,有的话直接输出,最后也没找到就输出-1.
代码:
#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<vector>#define LL __int64using namespace std;struct Point { int x,y; Point(int x = 0 , int y = 0) :x(x),y(y) {} void out() { printf("%d %d\n",x,y); }};vector<Point> v;LL dist(Point T,Point S) { return 1LL*(T.x-S.x)*(T.x-S.x)+1LL*(T.y-S.y)*(T.y-S.y);}int main() { int a,b,c; while(~scanf("%d%d%d",&a,&b,&c)) { Point O(0,0); v.clear(); for(int i=0; i<=a; i++) { LL tmp = 1LL*a*a - 1LL*i*i; int j = sqrt(tmp+0.0); if(1LL*j*j != tmp) j++; if(1LL*j*j != tmp) continue; v.push_back(Point(i,j)); } Point B; for(int i=0; i<=b; i++) { LL tmp = 1LL*b*b - 1LL*i*i; int j = sqrt(tmp+0.0); if(1LL*j*j != tmp) j++; if(1LL*j*j != tmp) continue; B = Point(i,j); for(int k=0; k<v.size(); k++) { if(dist(v[k],B) == 1LL*c*c) { O.out(); B.out(); v[k].out(); return 0; } } B = Point(i,-j); for(int k=0; k<v.size(); k++) { if(dist(v[k],B) == 1LL*c*c) { O.out(); B.out(); v[k].out(); return 0; } } B = Point(-i,j); for(int k=0; k<v.size(); k++) { if(dist(v[k],B) == 1LL*c*c) { O.out(); B.out(); v[k].out(); return 0; } } B = Point(-i,-j); for(int k=0; k<v.size(); k++) { if(dist(v[k],B) == 1LL*c*c) { O.out(); B.out(); v[k].out(); return 0; } } } puts("-1"); } return 0;}
0 0
- URAL_2032_Conspiracy Theory and Rebranding(暴力枚举)
- ural 2032 Conspiracy Theory and Rebranding 整点三角形
- 暴力枚举 C. Arthur and Table
- UVA 10825 Anagram and Multiplication(暴力枚举)
- hdu 5944 Fxx and string【暴力枚举】
- 暴力枚举
- 暴力枚举?
- 暴力枚举
- 暴力枚举
- 暴力枚举
- CF 321A(Ciel and Robot-暴力枚举)
- codeforces 380B Sereja and Tree 暴力枚举
- Codeforces 425A Sereja and Swaps(暴力枚举)
- HDU ACM 5224 Tom and paper 水题+暴力枚举
- CodeForces 552D — Vanya and Triangles 暴力枚举
- CF_318_Div.2 Bear and Elections(二分||暴力枚举)
- codeforces 324# E. Anton and Ira (暴力枚举+贪心)
- Codeforces #325 B. Laurenty and Shop (暴力枚举)
- ios TabBat 中图标设计模糊的问题
- 执行力在ERP系统中发挥的作用
- HDU5087 - Revenge of LIS II (次长上升子序列)
- 第十周项目四 (拓展)大奖赛计分
- 一蓑烟雨任平生
- URAL_2032_Conspiracy Theory and Rebranding(暴力枚举)
- Binary Tree Level Order Traversal II-LeetCode
- RROR 1045 (28000):
- 使用edittext直接添加qq表情
- 指针和引用(c++)
- Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道
- DLL初步和钩子入门
- WPF 3D Primer
- poj百练 2694