Advertisement
Um_nik

Untitled

Oct 27th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <vector>
  5. using namespace std;
  6. typedef long long ll;
  7. typedef pair<int, int> pii;
  8. #define mp make_pair
  9.  
  10. ll w, h;
  11. ll x, y;
  12. ll L;
  13. ll sq;
  14. int a[1000100];
  15. vector<pii> ans;
  16.  
  17. void print2()
  18. {
  19.     printf("%d\n", (int)ans.size());
  20.     for (int i = (int)ans.size() - 1; i >= 0; i--)
  21.         printf("%d %d\n", (int)w - ans[i].first, ans[i].second);
  22.     return;
  23. }
  24.  
  25. void solveEasy()
  26. {
  27.     ans.push_back(mp(1, 0));
  28.     ans.push_back(mp(1, (int)y));
  29.     ans.push_back(mp((int)(x + L), (int)y));
  30.     ans.push_back(mp((int)(x + L), (int)(y + L)));
  31.     ans.push_back(mp((int)x, (int)(y + L)));
  32.     ans.push_back(mp((int)x, (int)(y + 1 + sq / (x - 1) )));
  33.     ans.push_back(mp((int)1 + sq % (x - 1), (int)(y + 1 + sq / (x - 1) )));
  34.     if (sq % (x - 1) != 0)
  35.     {
  36.         ans.push_back(mp(1 + (int)(sq % (x - 1)), (int)(y + 1 + sq / (x - 1) + 1 )));
  37.         ans.push_back(mp(1, (int)(y + 1 + sq / (x - 1) + 1 )));
  38.     }
  39.     ans.push_back(mp(1, h));
  40.     print2();
  41.     return;
  42. }
  43.  
  44. void print()
  45. {
  46.     int tx = a[0];
  47.     ans.push_back(mp(tx, 0));
  48.     int it = 0;
  49.     while(it < h)
  50.     {
  51.         while (it < h && a[it] == tx) it++;
  52.         ans.push_back(mp(tx, it));
  53.         if (it == h) break;
  54.         tx = a[it];
  55.         ans.push_back(mp(tx, it));
  56.     }
  57.     print2();
  58.     return;
  59. }
  60.  
  61. int main()
  62. {
  63. //  freopen("input.txt", "r", stdin);
  64. //  freopen("output.txt", "w", stdout);
  65.  
  66.     cin >> w >> h;
  67.     cin >> x >> y >> L;
  68.     x = w - x - L;
  69.     sq = (w * h) / 2;
  70.     sq -= L * L + h;
  71.     sq -= x - 1LL;
  72.     if (sq < 0)
  73.     {
  74.         printf("Impossible\n");
  75.         return 0;
  76.     }
  77.     if (sq < (x - 1) * (L - 1))
  78.     {
  79.         solveEasy();
  80.         return 0;
  81.     }
  82.     sq -= (x - 1) * (L - 1);
  83.     for (int i = 0; i < h; i++)
  84.         if (i >= y && i < y + L)
  85.             a[i] = x + L;
  86.         else
  87.             a[i] = 1LL;
  88.     for (int i = 0; i < h; i++)
  89.     {
  90.         if (w - 1 - a[i] >= sq)
  91.         {
  92.             a[i] += sq;
  93.             sq = 0;
  94.             break;
  95.         }
  96.         sq -= w - 1 - a[i];
  97.         a[i] = w - 1;
  98.     }
  99.     print();
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement