Luogu3579 solar panels

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.