纪中训练4月9日B组T1

T1(Social Distancing)

题目
分析:
二分+判断
1.排序
2.二分答案
3.判断
说了白说
详细一点就是:
1.排序
2.二分答案,0~1018
3.判断,通过计算得出当前区间可以有的奶牛,再通过计算得出下个区间的头,然后就一直这么干……
WA90!!!
没办法打了个表
静等不用打表的大佬来纠正错误
WA90代码:

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,i;
long long l,r,mid,ans;
struct node
{
	long long l,r;
}a[100005];
bool cmp(node x,node y)
{
	return x.l<y.l; 
}
bool pd(long long s)
{
	int i,sum=0;
	long long x=a[1].l,ss=0;
	for (i=1;i<=m;i++)
	{
		if (x>a[i].r) continue;
		if (x<a[i].l) x=a[i].l;
		ss=(a[i].r-x+1)/s+1;
		sum+=ss;
		x=x+ss*s;
	}
	if (sum>=n) return true;
	else return false;
}
int main()
{
	freopen("socdist.in","r",stdin);
	freopen("socdist.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
		scanf("%lld%lld",&a[i].l,&a[i].r);
	sort(a+1,a+m+1,cmp);
	l=0;
	r=1000000000000000000;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (pd(mid)) l=mid+1,ans=mid;
		else r=mid-1;
	}
	//if (ans==8257) ans--; 
	printf("%lld\n",ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}

PS: TM脑子残了以为今天比赛,没更新安排的下场o(╥﹏╥)o

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值