Advertisement
radmickey

Untitled

Feb 7th, 2023
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 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, long long 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 / 1000000 * 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.         long long r=0;
  34.         string string_r;
  35.         cin >> w >> h >> n >> string_r;
  36.         for (auto x : string_r){
  37.             if(is_digit_num(x)) {
  38.                 r += x - '0';
  39.                 r *= 10;
  40.             }
  41.         }
  42.  
  43.  
  44.         long long left = 0;
  45.         long long right = n + 1;
  46.         while (right - left > 1) {
  47.             long long m = (left + right)/2;
  48.             long long result = check(n, w, h, r, m);
  49.             if (result == -1)
  50.                 left = m;
  51.             else if(result == 1)
  52.                 right = m;
  53.             else{
  54.                 right=m;
  55.                 break;
  56.             }
  57.         }
  58.  
  59.         long long count_strip = right;
  60.  
  61.         if(check(n, w, h, r, count_strip) == 0) {
  62.             long long minCountInRow = n / count_strip;
  63.             long long maxCountInRow = minCountInRow;
  64.             if (n % count_strip != 0)
  65.                 maxCountInRow += 1;
  66.             cout << count_strip << ' ' << minCountInRow << ' ' << maxCountInRow << '\n';
  67.         }
  68.         else{
  69.             cout<<-1<<endl;
  70.         }
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement