rakcode1998

Untitled

Feb 12th, 2017
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <stack>
  4. #include <set>
  5. #include <list>
  6. #include <map>
  7. #include <deque>
  8. #include <cmath>
  9. #include <vector>
  10. #include <utility>
  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <algorithm>
  14. #include <functional>
  15. #include <sstream>
  16.  
  17. // short keywords
  18.  
  19. #define ipow(a,b) (int)pow(a,b)
  20. #define pb push_back
  21. #define mp make_pair
  22. #define mod 1000000007
  23.  
  24. // for loops
  25.  
  26. #define rep(i,n) for(int i=0;i<n;i++)
  27. #define reps(i,a,b) for(int i=a;i<=b;i++)
  28. #define rev(i,a,b) for(int i=a;i>=b;i--)
  29.  
  30. using namespace std;
  31.  
  32. // short keywords2
  33. typedef long long ll;
  34. typedef long double ld;
  35. typedef set<int>::iterator sit;
  36. typedef map<int,int>::iterator mit;
  37.  
  38. class Point
  39. {
  40. private:
  41.     int a;
  42.     int b;
  43. public :
  44.     Point(int a, int b)
  45.     {
  46.         this->a=a;
  47.         this->b=b;
  48.     }
  49.  
  50.     void setfirst(int a)
  51.     {
  52.         this->a=a;
  53.     }
  54.  
  55.     void setsecond(int b)
  56.     {
  57.         this->b=b;
  58.     }
  59.  
  60.     int getfirst()const
  61.     {
  62.         return a;
  63.     }
  64.  
  65.     int getsecond()const
  66.     {
  67.         return b;
  68.     }
  69. };
  70.  
  71. struct compare
  72. {
  73.     bool operator()(const Point& a,const Point& b)
  74.     {
  75.         if(a.getfirst()>b.getfirst())
  76.         {
  77.             return true;
  78.         }
  79.         else
  80.         {
  81.             if(a.getsecond()>b.getsecond())
  82.             {
  83.                 return true;
  84.             }
  85.             else
  86.             {
  87.                 return false;
  88.             }
  89.         }
  90.     }
  91. };
  92.  
  93. class Task
  94. {
  95. public:
  96.     const int mod2=1000000;
  97.     void solve(istream& in,ostream& out)
  98.     {
  99.         int t;
  100.         in>>t;
  101.  
  102.         map<Point,int,compare>store;
  103.         for(int i=0;i<11111;i++)
  104.         {
  105.             if(i%2==0)
  106.             {
  107.                 Point check(i,i);
  108.                 store.insert(mp(check,2*i));
  109.             }
  110.             else
  111.             {
  112.                 Point check(i,i);
  113.                 store.insert(mp(check,2*i-1));
  114.             }
  115.         }
  116.  
  117.         for(int i=2;i<11111;i++)
  118.         {
  119.             Point check(i,i-2);
  120.             if(i%2==0)
  121.             {
  122.                 store.insert(mp(check,2*i-2));
  123.             }
  124.             else
  125.             {
  126.                 store.insert(mp(check,2*i-3));
  127.             }
  128.         }
  129.  
  130.         for(auto h=store.begin();h!=store.end();h++)
  131.         {
  132.             out<<((*h).first).getfirst()<<" "<<((*h).first).getsecond()<<endl;
  133.         }
  134.  
  135.         rep(j,t)
  136.         {
  137.             int a,b;
  138.             in>>a>>b;
  139.             Point point(a,b);
  140.  
  141.             if(store.find(point)==store.end())
  142.             {
  143.                 out<<"No Number"<<endl;
  144.             }
  145.             else
  146.             {
  147.                 out<<(*store.find(point)).second<<endl;
  148.             }
  149.         }
  150.     }
  151.  
  152.     int gcd(int a,int b)
  153.     {
  154.         if(a==0)
  155.         {
  156.            return b;
  157.         }
  158.         else
  159.         {
  160.            return gcd(b%a,a);
  161.         }
  162.     }
  163. };
  164.  
  165.  
  166. int main()
  167. {
  168.     ios_base::sync_with_stdio(false);
  169.     cin.tie(NULL);
  170.     cout.tie(NULL);
  171.     Task solver;
  172.     std::istream& in(std::cin);
  173.     std::ostream& out(std::cout);
  174.     solver.solve(in,out);
  175.     out.flush();
  176.  
  177.     return 0;
  178. }
Add Comment
Please, Sign In to add comment