Advertisement
rotti321

Untitled

Mar 14th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct raport{
  5.     int sus, jos;
  6.     raport(const int x, const int y){
  7.         if(x == 0 && y == 0)
  8.             sus = jos = 0;
  9.         else{
  10.             const int tmp = __gcd(x, y);
  11.             sus = x / tmp;
  12.             jos = y / tmp; } }
  13.     bool operator==(const raport& rhs)const{
  14.         return sus == rhs.sus && jos == rhs.jos; }
  15.     bool operator<(const raport& rhs)const{
  16.         return (long long)sus * rhs.jos <
  17.             (long long)jos * rhs.sus; } };
  18.  
  19. int nr_vizibile(vector<raport> v){
  20.     sort(begin(v), end(v), [](const raport& a, const raport& b){
  21.         return a.jos < b.jos; });
  22.     int rez = 1;
  23.     raport cur = v[0];
  24.     for(const auto r : v)
  25.         if(cur < r) cur = r, ++rez;
  26.     return rez; }
  27.  
  28. map<raport, vector<raport>> mp;
  29.  
  30. int p, n, m;
  31. ifstream f("ace.in");
  32. ofstream g("ace.out");
  33.  
  34. int main(){
  35.     f >> p >> n >> m;
  36.     for(int i = 0, h; i < n; ++i){
  37.         for(int j = 0; j < (i == n-1 ? m-1 : m); ++j){
  38.             f >> h;
  39.             const int dx = n-1-i, dy = m-1-j;
  40.             mp[raport(dx, dy)].push_back(
  41.                 raport(h*h, dx*dx + dy*dy)); } }
  42.     if(p == 1)
  43.         g << nr_vizibile(mp[raport(0, 1)]) +
  44.             nr_vizibile(mp[raport(1, 0)]) << endl;
  45.     else{
  46.         int rez = 0;
  47.         for(const auto x : mp)
  48.             rez += nr_vizibile(x.second);
  49.         g << rez << endl; }
  50.     return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement