APIO2019
2024-09-03 08:11:34
device:
用最小公倍数的知识或是画网格模拟转移,神仙们也可以找规律。然后就变成区间覆盖了。
忘记特殊情况了,大众分→Ag
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long i64;
const int N=2e6+;
const i64 INF=1e18+; struct sgm{
i64 x,y;
bool operator<(const sgm a)const{
return x<a.x||x==a.x&&y<a.y;
}
}t[N];
int cnt; i64 gcd(i64 n,i64 m){
while(n%m){
swap(n,m);
m%=n;
}
return m;
} int main()
{
int n,i;
i64 a,b,x,y;
scanf("%d%lld%lld",&n,&a,&b);
i64 l;
if(a/gcd(a,b+)>=(double)INF/b)
l=INF;
else
l=a/gcd(a,b+)*b;
for(i=;i<=n;i++){
scanf("%lld%lld",&x,&y);
if(y-x+>=l){ //我怎么就这么睿智(
printf("%lld",l);
return ;
}
else{
x%=l,
y%=l;
if(x<=y){
++cnt,
t[cnt].x=x,
t[cnt].y=y;
}
else{
++cnt,
t[cnt].x=,
t[cnt].y=y;
++cnt,
t[cnt].x=x,
t[cnt].y=l-;
}
}
}
sort(t+,t+cnt+);
x=t[].x,
y=t[].y;
i64 s=;
for(i=;i<=cnt;i++)
if(t[i].x>y){
s+=y-x+;
x=t[i].x,
y=t[i].y;
}
else
y=max(y,t[i].y);
s+=y-x+;
printf("%lld",s);
return ;
}
bridges:
分块
lamps:
不会做咕咕咕
最新文章
- mysql数据备份
- centOS升级python3.5
- Javascript中构造函数与new命令2
- PHP获取图片宽度高度、大小尺寸、图片类型、用于布局的img属性
- Python学习笔记10
- 11039 - Building designing
- Spring.Net.FrameworkV3.0 版本发布了,感谢大家的支持
- web classpath 路径说明
- git命令常见问题总结
- 内存恶鬼drawRect
- BestCoder HDU 5750 Dertouzos
- 去除 waring Method &#39;CreateNew&#39; hides virtual method of base type &#39;TCustomForm&#39;
- python无私有成员变量
- iOS安全攻防
- WPF Canvas小例子
- c++内存管理错误记录
- MySQL之终端(Terminal)管理MySQL(转)
- python实现PKCS5Padding
- 当Azure里的虚拟机网卡被禁用
- 故障定位之查找附近点GeoHash研讨