太虛隱沒


私信TA

用户名:uq_41397082368

访问量:1416

签 名:

等  级
排  名 26249
经  验 528
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:二分


参考代码:

#include <stdio.h>
#include <algorithm>
using namespace std;
int h[100010];
int w[100010];
int a[100010];
int n,k;
int judge(int ans){
	int cnt=0;
	for(int i=0;i<n;i++){
		cnt+=(h[i]/ans)*(w[i]/ans);
	}
	return cnt>=k;
}
int main(){	
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d%d",&h[i],&w[i]);
	}
	int ans=1;
	int l=1;
	int r=100000;
	while(l<=r){
		int m=(l+r)/2;
		if(judge(m)){
			ans=max(m,ans);
			l=m+1;
		}
		else r=m-1;
	}
	printf("%d",ans);
	return 0;
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区