zoukankan      html  css  js  c++  java
  • pku1029false coin

    枚举法

    代码如下:

     

    #include<stdio.h>
    #include<string.h>
    int left[102][502];
    int right[102][502];
    int a[102];
    short r[1001];
    char c[102];
    int n,k,num;
    int result=0,index;
    int isgreat(int i)
    {
     int j,flag,m;
     for(j=0;j<k;j++)
     {
      if(c[j]=='<')
      {
       flag=0;
       for(m=0;m<a[j];m++)
       {
        if(right[j][m]==i)
        {
         flag=1;break;
        }
       }
       if(flag==0)
        return 0;
      }
      if(c[j]=='>')
      {
       flag=0;
       for(m=0;m<a[j];m++)
       {
        if(left[j][m]==i)
        {
         flag=1;break;
        }
       }
       if(flag==0)
        return 0;
      }
     }
     return 1;
    }
    int islittle(int i)
    {
     int j,flag,m;
     for(j=0;j<k;j++)
     {
      if(c[j]=='<')
      {
       flag=0;
       for(m=0;m<a[j];m++)
       {
        if(left[j][m]==i)
        {
         flag=1;break;
        }
       }
       if(flag==0)
        return 0;
      }
      if(c[j]=='>')
      {
       flag=0;
       for(m=0;m<a[j];m++)
       {
        if(right[j][m]==i)
        {
         flag=1;break;
        }
       }
       if(flag==0)
        return 0;
      }
     }
     return 1;
    }
    void myenum()
    {
     int i;
     for(i=1;i<=n;i++)
     {
      if(r[i])
       continue;
      else if(isgreat(i))
      {
       result++;index=i;
      }
      else if(islittle(i))
      {
       result++;index=i;
      }
     }
     if(result!=1)
      printf("0\n");
     else
      printf("%d\n",index);
    }
    int main()
    {
     int count,i;char cr;
     scanf("%d %d",&n,&k);
     memset(r,0,sizeof(r));
     for(count=0;count<k;count++)
     {
      scanf("%d",&num);
      for(i=0;i<num;i++)
       scanf("%d",&left[count][i]);
      for(i=0;i<num;i++)
       scanf("%d",&right[count][i]);
      a[count]=num;
      scanf("%c",&c[count]);
      scanf("%c",&c[count]);
      if(c[count]=='=')
      {
       for(i=0;i<num;i++)
        r[left[count][i]]=r[right[count][i]]=1;
      }
     } 
     myenum();
     return 0;

    }

  • 相关阅读:
    OP_REQUIRES failed at conv_ops.cc:386 : Resource exhausted: OOM when allocating tensor with shape..
    Python中*args和**kwargs的区别
    命令行运行Python脚本时传入参数的三种方式
    关于 initWithNibName 和 loadNibNamed 的区别和联系-iPhone成长之路
    NSBundle介绍
    UIView总结
    iPhone How-to:如何调整UIView的Z-Order
    有关View的几个基础知识点-IOS开发
    NSNumber与NSInteger的区别
    iOS第三方开源库的吐槽和备忘
  • 原文地址:https://www.cnblogs.com/pandy/p/1331741.html
Copyright © 2011-2022 走看看