为什么同一个程序用C++写过不了,Pascal去能过?

RT

3 条评论

  • @ 2015-11-16 12:54:51

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int dot[50010][2],que[50010][2],ch[50010],n;
    bool used[50010];
    bool make_it()
    {
    int pre;
    int node=1;
    for(int i=1;;i++)
    {
    pre=node;
    que[i][0]=node;
    used[node]=true;
    if(i==n)break;
    if(!used[dot[node][0]])node=dot[node][0];
    else if(!used[dot[node][1]])node=dot[node][1];
    else return false;
    if(dot[node][0]!=pre&&dot[node][1]!=pre)return false;
    }
    if(dot[node][0]!=1&&dot[node][1]!=1)return false;
    return true;
    }
    int main()
    {
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d%d",&dot[i][0],&dot[i][1]);

    if(!make_it()){
    printf("-1\n");return 0;
    }
    int maxn=0;
    for(int i=1;i<=n;i++)que[n-i+1][1]=que[i][0];
    for(int k=0;k<=1;k++){
    memset(ch,0,sizeof(ch));
    for(int i=1;i<=n;i++)
    ch[(que[i][k]-i+n)%n]++;
    for(int i=0;i<n;i++)
    maxn=max(maxn,ch[i]);
    }
    printf("%d",n-maxn);
    }

  • @ 2014-10-25 11:38:41

    写错了

  • @ 2014-08-12 11:22:47

    人品

  • 1

信息

ID
1008
难度
5
分类
组合数学 点击显示
标签
递交数
4095
已通过
1363
通过率
33%
被复制
31
上传者