Advertisement
erfanul007

UVa 866

Apr 9th, 2021
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.75 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 <stack>
  12. // #include <ctime>
  13. // #include <cassert>
  14. // #include <complex>
  15. // #include <string>
  16. // #include <cstring>
  17. // #include <bitset>
  18. using namespace std;
  19.  
  20. // #pragma GCC optimize("Ofast,no-stack-protector")
  21. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  22. // #pragma GCC optimize("unroll-loops")
  23.  
  24. #define ll              long long int
  25. #define vi              vector< int >
  26. #define vll             vector< ll >
  27.  
  28. #define sc              scanf
  29. #define pf              printf
  30. #define cspf(i)         pf("Case %d: ", i)
  31. #define spc             pf(" ")
  32. #define line            pf("\n")
  33.  
  34. #define ff              first
  35. #define ss              second
  36. #define mp              make_pair
  37. #define pb              push_back
  38. #define ppb             pop_back
  39. #define tp(v,j)         get<j>(v)
  40. #define Log(b,x)        (log(x)/log(b))
  41.  
  42. #define FOR(i,x,y)      for(int i = int(x); i < int(y); i++)
  43. #define ROF(i,x,y)      for(int i = int(x)-1; i >= int(y); i--)
  44. #define clr(arr,x)      memset(arr, x, sizeof arr)
  45. #define vout(v,sz)      for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
  46. #define all(v)          v.begin(), v.end()
  47. #define rall(v)         v.rbegin(), v.rend()
  48. #define unq(v)          sort(all(v)),(v).resize(unique(all(v))-v.begin())
  49. #define fastIO          ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
  50.  
  51. #define sc1(x)          sc("%d",&x);
  52. #define sc2(x,y)        sc("%d %d", &x, &y)
  53. #define sc3(x,y,z)      sc("%d %d %d", &x, &y, &z)
  54. #define scl1(x)         sc("%lld",&x);
  55. #define scl2(x,y)       sc("%lld %lld", &x, &y)
  56. #define scf1(x)         sc("%lf",&x);
  57. #define scf2(x,y)       sc("%lf %lf", &x, &y)
  58.  
  59. #define pf1(x)          pf("%d",x);
  60. #define pf2(x,y)        pf("%d %d", x, y)
  61. #define pfl1(x)         pf("%lld",x);
  62. #define pfl2(x,y)       pf("%lld %lld", x, y)
  63.  
  64. #define MOD             (int)(998244353)
  65. #define MaxN            100000
  66. #define inf             0x3f3f3f3f
  67. #define PI              acos(-1.0)  // 3.1415926535897932
  68. #define eps             1e-9
  69.  
  70. #ifdef ERFANUL007
  71.     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
  72.     template < typename Arg1 >
  73.     void __f(const char* name, Arg1&& arg1){
  74.         cout << name << " = " << arg1 << std::endl;
  75.     }
  76.     template < typename Arg1, typename... Args>
  77.     void __f(const char* names, Arg1&& arg1, Args&&... args){
  78.         const char* comma = strchr(names, ',');
  79.         cout.write(names, comma - names) << " = " << arg1 <<" | ";
  80.         __f(comma+1, args...);
  81.     }
  82. #else
  83.     #define debug(...)
  84. #endif
  85.  
  86. 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;}
  87. template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
  88. template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
  89. template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
  90.  
  91. int dx[] = { 1,-1, 0, 0};                //graph moves
  92. int dy[] = { 0, 0, 1,-1};               //graph moves
  93.  
  94. struct PT{
  95.     int x, y;
  96.     void scan(){ scanf("%d %d",&x,&y);}
  97. };
  98.  
  99.  
  100. double SQ(double x){ return x*x;}
  101.  
  102. double Dis(PT a,PT b){ return SQ(a.x - b.x) + SQ(a.y - b.y);}
  103.  
  104. double absDis(PT a,PT b){ return sqrt(Dis(a,b));}
  105.  
  106. /*two vector lines Dot product*/
  107. int Dot(PT a,PT b){ return a.x*b.x + a.y*b.y;}
  108.  
  109. /*two vector lines Cross product*/
  110. int Cross(PT a,PT b){ return a.x*b.y - b.x*a.y;}
  111.  
  112. /*convert degree to radian*/
  113. double toRadian(double x){ return (x*(PI/180.0));}
  114.  
  115. /*convert radian to degree*/
  116. double toDegree(double x){ return (x*(180.0/PI));}
  117.  
  118. /*two point's vector line*/
  119. PT vect(PT a,PT b){ return {a.x-b.x, a.y-b.y};}
  120.  
  121. /*convert a coordinate p from cartesian to polar
  122. r = sqrt(x*x + y*y)
  123. theta = atan(y/x) [in radian]*/
  124. // PT toPolar(PT p){
  125. //     return {sqrt(SQ(p.x)+SQ(p.y)), atan(p.y/p.x)};
  126. // }
  127.  
  128. /*convert a coordinate p from polar to cartesian
  129. theta must be radian
  130. x = r * cos(theta)
  131. y = r * sin(theta)*/
  132. // PT toCartesian(PT a){
  133. //     return {a.x * cos(a.y), a.x * sin(a.y)};
  134. // }
  135.  
  136. /*divide line ab into m:n and return midpoint*/
  137. /*For 3D add the z part same as x and y*/
  138. // PT divideLine(PT a, PT b, double m, double n){
  139. //     return {(a.x * m + b.x * n)/(m+n),
  140. //         (a.y * m + b.y * n)/(m+n)};
  141. // }
  142.  
  143. /*line ab to point c
  144. 0 => if ab and c coliner
  145. + => clockwise
  146. - => anticlockwise
  147. */
  148. int orientation(PT a, PT b, PT c)
  149. {
  150.     int val = (b.y-a.y)*(c.x-b.x)-(b.x-a.x)*(c.y-b.y);
  151.     if(val > 0) return 1;
  152.     else if(val < 0) return -1;
  153.     return val;
  154. }
  155.  
  156. struct Line
  157. {
  158.     PT A, B;
  159.     void scan(){
  160.         A.scan();
  161.         B.scan();
  162.     }
  163.     bool isIntersect(Line L){
  164.         if(orientation(A, B, L.A) == orientation(A, B, L.B)) return false;
  165.         if(orientation(L.A, L.B, A) == orientation(L.A, L.B, B)) return false;
  166.         return true;
  167.     }
  168. };
  169.  
  170. struct Rectangle
  171. {
  172.     int fig;
  173.     PT A, B, C, D;
  174.     void scan(int _fig){
  175.         A.scan();
  176.         C.scan();
  177.         B = {C.x, A.y};
  178.         D = {A.x, C.y};
  179.         fig = _fig;
  180.     }
  181.     bool inside(PT P){
  182.         int val1 = orientation(A, B, P);
  183.         int val2 = orientation(B, C, P);
  184.         int val3 = orientation(C, D, P);
  185.         int val4 = orientation(D, A, P);
  186.         if(val1 == val2 && val2 == val3 && val3 == val4) return true;
  187.         return false;
  188.     }
  189. };
  190.  
  191. struct Circle
  192. {
  193.     int fig;
  194.     PT A;
  195.     double r;
  196.     void scan(int _fig){
  197.         A.scan();
  198.         scanf("%lf", &r);
  199.         fig = _fig;
  200.     }
  201.     bool inside(PT P){
  202.         double dis = absDis(A, P);
  203.         if(dis + eps < r) return true;
  204.         return false;
  205.     }
  206. };
  207.  
  208. struct Triangle
  209. {
  210.     int fig;
  211.     PT A, B, C;
  212.     void scan(int _fig){
  213.         A.scan();
  214.         B.scan();
  215.         C.scan();
  216.         fig = _fig;
  217.     }
  218.     bool inside(PT P){
  219.         int val1 = orientation(A, B, P);
  220.         int val2 = orientation(B, C, P);
  221.         int val3 = orientation(C, A, P);
  222.         if(val1 == val2 && val2 == val3) return true;
  223.         return false;
  224.     }
  225. };
  226.  
  227. /*line ab and line cd is parrallel if ab X cd = 0 */
  228. bool ifParallel(PT a,PT b,PT c,PT d)
  229. {
  230.     if(Cross(vect(a,b),vect(c,d)) != 0) // for double abs(val) > eps
  231.         return false;
  232.     return true;
  233. }
  234.  
  235. /*line ab and line cd is perpendicular if ab . cd = 0 */
  236. bool ifPerpendicular(PT a,PT b,PT c,PT d)
  237. {
  238.     if(Dot(vect(a,b),vect(c,d)) != 0) // for double abs(val) > eps
  239.         return false;
  240.     return true;
  241. }
  242.  
  243. /*Area*/
  244.  
  245. double heronTriangle(double a, double b, double c){
  246.     double s = (a + b + c) / 2.0;
  247.     if(s - a < 0) return -1;
  248.     if(s - b < 0) return -1;
  249.     if(s - c < 0) return -1;
  250.     return sqrt(s * (s - a) * (s - b) * (s - c));
  251. }
  252.  
  253. double mdedianTriangle(double a, double b, double c){
  254.     double s = (a + b + c) / 2.0;
  255.     if(s - a < 0) return -1;
  256.     if(s - b < 0) return -1;
  257.     if(s - c < 0) return -1;
  258.     return (4.0 / 3.0 ) * sqrt(s * (s - a) * (s - b) * (s - c));
  259. }
  260.  
  261. double trapeziumArea(double a, double b, double h){
  262.     return (a + b) * h / 2.0;
  263. }
  264.  
  265. ///Area of irregular polygon
  266. double AreaOfPolygon(int n,PT a[])
  267. {
  268.     double area = 0.0;
  269.     for(int i=1;i<n;i++){
  270.         area+=(a[i-1].x*a[i].y-a[i].x*a[i-1].y);
  271.     }
  272.     area+=(a[n-1].x*a[0].y-a[0].x*a[n-1].y);
  273.     return area/2.0;
  274. }
  275.  
  276. /*volumn*/
  277.  
  278. double coneVolume(double r, double h){
  279.     return PI * r * r * h / 3.0;
  280. }
  281.  
  282. double CircumcircleR(double a, double b, double c){
  283.     if(a + b + c < eps) return 0;
  284.     return (a * b * c) / sqrt((a + b + c) * (b + c - a) * (c + a - b) * (a + b - c));
  285. }
  286.  
  287. double IncircleR(double a, double b, double c){
  288.     if(a + b + c < eps) return 0;
  289.     return 2.0 * heronTriangle(a, b, c) / (a + b + c);
  290. }
  291.  
  292. bool insideRectangle(PT p, PT a, PT c){
  293.     if(p.x < a.x or p.x > c.x) return false;
  294.     if(p.y < a.y or p.y > c.y) return false;
  295.     return true;
  296. }
  297.  
  298. /*checking shapes*/
  299.  
  300. bool isSquare(PT *a){
  301.     if(abs(Dis(a[0], a[1]) - Dis(a[1], a[2])) > eps
  302.         or abs(Dis(a[1], a[2]) - Dis(a[2], a[3])) > eps
  303.         or abs(Dis(a[2], a[3]) - Dis(a[3], a[0])) > eps)
  304.         return false;
  305.     if(!ifPerpendicular(a[0], a[1], a[1], a[2])) return false;
  306.     return true;
  307. }
  308.  
  309. bool isRectangle(PT *a){
  310.     if(abs(Dis(a[0], a[1]) - Dis(a[3], a[2])) > eps
  311.         or abs(Dis(a[1], a[2]) - Dis(a[0], a[3])) > eps)
  312.         return false;
  313.     if(!ifPerpendicular(a[0], a[1], a[1], a[2])) return false;
  314.     return true;
  315. }
  316.  
  317. bool isRombus(PT *a){
  318.     if(abs(Dis(a[0], a[1]) - Dis(a[1], a[2])) > eps
  319.         or abs(Dis(a[1], a[2]) - Dis(a[2], a[3])) > eps
  320.         or abs(Dis(a[2], a[3]) - Dis(a[3], a[0])) > eps)
  321.         return false;
  322.     return true;
  323. }
  324.  
  325. bool isParallelogram(PT *a){
  326.     if(abs(Dis(a[0], a[1]) - Dis(a[3], a[2])) > eps
  327.         or abs(Dis(a[1], a[2]) - Dis(a[0], a[3])) > eps)
  328.         return false;
  329.     return true;
  330. }
  331.  
  332. bool isTrapezium(PT *a){
  333.     if(!ifParallel(a[0], a[1], a[3], a[2])
  334.         and !ifParallel(a[1], a[2], a[0], a[3])) return false;
  335.     return true;
  336. }
  337.  
  338.  
  339. PT f; //init first coordinate
  340. //for clockwise sorting
  341. bool ClockCmp(PT &a,PT &b){ return (f.x-a.x)*(f.y-b.y)<(f.x-b.x)*(f.y-a.y);}
  342.  
  343. //for anti-clockwise sorting
  344. bool AClockCmp(PT &a,PT &b){ return (f.x-a.x)*(f.y-b.y)>(f.x-b.x)*(f.y-a.y);}
  345.  
  346. vector< ll > vv;
  347.  
  348. int main()
  349. {
  350.     #ifndef ONLINE_JUDGE
  351.         clock_t tStart = clock();
  352.         freopen("input.txt", "r", stdin);
  353.         freopen("output.txt", "w", stdout);
  354.     #endif
  355.  
  356.     int t, ca=0; sc1(t);
  357.  
  358.     while(t--){
  359.         if(ca) line;
  360.         ca++;
  361.         int n; sc1(n);
  362.         Line a[n];
  363.         FOR(i, 0, n) a[i].scan();
  364.         int ans = 0;
  365.         for(int i=0; i<n; i++){
  366.             int cnt = 1;
  367.             for(int j=0; j<n; j++){
  368.                 if(a[i].isIntersect(a[j])) cnt++;
  369.             }
  370.             ans += cnt;
  371.         }
  372.         pf1(ans); line;
  373.     }
  374.  
  375.     #ifndef ONLINE_JUDGE
  376.         fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  377.     #endif
  378.  
  379.     return 0;
  380. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement