P8948 [YsOI2022]NOIp和省选

· · 个人记录

先给大家看一段代码

#include <IOI/Burst_zero.h>

// using brain;
// using eye;
using body::foot;
using computer::keyboard;
using body::mouth;

int main() {
    string t1;
   mouth >> t1;
   think result = foot.think(&t1);
   while (result.err()) {
    result.back(1);
   }
   keytype key = think.res();
   key.run();
   return 114514;
}
< CWorld -Wall YsOI2022.cwd
> YsOI2022.cwd: In function 'int main()':
> YsOI2022.cwd:13:24: error: loop judgment always true
>    13 |   while (result.err()) {
>       |                      ^

你一定会遇到的误区

对 c_ {i} =1000( \frac {ai}{A} + \frac {bi}{B} ) 来说,你可能对它一通改造得到:

A\times b+a\times B= \frac {c\times A\times B}{1000}

什么的之类的东西。 然后得出通过判断 A\times b 与 a\times B 的大小隔开,就可得到正解……个\texttt P

打表毒瘤题

观察答案,想一想就可以知道我们完全可以用一组 A、B 来解决所有问题。

证:对于每一组输入,由于仅要求可行解,而又只给出大致的大小关系。所以,若对于一组输入的可行 A、B 解,还有另外一组 A、B 也可行且对于其他的所有可能输入都可行(即 \forall i>1,c_i\in [10,1990] 都能有解),那么可以用这组 A、B 解答所有输入,而其中一组是 \texttt{A = 400, B = 600}。而对应所有的 a_{i}、b_{i} 若能解答一组问题中对应的 c_{i},那么,因为 A、B 不变,所以 c_ {i} =1000( \frac {ai}{A} + \frac {bi}{B} ) 不变。由此可得 a_{i}、b_{i} 可满足所有对应的常量 c_{i}。

就是搞出所有可能的值,然后 \texttt{cout << a[ai] << ' ' << b[bi] << endl;} 即可。

附打表程序(不完整版,需要填写核心)

int A = 600, B = 400;
    for (int i = 0; i <= 600; i++) {
        for (int j = 0; j <= 400; j++) {
            if(/* Here */)a[/* Here */] = /* Here */, 
                                      b[/* Here */] = /* Here */;
        }
    }
    for (int i = 1; i <= 2000; i++) {
        cout /* Here */;
    }

注:原来 CWorld -Wall YsOI2022.cwd 那块出了问题。 原来的:(就是那个 $)见问题区https://www.luogu.com.cn/discuss/559481

$ CWorld -Wall YsOI2022.cwd
> YsOI2022.cwd: In function 'int main()':
> YsOI2022.cwd:13:24: error: loop judgment always true
>    13 |   while (result.err()) {
>       |                      ^