Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <utility>
  4.  
  5. using namespace std;
  6. int level(int n){
  7.     return floor((-1+sqrt(n))/2)+1;
  8. }
  9.  
  10. pair<int, int> coords(int n){
  11.     int l = level(n);
  12.     if (l == 0)
  13.         return pair<int,int>(0,0);
  14.    
  15.     int dots_on_previous_levels = 4*l*(l-1) + 1;
  16.     int cur = n - dots_on_previous_levels;
  17.     if (cur <= l)
  18.         return pair<int,int>(l,cur);
  19.     else {
  20.         cur -= l;
  21.         if (cur<=2*l)
  22.             return pair<int,int>(l-cur,l);
  23.         else{
  24.             cur -= 2*l;
  25.             if (cur<=2*l)
  26.                 return pair<int,int>(-l,l-cur);
  27.             else{
  28.                 cur-=2*l;
  29.                 if (cur<=2*l)
  30.                     return pair<int,int>(-l+cur,-l);
  31.                 else
  32.                     return pair<int,int>(l,-l+cur);
  33.             }
  34.         }
  35.     }
  36. }
  37.  
  38. int main(){
  39.     int a, b, n;
  40.     cin >> a >> b >> n;
  41.     pair<int, int> p1, p2, p3;
  42.     p1 = coords(a);
  43.     p2 = coords(b);
  44.     int x1,x2,y1,y2;
  45.     x1 = p1.first; y1 = p1.second;
  46.     x2 = p2.first; y2 = p2.second;
  47.     while (n != -1){
  48.         p3 = coords(n);
  49.         int x, y;
  50.         x = p3.first;
  51.         y = p3.second;
  52.         if (x*(y1-y2)+y*(x2-x1) == x2*y1-x1*y2)
  53.             cout << "1 ";
  54.         else
  55.             cout << "0 ";
  56.         cin >> n;
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement