我告诉你A+B是这样做的

P1001 A+B Problem

题解里面的才是真牛逼,比这厉害多了
by Ebola @ 2018-01-03 16:22:54


@[arfa](/space/show?uid=77760) 其实rand有一个稳妥算法能保证AC的,附上AC代码原理自己理解吧 ```cpp #include <bits/stdc++.h> using namespace std; #define ll long long ll a, b, res; int main() { srand(time(0)+817); cin >>a >> b; while(1) { if(res==a+b) break; else if(a + b <=0 && res > a + b) res-=rand()%1000000; else if(a + b <= 0 && res < a + b) res+=rand()%1000000; else if(a + b >= 0 && res > a + b) res-=rand()%1000000; else if(a + b >= 0 && res < a + b) res+=rand()%1000000; } cout << res << endl; return 0; } ``` 当然如果你~~**运气太差**~~太欧了(因为这种概率非常之低)也可能出现因为rand转太久而TLE的情况
by 权御天下 @ 2018-01-07 15:50:09


这道题有 # 100 种算法
by Unknown_Error  @ 2018-02-13 21:45:34


UKE 楼下+考谷
by 精神小伙! @ 2022-04-05 21:04:13


|