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();
}
Luogu3579 Solar Panels的更多相关文章
- BZOJ3834[Poi2014]Solar Panels——分块
题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appea ...
- bzoj 3834 [Poi2014]Solar Panels 数论分块
3834: [Poi2014]Solar Panels Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 367 Solved: 285[Submit] ...
- 【bzoj3834】[Poi2014]Solar Panels 数论
题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appea ...
- 【BZOJ3834】[Poi2014]Solar Panels 分块好题
[BZOJ3834][Poi2014]Solar Panels Description Having decided to invest in renewable energy, Byteasar s ...
- 【BZOJ】3834: [Poi2014]Solar Panels
http://www.lydsy.com/JudgeOnline/problem.php?id=3834 题意:求$max\{(i,j)\}, smin<=i<=smax, wmin< ...
- BZOJ3834 : [Poi2014]Solar Panels
问题相当于找到一个最大的k满足在$[x_1,x_2]$,$[y_1,y_2]$中都有k的倍数 等价于$\frac{x_2}{k}>\frac{x_1-1}{k}$且$\frac{y_2}{k}& ...
- BZOJ3834 [Poi2014]Solar Panels 【数论】
题目链接 BZOJ3834 题解 容易想到对于\(gcd(x,y) = D\),\(d\)的倍数一定存在于两个区间中 换言之 \[\lfloor \frac{a - 1}{D} \rfloor < ...
- [POI2014]Solar Panels
题目大意: $T(T\le1000)$组询问,每次给出$A,B,C,D(A,B,C,D\le10^9)$,求满足$A\le x\le B,C\le y\le D$的最大的$\gcd(x,y)$. 思路 ...
- BZOJ3834:Solar Panels (分块)
题意 询问两个区间[smin,smax],[wmin,smax]中是否存在k的倍数,使得k最大 分析 将其转化成\([\frac{smin-1}k,\frac{smax}k],[\frac{wmin- ...
随机推荐
- How does the compilation and linking process work?
The compilation of a C++ program involves three steps: Preprocessing: the preprocessor takes a C++ s ...
- 通过SID查找历史执行的SQL语句
这次某系统发生严重的阻塞,但是去查顶级会话,发现已经没有该对应的sql_id了,于是我们只用通过 v$active_session_history 视图来寻找.下面是查找的过程: 1.查找顶层ASH历 ...
- LeetCode 112. Path Sum 二叉树的路径和 C++
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- zabbix自动发现华为,H3C交换机
一.添加自动发现规则 1.ip范围尽量别太大 zabbix是通过ARP来搜索符合条件的主机的 2.团体名和交换机要一样.这个OID值是提取系统信息的 在OID这块遇到个坑 我用Getif查询到的是1. ...
- idea的环境设置
IDEA的个人配置与常用操作 IDEA的个人配置 1.修改代码编辑器 新版的IDEA默认使用vim编辑器(linux下的一个工具),虽然熟练掌握后可以提高工作效率,但是学习成本很大,不习惯的可以选择关 ...
- DRF框架之 用户角色权限与访问频率的权限设置
1. 简单演示,创建一个models的数据库表 class User(models.Model): name=models.CharField(max_length=32) pwd=models.Ch ...
- C#控件——批量化隐藏或显示同类型控件
当一个页面中添加了许多同类型控件,当需要控制这些控件进行显示或隐藏的时候,需要一个个的将Visible属性设置为false,十分不方便, 后通过论坛受一位大神(至于叫什么忘了)的启发,通过建立控件数组 ...
- elasticsearch增删查改
创建结构化索引 put http://127.0.0.1:9200/person{ "settings" : { "number_of_shards": 3, ...
- 求1!+2!+3!+......+n!的和 -----C++-----
#include<iostream> using namespace std; int function(int x) { ; ;i<=x;i++) sum=sum*i; retur ...
- pandas操作行集锦
pandas移花接木 数据准备两表: 我们接下来要进行的操作: 增 将两表进行合并 # 把两张表合并,但是这样有问题,索引会重复的进行0-19 students = page_001.append(p ...