Tag: Math getch string integer STR \ n print = min
Partition enumeration...
I really didn't think it would be that simple.
To make a number \ (P \) meet the condition, \ (X, Y \) exists \), \ (A <= x \ times P <= B \\\\& \ c <= Y \ times P <= d \)
Remove \ (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 \)
Returns the rounded up value to the rounded down value.
\ (\ 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 \)
Then it becomes:
\ (\ 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 \)
Finally, the partition is divided. Only \ (B/P \) and \ (D/P \) are classified at the same time. In this way, we can make \ (B/P \) and \ (D/P \) equal at the same time \ (C/P \) and \ (D/P \) as small as possible, more likely to meet the conditions
#include<cstdio>#include<cstring>#include<algorithm>#define rd read()#define R registerusing 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