Advertisement
a53

SortareUnghi

a53
Jan 23rd, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4. ifstream f("sortareunghi.in");
  5. ofstream g("sortareunghi.out");
  6. pair<int,int> v[101];
  7. int n,i;
  8.  
  9. int cadran(int x,int y)
  10. {
  11. if(x>0&&y>=0)
  12. return 1;
  13. if(x<=0&&y>0)
  14. return 2;
  15. if(x<=0&&y<=0)
  16. return 3;
  17. return 4;
  18. }
  19.  
  20. int det(int X1,int Y1,int X2,int Y2,int X3,int Y3)
  21. {
  22. return (X2-X1)*(Y3-Y1)-(X3-X1)*(Y2-Y1);
  23. }
  24.  
  25. int cmp(const pair<int,int> &a,const pair<int,int> &b)
  26. {
  27. int c1=cadran(a.first,a.second);
  28. int c2=cadran(b.first,b.second);
  29. if(c1!=c2)
  30. return c1<c2;
  31. else
  32. {
  33. int d=det(0,0,a.first,a.second,b.first,b.second);
  34. if (d!=0)
  35. return d>0;
  36. else
  37. return a.first*a.first+a.second*a.second<b.first*b.first+b.second*b.second;
  38. }
  39. }
  40.  
  41. int main()
  42. {
  43. f>>n;
  44. for (i=1;i<=n;++i)
  45. f>>v[i].first>>v[i].second;
  46. sort(v+1,v+n+1,cmp);
  47. for (i=1;i<=n;++i)
  48. g<<v[i].first<<' '<<v[i].second<<'\n';
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement