Advertisement
radmickey

Untitled

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