爆数据了!a[20]

P1010 [NOIP1998 普及组] 幂次方

您所说的`爆数据`是指以下的哪个? - `int`类型溢出 - 数组越界 - ~~超过内存限制~~
by HarunluoON @ 2022-01-20 11:00:59


RE
by lijunye_1 @ 2022-01-20 11:20:46


你应该是“while(n)”哪里错了吧,因为n是**int**类型数据,而while语句是按位运算的,n是32位数据,所以造成了死循环。 编译结果:2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2(2( 建议你老老实实用“(n==1)”吧。
by gao0202 @ 2022-04-08 20:46:28


完整递归代码: ```cpp int doit(int n){ while(n){ if(n&1){ a[q]=1; } q++; n>>=1; } q--; for(int i=q;i>=0;i--){ if(a[i]==1){ if(i!=q){ cout<<"+"; } cout<<"2"; if(i!=1){ cout<<"("; if(i==0){ cout<<"0"; }else if(i==2){ cout<<"2"; }else{ doit(i); } cout<<")"; } } } } ```
by gao0202 @ 2022-04-08 20:50:32


|