Advertisement
radmickey

Untitled

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