C++ 中的名称冲突之 "y1"
2016-05-23 01:16
816 查看
已经是第二次遇到这个问题了:
#include <bits/stdc++.h> using namespace std; const int N(105); int dp [2] [2] ; int x1, x2, y1, y2; int dfs(int x1, int s, int x2, int t, int y){ int & now=dp[x1][s][x2][t][y]; if(~now) return now; int sum=0, cnt=0; if(s==0){ sum+=dfs(x1, 1, x2, t, y-1), cnt++; if(t==0) sum+=dfs(x1, s, x2, 1, y-1), cnt++; else if(x2>0) sum+=dfs(x1, 0, x2-1, t, y), cnt++; } else{ if(x1>0) sum+=dfs(x1-1, s, x2, t, y), cnt++; if(t==0) sum+=dfs(x1, s, x2, 1, y-1), cnt++; else if(x2>0) sum+=dfs(x1, s, x2-1, t, y), cnt++; } if((y1+1)*(1-s)+(y2+1)*(1-t)< y) //forbidden numbers; sum+=dfs(x1, s, x2, t, y-1), cnt++; return now = sum!=cnt; } int a ; int main(){ int T; int n; for(cin>>T; T--; ){ cin>>n; int p; for(int i=0; i<n; i++){ cin>>a[i]; if(a[i]==1) p=i; } x1=0, x2=0, y1=0, y2=0; int i; for(i=p-1; i>=0 && a[i]>a[i+1]; i--, x1++); for(; i>=0 && a[i]<a[i+1]; i--, y1++); for(i=p+1; i<n && a[i]>a[i-1]; i++, x2++); for(; i<n && a[i]<a[i-1]; i++, y2++); memset(dp, -1, sizeof(dp)); x1=max(x1-1, 0), x2=max(x2-1, 0); // cout<<x1<<' '<<x2<<' '<<y1<<' '<<y2<<endl; int peak=(p!=0) + (p!=n-1); for(int i=0; i<=n-1-x1-x2-peak; i++) dp[0][1][0][1][i]=1; //error-prone int s=p==0, t=p==n-1; //error-prone int res=dfs(x1, s, x2, t, n-1-x1-x2); // cout<<res<<endl; puts(res==1?"Alice": "Bob"); } return 0; }
试图在终端编译,运行: (gcc version 4.8.4)
g++ main.cpp -std=c++11 -o main && ./main <in
返回结果:
main.cpp:8:13: error: ‘int y1’ redeclared as different kind of symbol int x1, x2, y1, y2; ^ In file included from /usr/include/features.h:374:0, from /usr/include/assert.h:35, from /usr/include/c++/4.8/cassert:43, from /usr/include/x86_64-linux-gnu/c++/4.8/bits/stdc++.h:33, from main.cpp:1: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:241:1: error: previous declaration of ‘double y1(double)’ __MATHCALL (y1,, (_Mdouble_)); ^
显示变量y1 和C++标准库中的某个变量名称冲突,这个问题应当引起注意。
另外这不是头文件写成<bits/stdc++.h>引起的,即使换成各具体的头文件(<iostream>, <algorithm>, <ctring>)还是会返回这个错误。
具体原因及解决办法还有待研究。
相关文章推荐
- C语言:线索二叉树的线索化及其遍历实现
- leetcode_c++:First Missing Positive(041)
- [C++]关于重载运算符的一些建议
- leetcode_c++:Combination Sum_2(040)
- C++第六次上机实验其他作业
- C++ Primer 阅读记录之继承类的构造函数
- OJ题目-使用+-|等符号表示数字,进行运算【C语言】
- leetcode_c++:Combination Sum(039)
- 用C语言实现循环链表
- C++第六次作业
- c++ 基础知识整理(二)
- c++ primer(第五版)学习笔记及习题答案代码版(第十章)泛型算法
- 请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配
- c语言学习笔记13之二维数组1
- c++第6次作业
- GeekBand C++第二周学习感悟
- C/C++中一些不太注意到的小知识点--[锦集]
- c++-作业6
- B00008 C++实现的大整数计算(一)
- 作业:C++作业6