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