• 蓝桥杯2016决赛 凑平方数


    最倒霉的一次,我直接也是醉了,想在想起来都悔死了,263,这个数字我绝对不会忘掉,一等奖一步之遥,刚考完的时候还在想怎么会这样,最不能确定的题目就是这道了,考试的时候感觉挺简单的,之后聊的时候甚至有点纳闷,怎么还都最不出来呢,结果最后自己却是错掉了,如果不会也就算了,但是全部结果只因为一个LL,两个字母就决定了最终的结果,也是悔死了。。。

    但是决赛已经结束,ACM省赛全力以赴吧。。。

    8个人,额,就8个人 。 。 。 。 。 。 。 。 。。 。 。 。。 。 。 。。  。。 。 。 。。 。 。 。。 。。 。 。 。。 。。 。 。 

    正确代码:

    #include <iostream>
    #include <fstream>
    #include <cstring>
    #define LL long long
    using namespace std;
    bool mark[100];
    LL res[100],sum=0;
    bool tmpmark[10];
    bool judge(LL x){
      memset(tmpmark,0,sizeof(tmpmark));
      if(x==0){
        if(mark[0] == 1)
            return false;
        return true;
      }
      while(x!=0){
        if(mark[x%10] || tmpmark[x%10])     
            return false;
        tmpmark[x%10] = 1;
        x/=10;
      }
      return true;
    }
    
    int update(LL x,int coun){  ///就错了这个地方的一个LL,两个字母啊啊啊啊啊啊啊 啊啊啊啊啊啊 啊啊 啊啊啊啊 啊啊 啊啊啊啊 啊啊啊啊 啊 啊啊 啊啊啊
      if(x==0){
        mark[x] = 1;
        coun++;
        return coun;
      }
      while(x!=0){
        mark[x%10] = 1;
        x/=10;
        coun++;
      }
      return coun;
    }
    
    void reupdate(LL x){
      if(x==0){
        mark[x] = 0;
        return ;
      }
      while(x!=0){
        mark[x%10] = 0;
        x/=10;
      }
    }
    
    void dfs(int coun,int rescoun,LL last){
      if(coun == 10){
        for(int i=0;i<rescoun;i++)
            cout<<res[i]<<' ';
        cout<<">>>"<<sum<<endl;
        sum++;
        return ;
      }
      for(LL i=last;i<=100000;i++){
        if(judge(i*i)){
            int tmpcoun = update(i*i,coun);
            res[rescoun] = i*i;
            dfs(tmpcoun,rescoun+1,i+1);
            reupdate(i*i);
        }
      }
    }
    int main (){
        memset(mark,0,sizeof(0));
        dfs(0,0,0);
        cout<<sum;
        return 0;
    }
    



  • 相关阅读:
    <<卸甲笔记>>-基础语法对比
    <<卸甲笔记>>-Oracle线下迁移到PPAS
    How to use PEM of PPAS
    PPAS Migration Toolkit document
    PostgreSQL中数据库,表,等对象的oid与对象名的对应关系
    使用pgstatspack分析PostgreSQL数据库性能
    Postgres Plus Advanced Server installation
    Ways to access Oracle Database in PostgreSQL
    Some settings of PostgreSQL
    nginx内置变量
  • 原文地址:https://www.cnblogs.com/zswbky/p/6717915.html
Copyright © 2020-2023  润新知