Luogu3579 Solar Panels
整除分块枚举。。。
真的没有想到会这么简单。
要使一个数 \(p\) 满足 条件, 则 存在\(x, y\), \(a<=x \times p<=b\ \&\&\ c<=y \times p <=d\)
把\(p\) 除掉 则
\(\left\lceil\dfrac{a}{p}\right\rceil <=y <=\left\lfloor\dfrac{b}{p}\right\rfloor\)
\(\left\lceil\dfrac{c}{p}\right\rceil <=y <=\left\lfloor\dfrac{d}{p}\right\rfloor\)
把向上取整变为向下取整
\(\left\lfloor\dfrac{a+p-1}{p}\right\rfloor <= \left\lfloor\dfrac{b}{p}\right\rfloor\)
\(\left\lfloor\dfrac{b+p-1}{p}\right\rfloor <= \left\lfloor\dfrac{d}{p}\right\rfloor\)
然后就变成了 :
\(\left\lfloor\dfrac{a-1}{p}\right\rfloor < \left\lfloor\dfrac{b}{p}\right\rfloor\)
\(\left\lfloor\dfrac{b-1}{p}\right\rfloor < \left\lfloor\dfrac{d}{p}\right\rfloor\)
最后整除分块。 只需按照 \(b/p\)和\(d/p\) 相同时进行分类。 这样能使 \(b/p\) 和 \(d/p\)相等的同时 \(c/p\) 和 \(d/p\)尽量小, 更可能满足条件
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
#define R register
using namespace std;
inline int read() {
int X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c >= '0' && c <= '9'; c = getchar())
X = X * 10 + c - '0';
return X * p;
}
inline void cmax(int &A, int B) {
if (A < B) A = B;
}
inline int cmin(int A, int B) {
return A > B ? B : A;
}
void work() {
int ans = 1;
int a = rd - 1, b = rd, c = rd - 1, d = rd;
for (R int i = 1, j = 1, up = cmin(b, d); i <= up; i = j + 1) {
j = cmin(b / (b / i), d / (d / i));
if (b / j > a / j && d / j > c / j) cmax(ans, j);
}
printf("%d\n", ans);
}
int main()
{
int n = rd;
for (; n; --n) work();
}
最新文章
- Kanzi Q&;A
- git参考资料
- HDU 4349 Xiao Ming&#39;s Hope lucas定理
- python在window下的Nginx部署
- RabbitMQ系列二(构建消息队列)
- 解决sharepoint 2010 用户配置文件同步服务 正在启动
- mysqld --debug-sync
- 读书笔记 effective c++ Item 5 了解c++默认生成并调用的函数
- js如何获取地址栏的参数
- python爬虫爬取人人车(二手车)、利用padas、matplotlib生成图表,将信息打成csv格式
- maven 阿里云仓库配置
- 关于ajax的content-download时间过慢问题的解决方案与思考
- ad network
- patch 28729262
- 利用pyinstaller 打包Python文件
- Linux配置日志服务器
- cocos2d-x 清空缓存
- Qt选择文件对话框-中文路径-转std::string
- day2、购物商城
- ipad4没有声音提示消息
热门文章
- matlab-逻辑回归二分类(Logistic Regression)
- Jmeter5.1.1+python调用python脚本
- redis 模糊删除key
- redis 安装启动
- Head First Java.(第2版)
- ios 信任charles https 证书
- ReactiveX 学习笔记(28)使用 RxJS + React.js 进行 GUI 编程
- 关于Eclipse for Python
- VirtualBox安装Ubuntu16.04过程
- nginx stream module on mt7621(newifi3 d2) with openwrt 18.06.2