Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define mp make_pair
  4. #define maxn 200002
  5.  
  6. int T, n;
  7. int x[maxn], y[maxn];
  8. vector<pair<pair<int, int>, int> > v;
  9. vector<int> oto, oto2;
  10.  
  11. int wek(int a, int b, int c){
  12. return ((x[b]-x[a])*(y[c]-y[a]))-((y[b]-y[a])*(x[c]-x[a]));
  13. }
  14.  
  15. long double len(int a, int b){
  16. long double dx=abs(x[a]-x[b]);
  17. long double dy=abs(y[a]-y[b]);
  18. return sqrt(dx*dx+dy*dy);
  19. }
  20.  
  21. void find_conv(){
  22. oto.clear();
  23. oto2.clear();
  24. oto.push_back(v[0].second);
  25. oto.push_back(v[1].second);
  26. for(int i=2; i<n; i++){
  27. while(oto.size()>=2 && wek(oto[oto.size()-2], oto.back(), v[i].second)<0) oto.pop_back();
  28. oto.push_back(v[i].second);
  29. }
  30. oto2.push_back(v.back().second);
  31. oto2.push_back(v[v.size()-2].second);
  32. for(int i=n-3; i>=0; i--){
  33. while(oto2.size()>=2 && wek(oto2[oto2.size()-2], oto2.back(), v[i].second)<0) oto2.pop_back();
  34. oto2.push_back(v[i].second);
  35. }
  36. }
  37.  
  38. void answer(){
  39. long double odp=0;
  40. for(int i=1; i<oto.size(); i++){
  41. odp+=len(oto[i-1], oto[i]);
  42. }
  43. for(int i=1; i<oto2.size(); i++){
  44. odp+=len(oto2[i-1], oto2[i]);
  45. }
  46. long long ile=ceil(odp/150);
  47. printf("%lld ", ile);
  48. for(int i=0; i<oto.size(); i++){
  49. printf("%d ", oto[i]);
  50. }
  51. for(int i=1; i<oto2.size()-1; i++){
  52. printf("%d ", oto2[i]);
  53. }
  54. printf("\n");
  55. }
  56.  
  57. int main(){
  58. scanf("%d", &T);
  59. for(int q=1; q<=T; q++){
  60. scanf("%d", &n);
  61. int a, b;
  62. v.clear();
  63. for(int i=1; i<=n; i++){
  64. scanf("%d%d", &a, &b);
  65. x[i]=a;
  66. y[i]=b;
  67. v.push_back(mp(mp(a, b), i));
  68. }
  69. sort(v.begin(), v.end());
  70. find_conv();
  71. answer();
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement