Rain888_ @ 2024-07-14 19:15:30
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll k, cnt = 0, n;
cin >> k;
for (int i = 1; i <= k; i ++) {
for (int j = 1; j <= i; j ++) {
cnt ++;
n += i;
if (cnt == k) {
cout << n;
return 0;
}
}
}
return 0;
}
本蒟蒻发现:如果开启O2优化,那全WA,而关上却全AC,所以啥情况?
by lzj666_luogu @ 2024-07-14 19:17:55
正常,代码厌氧。
by lzj666_luogu @ 2024-07-14 19:19:41
@Rain888_ 不对啊,你 n
的初始值呢?不设初值应放在 main()
外定义啊。
by Rain888_ @ 2024-07-14 19:30:34
@lzj666_luogu 啊?我没在意,咋还AC了??
by xudongyi1 @ 2024-07-14 19:33:50
有UB
by xudongyi1 @ 2024-07-14 19:34:27
好像开O2程序会更苛刻一点
by Rain888_ @ 2024-08-05 18:22:02
是这样啊