标签:style blog ar for sp on 2014 log ef
首先要求在平面内找到一个直角三角形,两个边长分别为a,b,并且三条边都不得与二维坐标轴的 平行,且点都在整数点上,首先这个三角形若是存在的话,那么它肯定可以在这个平面上平移的,那么我们把它给移到一二象限,然后一个点固定在(0,0)点,这样另外两个点看一下 a,b,的范围,那么另外两个点无非在 一二两个象限内以(0,0)为端点的 边长为1000的正方形内,在这两个正方形内 枚举出所有符合的点,分在两个容器内,然后在枚举两个点 与(0,0)点是否可以组成直角三角形,是否与坐标轴平行
int aa,bb;
vector<pair<int ,int > > xx,yy,ans;
void init() {
xx.clear();
yy.clear();
ans.clear();
}
bool input() {
while(cin>>aa>>bb) {
return false;
}
return true;
}
int dis(int x1,int y1,int x2,int y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
void cal() {
bool flag = false;
for(int i=1;i<=1000;i++)
for(int j=1;j<=1000;j++)
if(dis(i,j,0,0) == aa * aa)xx.push_back(make_pair(i,j));
for(int i=-1;i>=-1000;i--)
for(int j=1;j<=1000;j++)
if(dis(i,j,0,0) == aa * aa)xx.push_back(make_pair(i,j));
for(int i=1;i<=1000;i++)
for(int j=1;j<=1000;j++)
if(dis(i,j,0,0) == bb * bb)yy.push_back(make_pair(i,j));
for(int i=-1;i>=-1000;i--)
for(int j=1;j<=1000;j++)
if(dis(i,j,0,0) == bb * bb)yy.push_back(make_pair(i,j));
for(int i=0;i<xx.size();i++) {
if(flag)break;
for(int j=0;j<yy.size();j++) {
if(flag)break;
int tx = xx[i].first,ty = xx[i].second;
int txx = yy[j].first,tyy = yy[j].second;
int cc = dis(xx[i].first,xx[i].second,yy[j].first,yy[j].second);
if(aa * aa + bb * bb == cc || aa * aa == bb * bb + cc || bb * bb == aa * aa + cc) {
if(xx[i].first == yy[j].first || xx[i].second == yy[j].second)continue;
flag = true;
ans.push_back(make_pair(xx[i].first,xx[i].second));
ans.push_back(make_pair(yy[j].first,yy[j].second));
break;
}
}
}
if(!flag)puts("NO");
else {
puts("YES");
puts("0 0");
cout<<ans[0].first<<" "<<ans[0].second<<endl;
cout<<ans[1].first<<" "<<ans[1].second<<endl;
}
}
void output() {
}
int main() {
while(true) {
init();
if(input())return 0;
cal();
output();
}
return 0;
}
标签:style blog ar for sp on 2014 log ef
原文地址:http://blog.csdn.net/yitiaodacaidog/article/details/40620945