Advertisement
erfanul007

LOJ 1196

Nov 3rd, 2020
1,971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // #include <iostream>
  3. // #include <cstdio>
  4. // #include <cstdlib>
  5. // #include <algorithm>
  6. // #include <cmath>
  7. // #include <vector>
  8. // #include <set>
  9. // #include <map>
  10. // #include <queue>
  11. // #include <ctime>
  12. // #include <cassert>
  13. // #include <complex>
  14. // #include <string>
  15. // #include <cstring>
  16. // #include <queue>
  17. // #include <bitset>
  18.  
  19. using namespace std;
  20.  
  21. // #pragma GCC optimize("Ofast,no-stack-protector")
  22. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  23. // #pragma GCC optimize("unroll-loops")
  24.  
  25.  
  26. #define ll              long long int
  27. #define vi              vector< int >
  28. #define vll             vector< ll >
  29.  
  30. #define sc              scanf
  31. #define pf              printf
  32. #define cspf(i)         pf("Case %d:\n", i)
  33. #define spc             pf(" ")
  34. #define line            pf("\n")
  35.  
  36. #define ff              first
  37. #define ss              second
  38. #define mp              make_pair
  39. #define pb              push_back
  40. #define ppb             pop_back
  41. #define tp(v,j)         get<j>(v)
  42. #define Log(b,x)        (log(x)/log(b))
  43.  
  44. #define FOR(i,x,y)      for(int i = int(x); i < int(y); i++)
  45. #define ROF(i,x,y)      for(int i = int(x)-1; i >= int(y); i--)
  46. #define clr(arr,x)      memset(arr, x, sizeof arr)
  47. #define vout(v,sz)      for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
  48. #define all(v)          v.begin(), v.end()
  49. #define rall(v)         v.rbegin(), v.rend()
  50. #define unq(v)          sort(all(v)),(v).resize(unique(all(v))-v.begin())
  51. #define fastIO          ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
  52.  
  53. #define sc1(x)          sc("%d",&x)
  54. #define sc2(x,y)        sc("%d %d", &x, &y)
  55. #define sc3(x,y,z)      sc("%d %d %d", &x, &y, &z)
  56. #define scl1(x)         sc("%lld",&x);
  57. #define scl2(x,y)       sc("%lld %lld", &x, &y)
  58. #define scf1(x)         sc("%lf",&x)
  59. #define scf2(x,y)       sc("%lf %lf", &x, &y)
  60.  
  61. #define pf1(x)          pf("%d",x)
  62. #define pf2(x,y)        pf("%d %d", x, y)
  63. #define pf3(x,y,z)      pf("%d %d %d", x, y, z)
  64. #define pfl1(x)         pf("%lld",x)
  65. #define pfl2(x,y)       pf("%lld %lld",x,y)
  66.  
  67. #define MOD             (ll)(1e9)
  68. #define MaxN            100001
  69. #define inf             0x3f3f3f3f
  70. #define PI              acos(-1.0)  // 3.1415926535897932
  71. #define eps             1e-9
  72.  
  73. template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
  74. template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
  75. template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
  76. template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
  77. template <class T> inline T SQR(T a){return a*a;}
  78.  
  79. int dx[] = { 1,-1, 0, 0};
  80. int dy[] = { 0, 0, 1,-1};
  81.  
  82. struct PT{
  83.     ll x,y;
  84.     void scan(){ scanf("%lld %lld",&x,&y);}
  85.     void prnt(){ printf("%lld %lld\n",x,y);}
  86. }ar[MaxN];
  87.  
  88. ll SQ(ll x){ return x*x;}
  89.  
  90. ll Dis(PT a,PT b){ return SQ(a.x-b.x) + SQ(a.y-b.y);}
  91.  
  92. long double absDis(PT a,PT b){ return sqrt((long double)Dis(a,b));}
  93.  
  94. // ll orientation(PT a,PT b,PT c){ return (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);}
  95.  
  96. ll AreaOfTri(PT a, PT b, PT c)
  97. {
  98.     ll area = 0;
  99.     area += a.x * b.y - b.x * a.y;
  100.     area += b.x * c.y - c.x * b.y;
  101.     area += c.x * a.y - a.x * c.y;
  102.     return area; //positive anticlockwise, negative clockwise
  103. }
  104.  
  105. PT f; //init first coordinate
  106. //for anti-clockwise sorting
  107. bool AClockCmp(PT &a,PT &b){ return (f.x-a.x)*(f.y-b.y)>(f.x-b.x)*(f.y-a.y);}
  108.  
  109. //find the highets point lower then f_p
  110. int bslo(int lo, int hi, PT p){
  111.     if(lo>hi) return -1;
  112.     int mid = (lo+hi)/2;
  113.     ll ori = AreaOfTri(f, ar[mid], p);
  114.     if(ori >= 0) return max(mid, bslo(mid+1, hi, p));
  115.     return bslo(lo, mid-1, p);
  116. }
  117.  
  118. //check if p lies in segment a_b
  119. bool insegment(PT a, PT b, PT p){
  120.     long double dis = absDis(a, b);
  121.     long double dis1 = absDis(a, p);
  122.     long double dis2 = absDis(p, b);
  123.     return abs(dis - (dis1 + dis2)) <= eps;
  124. }
  125.  
  126.  
  127. int main(){
  128.  
  129.     #ifndef ONLINE_JUDGE
  130.         clock_t tStart = clock();
  131.         freopen("input.txt", "r", stdin);
  132.         freopen("output.txt", "w", stdout);
  133.     #endif
  134.  
  135.     int t, ca=0; sc1(t);
  136.  
  137.     while(t--){
  138.         int n; sc1(n);
  139.         FOR(i,0,n) ar[i].scan();
  140.         f = ar[0];
  141.         //sort(ar, ar+n, AClockCmp);
  142.  
  143.         cspf(++ca);
  144.  
  145.         int q; sc1(q);
  146.  
  147.         while(q--){
  148.             PT p;
  149.             p.scan();
  150.  
  151.             int inx = bslo(0, n-1, p);
  152.  
  153.             if(inx==-1) pf("n\n");
  154.             else if(inx == n-1){
  155.                 if(insegment(f, ar[inx], p)) pf("y\n");
  156.                 else pf("n\n");
  157.             }
  158.             else{
  159.                 //check if point is inside the f_inxlo_inxhi triangle
  160.                 ll ori = AreaOfTri(ar[inx], ar[inx+1], p);
  161.                 if(ori>=0) pf("y\n");
  162.                 else pf("n\n");
  163.             }
  164.         }
  165.     }
  166.  
  167.  
  168.     #ifndef ONLINE_JUDGE
  169.         fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  170.     #endif
  171.  
  172.     return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement