last是linux关键字?

P4363 [九省联考 2018] 一双木棋 chess

```cpp #include<cstdio> #include<cctype> #include<cstring> #include<algorithm> using namespace std; inline int read(){ char c=getchar();int x=0,f=1; while(!isdigit(c)){ if(c=='-')f=-1; c=getchar(); } while(isdigit(c)){ x=(x<<3)+(x<<1)+(c^48); c=getchar(); } return x*f; } const int N=1e5; int dp[N],a[12][12],b[12][12],pow[12]; int n,m,tn,ans=0x3f3f3f3f,sum; int tmp[12]; inline void dfs(int cur,int step){ if(step==n*m){ if(sum<0)sum=-sum; ans=min(ans,sum); return; } int last=0x3f3f3f3f; if(cur){ for(int i=1;i<=n;i++){ if(tmp[i]==m)continue; if(tmp[i]>last){ break; } last=tmp[i]; tmp[i]+=1; sum-=b[i][tmp[i]]; dfs(0,step+1); sum+=b[i][tmp[i]]; tmp[i]-=1; if(tmp[i]==0)break; } }else { for(int i=1;i<=n;i++){ if(tmp[i]==m)continue; if(tmp[i]>last){ break; } last=tmp[i]; tmp[i]+=1; sum+=a[i][tmp[i]]; dfs(1,step+1); sum-=a[i][tmp[i]]; tmp[i]-=1; if(tmp[i]==0)break; } } } inline void process(){ int res=0; for(int i=1;i<=n;i++){ if(i&1)res+=a[i][1]; else res-=b[i][1]; } printf("%d\n",res); } int main(){ freopen("chess.in","r",stdin); freopen("chess.out","w",stdout); n=read(),m=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) b[i][j]=read(); if(n<=5&&m<=5){ dfs(0,0); printf("%d\n",ans); } else if(m==1){ process(); } return 0; } ```
by misinclair @ 2018-04-06 21:47:18


@[AK_583](/space/show?uid=46749) 为什么要定义 pow 数组?
by Anguei @ 2018-04-06 22:00:34


@[yyfcpp](/space/show?uid=53062) 那个是写了一个yy的想法 发现行不通...忘删了
by misinclair @ 2018-04-06 22:08:38


@[AK_583](/space/show?uid=46749) 好像就是那个数组名 CE 了。。
by Anguei @ 2018-04-06 22:19:43


@[yyfcpp](/space/show?uid=53062) 但是洛谷也是linux啊 没有ce额
by misinclair @ 2018-04-06 22:24:17


@[AK_583](/space/show?uid=46749) 您用 C++11 编译试试?应该就是这里的问题。
by Anguei @ 2018-04-06 22:26:34


@[yyfcpp](/space/show?uid=53062) 好吧 是我sb了 thx
by misinclair @ 2018-04-06 22:30:51


@[AK_583](/space/show?uid=46749) 这是一个很好的例子。 using namespace是一个不好的习惯,会增加CE概率。 出处:@[yyfcpp](/space/show?uid=53062)
by middle_set @ 2018-04-07 00:01:00


@[AK_583](/space/show?uid=46749) 研究了一下,终于知道为什么开 C++11 会 CE 了。 罪魁祸首是 `cmath` 这个头文件,里面定义了 `pow` 函数。如果引入了 `cmath`,又在 `main()` 外面定义了名叫 `pow` 的东西,就会冲突,产生 CE。 然而您的程序并没有 `#include <cmath>`。这说明是 C++11 **间接引用了 `cmath`。** ----- 下面来详细分析一下。`algorithm` 头文件中含有大量算法。有些算法需要随机化(比如快速排序选择起点)。所以在 `algorithm` 头文件中一定引用了一个包含随机函数的头文件。 + 如果没有开启 C++11,那么,很好运,使用 `cstdlib` 当中的 `rand()`。 + 但是如果开启了 C++11,就会优先使用 C++11 的随即库 `random`。让我们看看 GCC 的 `random` 头文件**开头**是怎么写的: ```cpp #if __cplusplus < 201103L // 如果是 C++11 之前的标准 # include <bits/c++0x_warning.h> #else #include <cmath> // 注意这里 #include <cstdio> #include <cstdlib> #include <string> #include <iosfwd> #include <limits> #include <debug/debug.h> #include <type_traits> ``` 好了,分析完了。 `#include` 链:`algorithm` → `stl_algo.h` → `random` → `cmath` @[小闸蟹](/space/show?uid=59062)
by Anguei @ 2018-04-07 00:13:44


@[hiuseues](/space/show?uid=47842) 就算不写 `using namespace std;` 也会 CE。因为 `pow` 这种东西是 C 语言过来的。
by Anguei @ 2018-04-07 00:14:25


| 下一页