Advertisement
radmickey

Untitled

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