网线切割

对网线的数目二分答案,个数数找小了就网线变小,找大了就变大

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<cstdio>
using namespace std;
int n,k,a[19999];int l=1,r=0;
int check(int x){
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=a[i]/x;
}
return ans;
}
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
double x;
scanf("%lf",&x);
a[i]=x*100;
r=max(r,a[i]);
}
if(check(r)==k)
{printf("%.2lf",r/100.0);
return 0;
}
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid)>=k) l=mid+1;
else r=mid-1;
}
printf("%.2lf",(r)/100.0);

}

最近的文章

子串

这个题我搞了好久,终于算是明白了点吧看了很多大神的博客,总结出来了一些做法,不知对不对,就写一些吧。先定义两个数组sum[i][j][k]就是a串前i个字母,b串前j个字母的方案总数!!!!,就是结果f[i][j][k]是用第i个字母用的方案数。当匹配时:因为第i个可以和前i-1合并为一块(但这是方 …

于  dp 继续阅读
更早的文章

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in …

于 继续阅读