Advertisement
Guest User

D

a guest
Feb 15th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.05 KB | None | 0 0
  1. #pragma warning (disable : 4996)
  2. #pragma comment(linker, "/STACK:36777216")
  3.  
  4.  
  5.  
  6. #include <stdlib.h>
  7. #include <iostream>
  8. #include <vector>
  9. #include <string>
  10. #include <assert.h>
  11. #include <stack>
  12. #include <algorithm>
  13. #include <ios>
  14. #include <iostream>
  15. #include <fstream>
  16. #include <iomanip>
  17. #include <queue>
  18. #include <set>
  19. #include <functional>
  20. #include <cmath>
  21. #include <sstream>
  22. #include <map>
  23. #include <memory.h>
  24. #include <stdio.h>
  25. #include <cassert>
  26. #include <string.h>
  27. #include <deque>
  28.  
  29. #define forn(i , n) for (int i = 0; i < n; ++i)
  30. #define down(i, n) for (int i = n - 1; i >= 0; --i)
  31.  
  32.  
  33. using namespace std;
  34.  
  35. typedef unsigned long long int u64;
  36. typedef long long int i64;
  37. typedef vector<int> vint;
  38. typedef vector<i64> vi64;
  39. typedef pair<int, int> pint;
  40. typedef pair<i64, i64> pi64;
  41.  
  42. #define FILE_NAME "file"
  43. #define CONTEST "lines"
  44. #define M_PI 3.14159265358979323846
  45.  
  46. double sqr(double a)
  47. {
  48.     return a * a;
  49. }
  50.  
  51. const i64 inf = 100000000000000000LL;
  52.  
  53. #define MOD 1000000007
  54.  
  55.  
  56. struct Line
  57. {
  58.     i64 a, b, c;
  59.     i64 g;
  60.     set<int> nbr;
  61.     int used;
  62.     Line()
  63.     {
  64.         used = 0;
  65.     }
  66. };
  67.  
  68.  
  69. bool check(Line& a, Line & b)
  70. {
  71.     if (a.a == b.a && a.b == b.b)
  72.     {
  73.         return true;
  74.  
  75.     }
  76.  
  77.     if (a.b == 0 && a.c == 0 || b.b == 0 && b.c == 0)
  78.     {
  79.         return true;
  80.     }
  81.  
  82.    
  83.    
  84.     i64 y1 = -a.c*b.g*b.b;
  85.     i64 y2 = -b.c*a.g*a.b;
  86.     if (y1 == y2)
  87.     {
  88.         return true;
  89.     }
  90.     return false;
  91.  
  92.  
  93.  
  94. }
  95.  
  96.  
  97.  
  98. i64 nod(i64 a, i64 b)
  99. {
  100.     if (a == 0)
  101.     {
  102.         return b;
  103.  
  104.     }
  105.     if (b == 0)
  106.     {
  107.         return a;
  108.     }
  109.     return nod(b%a, a);
  110. }
  111.  
  112. int main()
  113. {
  114.     clock_t start = clock();
  115.     ios_base::sync_with_stdio(false);
  116.     cin.tie(NULL);
  117.     cout << fixed << setprecision(15);
  118.  
  119. #ifdef FILE_INPUT
  120.     freopen(FILE_NAME ".in", "r", stdin);
  121.     freopen(FILE_NAME ".out", "w", stdout);
  122. #else
  123.     freopen(CONTEST ".in", "r", stdin);
  124. #endif
  125.     int T;
  126.     cin >> T;
  127.     int n;
  128.     while (cin >> n)
  129.     {
  130.         vector<Line> arr(n);
  131.  
  132.  
  133.         forn(i, n)
  134.         {
  135.             cin >> arr[i].a >> arr[i].b >> arr[i].c;
  136.             int a = (arr[i].a);
  137.             int b = (arr[i].b);
  138.             int c = arr[i].c;
  139.  
  140.             int g = 1;
  141.            
  142.             arr[i].g = g= nod(a, b);
  143.             arr[i].a /= g;
  144.             arr[i].b /= g;
  145.  
  146.  
  147.             forn(j, i)
  148.             {
  149.                 if (check(arr[i], arr[j]))
  150.                 {
  151.                     arr[i].nbr.insert(j);
  152.                     arr[j].nbr.insert(i);
  153.                 }
  154.             }
  155.        
  156.         }
  157.         vint ans;
  158.         forn(i, n)
  159.         {
  160.             int best = 10000000;
  161.             int k = -1;
  162.             forn(j, n)
  163.             {
  164.                 if (arr[j].used)
  165.                     continue;
  166.                 if (arr[j].nbr.size() < best)
  167.                 {
  168.                     best = arr[j].nbr.size();
  169.                     k = j;
  170.                 }
  171.             }
  172.             if (k != -1)
  173.             {
  174.                 arr[k].used = 1;
  175.                 ans.push_back(k);
  176.                 vint good;
  177.                 for (auto j = arr[k].nbr.begin(); j != arr[k].nbr.end(); ++j)
  178.                 {
  179.                     int v = *j;
  180.                     good.push_back(v);
  181.                     arr[v].used = 1;
  182.                 }
  183.                 forn(j, n)
  184.                 {
  185.                     if (!arr[j].used)
  186.                     {
  187.                         forn(k, good.size())
  188.                         {
  189.                             if (arr[j].nbr.count(good[k]))
  190.                             {
  191.                                 arr[j].nbr.erase(good[k]);
  192.                             }
  193.                         }
  194.                     }
  195.                 }
  196.             }
  197.         }
  198.  
  199.  
  200.         cout << ans.size() << "\n";
  201.         forn(i, ans.size())
  202.         {
  203.             cout << ans[i] + 1 << "\n";
  204.         }
  205.        
  206.  
  207.  
  208.    
  209.  
  210.  
  211.  
  212.  
  213.     }
  214.  
  215.  
  216.  
  217.     return 0;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement