fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. typedef pair<ll,ll> ii;
  6. pair<ll,ll> slope(ll a, ll b){
  7. if(b==0)
  8. return {1,0};
  9. if(a==0)
  10. return {0,1};
  11. a = abs(a), b = abs(b);
  12. ll d = __gcd(abs(a),abs(b));
  13. return {a/d,b/d};
  14. }
  15.  
  16. pair<ll,ll> normaliza(ll a,ll b){
  17. if(a==0){
  18. return {0,1};
  19. }
  20. if(b<0){
  21. a = -a, b = -b;
  22. }
  23. ll d = __gcd(abs(a),abs(b));
  24. return {a/d,b/d};
  25. }
  26.  
  27. pair<ll,ll> inter(ll x1, ll y1, ll x2, ll y2){
  28. if(x2==x1)
  29. return {x1,1};
  30. if(y2==y1)
  31. return {y1,1};
  32. return normaliza(y1*(x2-x1)-x1*(y2-y1),(x2-x1));
  33. }
  34.  
  35. ll parse(string s){
  36. ll qtd = 0, answ = 0;
  37. bool inputLixo = false;
  38. for(auto c:s){
  39. if(c=='.'){
  40. qtd=0;
  41. inputLixo = true;
  42. }
  43. else{
  44. answ = answ*10 + (c-'0');
  45. qtd++;
  46. }
  47. }
  48. if(inputLixo==false)
  49. qtd = 0;
  50. while(qtd<2)
  51. answ = 10*answ, qtd++;
  52. return answ;
  53.  
  54. }
  55.  
  56. int main(){
  57. ll iter = 0;
  58. ll n;
  59. while(cin >> n && n){
  60. ll a, b, c, d;
  61. map<ii,map<ii,vector<ii>>> events;
  62. iter++;
  63. for(ll i=0;i<n;i++){
  64. string ra, rb, rc, rd;
  65. cin >> ra >> rb >> rc >> rd;
  66.  
  67. a = parse(ra), b = parse(rb), c = parse(rc), d = parse(rd);
  68.  
  69. auto anchor = inter(a,b,c,d);
  70. if(a!=c){
  71. if(a>c) swap(a,c);
  72. events[slope(d-b,c-a)][anchor].push_back({a,-1});
  73. events[slope(d-b,c-a)][anchor].push_back({c,1});
  74. }
  75. else{
  76. if(b>d) swap(b,d);
  77. events[slope(d-b,
  78. c-a)][anchor].push_back({b,-1});
  79. events[slope(d-b,c-a)][anchor].push_back({d,1});
  80. }
  81. }
  82.  
  83. ll answ = 0;
  84.  
  85.  
  86. for(auto v1:events){
  87. for(auto v2:v1.second){
  88. auto &arr = v2.second;
  89. sort(arr.begin(),arr.end());
  90. ll aberto = 0;
  91. for(auto p:arr){
  92. //cout << p.first << " " <<p.second <<", ";
  93. aberto -= p.second;
  94. answ += aberto==0;
  95. }
  96. //cout<<"\n";
  97. }
  98. }
  99. cout << answ <<"\n";
  100.  
  101. }
  102.  
  103. return 0;
  104. }
Success #stdin #stdout 0.01s 5508KB
stdin
Standard input is empty
stdout
Standard output is empty