社区讨论
关于全局变量与局部变量
P10501Cutting Game参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lz97wn2o
- 此快照首次捕获于
- 2024/07/31 10:18 2 年前
- 此快照最后确认于
- 2024/07/31 11:26 2 年前
RT,请问为什么提交代码是如下的时候
CPP#include <bits/stdc++.h>
using namespace std;
int sg[206][206];
int n,m;
int SG(int u, int v) {
bool vis[206];
memset(vis,0,sizeof(vis));
if (sg[u][v]!=0x3f3f3f3f) return sg[u][v];
for (int i=2;i<=u-i;i++) {
vis[SG(i,v)^SG(u-i,v)]=1;
}
for (int i=2;i<=v-i;i++) {
vis[SG(u,i)^SG(u,v-i)]=1;
}
int now=0;
while(vis[now]) ++now;
return sg[u][v]=now;
}
int main(){
memset(sg,0x3f,sizeof(sg));
sg[2][3]=sg[2][2]=sg[3][2]=0;
while(cin >> n >> m) {
cout << (SG(n,m)?"WIN\n":"LOSE\n");
}
return 0;
}
可以通过
而把vis数组改为全局变量时,(如下)
CPP#include <bits/stdc++.h>
using namespace std;
int sg[206][206];
int n,m;
bool vis[206];
int SG(int u, int v) {
memset(vis,0,sizeof(vis));
if (sg[u][v]!=0x3f3f3f3f) return sg[u][v];
for (int i=2;i<=u-i;i++) {
vis[SG(i,v)^SG(u-i,v)]=1;
}
for (int i=2;i<=v-i;i++) {
vis[SG(u,i)^SG(u,v-i)]=1;
}
int now=0;
while(vis[now]) ++now;
return sg[u][v]=now;
}
int main(){
memset(sg,0x3f,sizeof(sg));
sg[2][3]=sg[2][2]=sg[3][2]=0;
while(cin >> n >> m) {
cout << (SG(n,m)?"WIN\n":"LOSE\n");
}
return 0;
}
则WA 70pts
回复
共 3 条回复,欢迎继续交流。
正在加载回复...