zoukankan      html  css  js  c++  java
  • USACO 2.2 循环数

    题目:https://www.luogu.org/problemnew/show/P1467

    没认真读题啊,失误好多

    题目本身很简单,注意判断即可

    顺带:如果%n之后是0,得特判赋值成n

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<climits>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
      int ans = 0,op = 1;
      char ch = getchar();
      while(ch < '0' || ch > '9')
        {
          if(ch == '-') op = -1;
          ch = getchar();
        }
      while(ch >= '0' && ch <= '9')
        {
          (ans *= 10) += ch - '0';
          ch = getchar();
        }
      return ans * op;
    }
    ll m;
    int a[10];
    bool vis[12];
    bool ex[12];
    int invert(int x)
    {
      int tot = 0;
      memset(a,0,sizeof(a));
      memset(ex,0,sizeof(ex));
      while(x)
        {
          a[++tot] = x % 10;
          if(ex[a[tot]]) return -1;
         ex[a[tot]] = 1;
          x  /= 10;
        }
        for(int i = 1;i <=tot / 2;i++) swap(a[i],a[tot- i + 1]);
      return tot;
    }
    bool dfs(int x)
    {
      int cur = 1;
      memset(vis,0,sizeof(vis));
      int len = invert(x);
      if(len == -1) return 0;
      for(int i = 1;i <= len;i++)
        {
          if(vis[cur] || a[cur] == 0) return 0;
          vis[cur] = 1;
          cur += a[cur];
          if(cur > len) cur %= len;
          if(!cur) cur = len;
        }
    
      if(cur != 1) return 0;
      return 1;
    }
    int main()
    {
      m = read();
      for(ll i = m + 1;i <= LONG_LONG_MAX;i++)
        {
          if(dfs(i))
        {
          printf("%lld",i);
          return 0;
        }
        }
    }
  • 相关阅读:
    .Net反编译软件
    Windows下Node.js安装及环境配置
    Servlet处理日期
    Servlet的文件上传
    Eclipse错误:Syntax error on tokens, delete these tokens问题解决
    Servlet中操作数据库
    Servlet的会话(Session)跟踪
    Servlet的Cookies处理
    Servlet的异常处理
    Servlet的过滤器(Filter)
  • 原文地址:https://www.cnblogs.com/LM-LBG/p/9974111.html
Copyright © 2011-2022 走看看