为什么mt19937过不了,rand可以?

P1337 [JSOI2004] 平衡点 / 吊打XXX

运气问题。
by a2lyaXNhbWUgbWFyaXNh @ 2023-01-28 17:24:04


@[五个下划线](/user/661595) 现在才看到,我用mt19937与答案差距在0.5甚至10以上,不是运气问题。
by chenguoyi @ 2023-01-28 18:21:58


@[五个下划线](/user/661595) 而且我是复制题解,只改了生成数生成方式,实现也没问题
by chenguoyi @ 2023-01-28 18:24:02


随机数需要有正有负 题解中把 `rand()` 变有正有负的方式是 ```c++ RAND_MAX - 2*rand() ``` 而 `std::mt19937` 生成的是一个 `unsigned int` 范围的随机数,因此可以 ```c++ #include <climits> ``` 之后用 ```c++ std::mt19937 rd; INT_MAX - rd(); ``` 来实现正负随机
by Tibrella @ 2023-02-23 21:05:37


所以 `mt19937` 取模不香吗,模小一点随便过……
by Tnuzy_plzro @ 2023-03-20 11:40:35


@[Tibrella](/user/655192) 抱歉现在才看到,但是根据您的换了也还是11pts,感觉就这道题而言用rand卡mt19937真的是玄学。。。
by chenguoyi @ 2023-03-20 14:53:38


@[chenguoyi](/user/921117) 我用 `std::mt19937` 过的
by Tibrella @ 2023-03-20 20:49:56


@[Tibrella](/user/655192) 大佬,可不可以顺便看一下我改了成mt的: 改成mt确实过了,但是1ll*与(long long)两种写法分不同??(就是代码注释的上一行) 11pts: https://www.luogu.com.cn/record/105356358 100pts: https://www.luogu.com.cn/record/105356318
by chenguoyi @ 2023-03-20 21:45:44


@[chenguoyi](/user/921117) 突然发现我忘在上面写 `long long` 了( 我用的是 ```cpp ex = ((long long)INT_MAX - (long long)rd()) * temp + ansx; ey = ((long long)INT_MAX - (long long)rd()) * temp + ansy; ``` 感觉你第一个提交可能编译器把 `*1ll` 优化掉了,我不太懂(
by Tibrella @ 2023-03-20 22:04:45


|