Advertisement
radmickey

Untitled

Feb 7th, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.     bool is_digit_num(char c) {
  6.         return (c>='0' && c<='9');
  7.     }
  8.  
  9. int check(int n, int w, int h, float r, int cnt_strip) {
  10.     float hOfRow = (float) h / (float) cnt_strip;
  11.     long long Counter1 = n / cnt_strip;
  12.     long long Counter2 = (n - 1) / cnt_strip + 1;
  13.  
  14.     float maxW = hOfRow * r;
  15.     float minW = hOfRow;
  16.  
  17.     if (minW * Counter1 > w || minW * Counter2 > w) {
  18.         return -1;
  19.     }
  20.     if (maxW * Counter1 < w || maxW * Counter2 < w) {
  21.         return 1;
  22.     }
  23.     return 0;
  24. }
  25.  
  26. int main() {
  27.     cin.tie(0);
  28.     cout.tie(0);
  29.     ios_base::sync_with_stdio(false);
  30.  
  31.     long long t;
  32.     cin >> t;
  33.  
  34.     while (t--) {
  35.         long long n, w, h;
  36.         float r=0;
  37.         cin >> n >> w >> h >> r;
  38.  
  39.         long long left = 0;
  40.         long long right = n + 1;
  41.         while (right - left > 1) {
  42.             long long m = (left + right)/2;
  43.             long long result = check(n, w, h, r, m);
  44.             if (result == -1)
  45.                 left = m;
  46.             else if(result == 1)
  47.                 right = m;
  48.             else{
  49.                 right=m;
  50.                 break;
  51.             }
  52.         }
  53.  
  54.         long long count_strip = right;
  55.  
  56.         if(check(n, w, h, r, count_strip) == 0) {
  57.             long long minCountInRow = n / count_strip;
  58.             long long maxCountInRow = minCountInRow;
  59.             if (n % count_strip != 0)
  60.                 maxCountInRow += 1;
  61.             cout << count_strip << ' ' << minCountInRow << ' ' << maxCountInRow << '\n';
  62.         }
  63.         else{
  64.             cout<<-1<<endl;
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement