Diamond_Chestplate @ 2023-11-02 21:16:06
80分,下载数据点答案是对的,自已交上去就是WA
by Diamond_Chestplate @ 2023-11-02 21:18:45
#include<bits/stdc++.h>
using namespace std;
short n,a[2000]={3},b[2000]={2};
int main(){
cin>>n;
if(n==0||n==1||n==2){
cout<<n;
return 0;
}
for(short i=3;i<=n;i++){
if(i%2==0){
for(short j=0;j<2000;j++){
a[j]+=b[j];
a[j+1]+=a[j]/10;
a[j]%=10;
}
}else{
for(short j=0;j<2000;j++){
b[j]+=a[j];
b[j+1]+=b[j]/10;
b[j]%=10;
}
}
}
short len=2000;
if(n%2==1){
while(a[len]==0) len--;
for(int i=len;i>=0;i--) cout<<a[i];
}else{
while(b[len]==0) len--;
for(int i=len;i>=0;i--) cout<<b[i];
}
return 0;
}
by xu222ux @ 2023-11-02 21:31:43
您把数组,开大点
by xu222ux @ 2023-11-02 21:32:53
@caixukunhhh 试试
by BGM114514 @ 2023-11-02 21:42:31
#include<bits/stdc++.h>
using namespace std;
short n,a[5005]={3},b[5005]={2};
int main(){
cin>>n;
if(n==0||n==1||n==2){
cout<<n;
return 0;
}
for(short i=3;i<=n;i++){
if(i%2==0){
for(short j=0;j<5005;j++){
a[j]+=b[j];
a[j+1]+=a[j]/10;
a[j]%=10;
}
}else{
for(short j=0;j<5005;j++){
b[j]+=a[j];
b[j+1]+=b[j]/10;
b[j]%=10;
}
}
}
short len=5005;
if(n%2==1){
while(a[len]==0) len--;
for(int i=len;i>=0;i--) cout<<a[i];
}else{
while(b[len]==0) len--;
for(int i=len;i>=0;i--) cout<<b[i];
}
return 0;
}
by BGM114514 @ 2023-11-02 21:43:40
如 @xu222ux 所说,在原有的代码基础上做了改动
by Diamond_Chestplate @ 2023-11-03 18:57:57
@BGM114514 谢谢大佬 @xu222ux 谢谢大佬
by Diamond_Chestplate @ 2023-11-03 19:03:33
@xu222ux 请问为什么把数组开大了就能A呢
实不相瞒我是个小学生
by Diamond_Chestplate @ 2023-11-03 19:04:26
关键是我自测能对,位数也没有超,这也太奇怪了吧
by BGM114514 @ 2023-11-03 19:27:35
确实
by SuperChao @ 2023-11-03 20:05:37
因为你开的数组大小是2000,但是索引下标是从0开始的,所以会越界,但是不是特别多的数组越界,所以只会跑到不知名的内存去而不会CE?