Advertisement
radmickey

Untitled

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