版权声明:写得不好,随便转载,但请注明出处,感激不尽 https://blog.csdn.net/xyc1719/article/details/86657324
【简化题意】
n个搬桌子的路径在一条[1,200]坐标轴上,路径不重合的搬运可以同时进行,求最小搬运时间。n<=1e7
【分析】
相信各位大佬们都看出来了,这是一道显然的差分题。
求区间重叠的状况,数据范围又奇大无比,还不要求强制在线,实在是一道练差分的模板题。(如果n<=1e6,没准还有可能会想用树状数组,逃)
【code】
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,b,s[400];
char buf[1<<21],*p1=buf,*p2=buf;
inline char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline void read(int &x){
x=0;int fl=1;char tmp=getchar();
while(tmp<'0'||tmp>'9'){if(tmp=='-')fl=-fl;tmp=gc();}
while(tmp>='0'&&tmp<='9') x=(x<<1)+(x<<3)+tmp-'0',tmp=gc();
x=x*fl;
}
int main(){
freopen("move.in","r",stdin);
freopen("move.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
read(a),read(b),a=(a+1)>>1,b=(b+1)>>1;
if(a>b) swap(a,b);
s[a]++,s[b+1]--;
}
int ans=0;
for(int i=1;i<=200;i++){
s[i]=s[i-1]+s[i];
if(s[i]>ans) ans=s[i];
}
cout<<ans*10<<endl;
return 0;
}