There is a problem in which they have points on a graph (~100 of them) and they all rotate by a certain amount, except one of them. I thus tackle this problem by taking the distances from the center of the first set of points, and also distances from center of the second set, then, after comparing them, one set will not have a matching distance--which will be the wrong point.
#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;
}
The original problem: http://www.codeabbey.com/index/task_view/wandering-star Is it something wrong with my code, or something wrong with my interpretation?
Aucun commentaire:
Enregistrer un commentaire