Advertisement
Guest User

NCPC2012 Galactic

a guest
Aug 27th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <bitset>
  7. #include <iostream>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <string>
  13. #include <algorithm>
  14. #include <functional>
  15. using namespace std;
  16.  
  17. struct E {
  18.     int a, b, c;
  19.     E(int A, int B, int C) : a(A), b(B), c(C) {}
  20. };
  21.  
  22. long long int gcd(long long int a, long long int b) {
  23.     return b ? gcd(b, a % b) : a;
  24. }
  25.  
  26. struct lineEq {
  27.    
  28.     long long int a, b, c;
  29.  
  30.     lineEq(int x, int y, int x0, int y0) {
  31.         b = -(x0 - x);
  32.         a = (y0 - y);
  33.         c = -a*x + -b*y;
  34.         int g = gcd(a, b); g = gcd(g, c);
  35.         a/= g;
  36.         b/= g;
  37.         c/= g;
  38.         if (a < 0) {
  39.             a = -a; b = -b; c = -c;
  40.         }
  41.     }
  42.  
  43.     bool operator==(const lineEq & l) const {
  44.         return a == l.a && b == l.b && c == l.c;
  45.     }
  46.  
  47.     bool parallel(const lineEq & l) {
  48.         return (a * l.b == l.a * b);
  49.     }
  50.  
  51. };
  52.  
  53. vector<lineEq> vl;
  54. int w, n, ax, ay, bx, by, r = 0;
  55.  
  56. int main() {
  57.     //freopen("input.txt", "r", stdin);
  58.     //freopen("output.txt", "w", stdout);
  59.    
  60.     scanf("%d%d", &w, &n);
  61.     bool allParallel = 1;
  62.     for (int i = 0; i < n; i++) {
  63.         scanf("%d%d%d%d", &ax, &ay, &bx, &by);
  64.         lineEq l = lineEq(ax, ay, bx, by);
  65.         bool f = 1;
  66.         for (int j = 0; j < vl.size(); j++) {
  67.             if (vl[j] == l) {
  68.                 f = 0;
  69.                 break;
  70.             }
  71.         }
  72.         if (f) {
  73.             vl.push_back(l);           
  74.             allParallel &= (vl.size() == 1) || (vl[vl.size() - 2].parallel(l));
  75.         }
  76.     }
  77.  
  78.     n = vl.size();
  79.     w -= (allParallel && n > 1) ? n + 1 : (n << 1);
  80.     if (w <= 0) {
  81.         printf("0"); return 0;
  82.     }
  83.  
  84.     int ans = 0;
  85.     if (allParallel) {
  86.         w -= (n + 1);
  87.         if (w <= 0) {
  88.             printf("1"); return 0;
  89.         }
  90.         ans = 1;
  91.     }
  92.  
  93.     printf("%d", ans + (w/2) + (w % 2) );
  94.    
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement