ural 2032 Conspiracy Theory and Rebranding 整点三角形
来源:互联网 发布:临沂淘宝客服招聘信息 编辑:程序博客网 时间:2024/05/22 07:55
ural 2032 Conspiracy Theory and Rebranding
链接:https://vjudge.net/contest/175269#problem/I
题意:给定一个三角形的三条边 (a, b, c),问是否可放在二维坐标,使得3个顶点都是整数点。若可以,输出任意一组解,否则,输出 -1。
思路:暴力枚举:以 a 为半径做第一象限的 1/4 圆, 以 b 为半径做 一、四 象限的半圆,存储整数点的解,暴力枚举 a 整数点与 b 整数点是否构成长度为 c 的边。
其实网上还有其他用本源勾股数组做的,但需要分类比较麻烦
#include <iostream>#include<cstdio>#include<bits/stdc++.h>using namespace std;int a,b,c;struct node{ int x,y;}aa[100010],bb[100010];int main(){ while(~scanf("%d%d%d",&a,&b,&c)) { int i,j,y; int k1 = 0,k2 = 0; //找出在第一象限1/4圆上的整点 for(int i=0;i<=a;i++) { y = (int)sqrt(a*1.0*a-i*1.0*i); if(y*y+i*i==a*a) { aa[k1].x=i; aa[k1].y=y; k1++; } } //找出在第一,四象限半圆上的整点 for(int i=-b;i<=b;i++) { y=(int)sqrt(b*1.0*b-i*1.0*i); if(y*y+i*i==b*b) { bb[k2].x = i; bb[k2].y = y; k2++; } } int flag = 0; //验证两点之间距离是否等于第三条边 for(int i=0;i<k1;i++) { if(flag)break; for(int j=0;j<k2;j++) { if(abs(aa[i].x-bb[j].x)*abs(aa[i].x-bb[j].x)+abs(aa[i].y-bb[j].y)*(abs(aa[i].y-bb[j].y))==c*c) { flag = 1; printf("0 0\n%d %d\n%d %d\n",aa[i].x,aa[i].y,bb[j].x,bb[j].y); break; } } } if(!flag)printf("-1\n"); } return 0;}
阅读全文
0 0
- ural 2032 Conspiracy Theory and Rebranding 整点三角形
- URAL_2032_Conspiracy Theory and Rebranding(暴力枚举)
- 三角形内部的整点的个数
- URAL 1043 三角形外接圆
- Theory and Practice
- Java theory and practice
- pthread theory and usage
- Vibration Analysis and Theory Tutorial
- XML in Theory and Practice
- Web Services: Theory and Practice
- Game Design: Theory and Practice
- Systems Modelling: Theory and Practice
- Modern Cryptography: Theory and Practice
- Scheduling: Theory, Algorithms, and Systems
- Light Mapping - Theory and Implementation
- Game Theory and the Web
- Light Mapping - Theory and Implementation
- Software Engineering: Theory and Practice
- 8.7 模拟
- C/C++中关于qsort的使用
- 【git之窗】(八)git高级配置(珍藏版)以log优化为主
- javascript事件
- AndroidStudio-Creat new activity
- ural 2032 Conspiracy Theory and Rebranding 整点三角形
- Numpy(二)
- java中的静态变量、静态方法与静态代码块详解与初始化顺序
- 生成模型和判别模型
- 二进制问题
- 网络字节序
- 音频设计要求
- Day11
- POJ 3190 Stall Reservations