BZOJ5027: 数学题
2024-08-31 13:47:13
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 140 Solved: 48
[Submit][Status][Discuss]
Description
给出a,b,c,x1,x2,y1,y2,求满足ax+by+c=0,且x∈[x1,x2],y∈[y1,y2]的整数解有多少对?
Input
第一行包含7个整数,a,b,c,x1,x2,y1,y2,整数间用空格隔开。
a,b,c,x1,x2,y1,y2的绝对值不超过10^8。
Output
输出整数解有多少对?
Sample Input
1 1 -3 0 4 0 4
Sample Output
4
HINT
Source
一眼就能看出是扩欧
利用扩欧的通项公式求出上下边界进行处理
注意特殊情况的判断
注意这里
一定要先乘再除
mmp调了一晚上拍了n组数据都没拍出错误来。。
#include<iostream>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const LL MAXN=1e6+;
LL a,b,c,x1,x2,yy1,y2,x,y;
LL exgcd(LL a,LL b,LL &x,LL &y) {
if(b==){x=,y=;return a;}
LL r=exgcd(b,a%b,x,y),tmp;
tmp=x,x=y,y=tmp-a/b*y;
return r;
}
LL min(LL a,LL b){return a<b?a:b;}
LL max(LL a,LL b){return a>b?a:b;}
int main()
{
cin>>a>>b>>c>>x1>>x2>>yy1>>y2;c=-c;
if(a==&&b==) {
if(c==) {printf("%lld",(LL)(x2-x1+)*(y2-yy1+));return ;}
else {printf("");return ;}
}
if(a==){
if(c%b) {printf("");return ;}
if(c/b>=yy1&&c/b<=y2) {printf("%lld",x2-x1+);return ;}
else {printf("");return ;}
}
if(b==) {
if(c%a) {printf("");return ;}
if(c/a>=x1&&c/a<=x2) {printf("%lld",y2-yy1+);return ;}
else {printf("");return ;}
}
LL r=exgcd(a,b,x,y);
b=b/r;a=-a/r;//利用公式构造增量
if(c%r) {printf("");return ;}
x=x*c/r;y=y*c/r;
LL xlower,xupper,ylower,yupper;
if(b>) xlower=ceil( (double)(x1-x)/b ) , xupper=floor( (double)(x2-x)/b );
if(b<) xlower=ceil( (double)(x2-x)/b ) , xupper=floor( (double)(x1-x)/b );
if(a>) ylower=ceil( (double)(yy1-y)/a ) , yupper=floor( (double)(y2-y)/a );
if(a<) ylower=ceil( (double)(y2-y)/a ) , yupper=floor( (double)(yy1-y)/a );
LL ans=max(, min(xupper,yupper) - max(xlower,ylower) + );
printf("%lld",ans); return ;
} //1 5 -3 -123 40 -567 41
最新文章
- ajax 异步加载显示等待效果
- QQ左侧滑动显示
- Android-->;Genymotion虚拟机(模拟器)的配置
- python 类中staticmethod,classmethod,普通方法
- ecshop缓存清理-限制或禁用ECShop缓存
- new总结
- (转)resize扩展
- Namespace declaration statement has to be the very first
- auto 和 decltype (C++11 新增)
- iOS设计模式——MVC(Model-View-Controller)
- OkHttp基本使用
- doT.js——前端javascript模板引擎问题备忘录
- MySQL ProxySQL相关维护说明
- Eclipse拷贝动态的web工程修改context root的值
- 秒懂HTTPS
- nginx下后端节点realserverweb健康检测模块ngx_http_upstream_check_module
- [HNOI2009]最小圈 (二分答案+负环)
- day_10 py 字典
- o(1), o(n), o(logn), o(nlogn)算法复杂度
- Linux查看文件安装路径与文件所在路径