有一個問題,他們在圖上有點(約100個),並且它們都旋轉了一定數量,除了其中一個。因此,我通過從第一組點的中心到第二組的中心的距離,然後在比較它們之後,將沒有匹配距離來解決這個問題 - 這將是錯誤的點。在圖形程序中無法理解錯誤的答案
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
int main()
{
int star1, star2;
cin>>star1;
int x1[star1], y1[star1];
for (int i=0; i<star1; i++)
{cin>>x1[i]>>y1[i];}
cin>>star2;
int x2[star2], y2[star2];
for (int i=0; i<star2; i++)
{cin>>x2[i]>>y2[i];}
int d1[star1], d2[star2];
for (int i=0; i<star1; i++)
{d1[i]=sqrt(x1[i]*x1[i]+y1[i]*y1[i]);
d2[i]=sqrt(x2[i]*x2[i]+y2[i]*y2[i]);
}
int dis=0; //the ones furthest from the center will be gone
if (star1>star2)
{for (int i=0; i<(star1-star2); i++)
{if (d1[i]<d1[i+1])
{dis=i+1;} }
for (int i = dis; i < star1; i++)
{d1[dis] = d1[dis+1];
d1[star1-1] = 0;}
}
else if (star2>star1)
{for (int i=0; i<(star2-star1); i++)
{if (d2[i]<d2[i+1])
{dis = i+1;} }
for (int i = dis; i < star2; i++)
{d2[dis] = d2[dis+1];
d2[star2-1] = 0;}
}
int one, two;
for (int begin=0; begin<star1; begin++)
{
for (int i=0; i<star2; i++)
{if (d1[begin]==d2[i])
{one=begin; two=i;
goto finish;}}
}
finish:
cout<<one<<" "<<two;
}
原題:http://www.codeabbey.com/index/task_view/wandering-star 是不是有毛病我的代碼,或有毛病我的解釋呢?
啊。在換擋部位錯過了。我必須考慮..... @。@ –