Advertisement
Dmaxiya

最优分组 参考代码

Mar 5th, 2025
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 1000 + 100;
  6. int n, ans;
  7. double p, mn;
  8.  
  9. int main() {
  10. #ifdef ExRoc
  11.     freopen("test.txt", "r", stdin);
  12. #endif // ExRoc
  13.     ios::sync_with_stdio(false);
  14.  
  15.     cin >> n >> p;
  16.     mn = n;
  17.     ans = 1;
  18.     for (int i = 2; i <= n; ++i) {
  19.         if (n % i == 0) {
  20.             double tmp = n / i + n * (1 - pow(1 - p, i));
  21.             if (tmp < mn) {
  22.                 ans = i;
  23.                 mn = tmp;
  24.             }
  25.         }
  26.     }
  27.     cout << ans << endl;
  28.  
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement