- 切割绳子
二分答案模板
- 2023-7-16 16:10:24 @
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 5e5 + 5;
int n, m, a[N];
bool check(int mid)
{
int cnt = 0;
for(int i = 1; i <= n; i++)
cnt +=(a[i] / mid);
return cnt >= m;
}
void handle()
{
int ans = 0;
int left = 1, right = 1E6;
while(left <= right)
{
int mid = (left + right) / 2;
if(check(mid))
{
ans = mid;
left = mid + 1;
}
else
right = mid - 1;
}
if(ans == 0) cout << "Failed" << endl;
else
cout << ans << endl;
}
void initInput()
{
ios::sync_with_stdio(0);
cin >> n ;
for(int i = 1; i <= n; i++) cin >> a[i];
cin >> m;
}
int main(void)
{
initInput();
handle();
return 0;
}
0 条评论
目前还没有评论...
信息
- ID
- 28
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 433
- 已通过
- 59
- 上传者