zoukankan      html  css  js  c++  java
  • HDU 1404 Digital Deletions (暴力博弈)

    题意:给定一个数字串,最长是6,然后有两种操作。

    第一种是,把该串中的一个数字换成一个比该数字小的数,比如 5 可以换成 0,1,2,3,4.   e.g. 12345 --> 12341

    第二种是,把数字 0 以及它后面的数都删掉,e.g.  120154 --> 12

    析:因为数字最长是 6 位,所以直接把所有的情况都算出来,就好了,这首先 g[1] = 0,然后能够该必败态的,都是必胜态,然后没有到达的点都是必败点,就这样就可以筛选了,还要注意的事从必败态去筛选必胜态的时候,有两种情况,
    第一种是把其实的数字进行加法,最高到9。比如 1 筛选的时候, 1 2  3 4 5 6 7 8 9 都要筛选掉,因为这些都能得到 1

    第二种不够六位的添加一个0,然后后面, 随便  比如 1  101 102 1012 10123 101234 这样的

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #include <list>
    #include <assert.h>
    #include <bitset>
    #include <numeric>
    #define debug() puts("++++")
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a, b, sizeof a)
    #define sz size()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    #define lowbit(x) -x&x
    //#define all 1,n,1
    #define FOR(i,x,n)  for(int i = (x); i < (n); ++i)
    #define freopenr freopen("in.in", "r", stdin)
    #define freopenw freopen("out.out", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e17;
    const double inf = 1e20;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e6 + 10;
    const int maxm = 100 + 2;
    const LL mod = 100000000;
    const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
    const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c) {
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int g[maxn];
    char s[10];
    int a[10];
    
    void solve(int n){
      int len = 0, x = n;
      while(x){
        a[++len] = x % 10;
        x /= 10;
      }
      for(int i = 1; i <= len; ++i){
        int m = 1;
        x = i;  while(--x)  m *= 10;
        for(int j = 1; j + a[i] < 10; ++j)  g[n+j*m] = 1;
      }
      x = 6 - len;
      int y = 1;
      while(x--){
        n *= 10;
        for(int i = 0; i < y; ++i)  g[n+i] = 1;
        y *= 10;
      }
    }
    
    int main(){
      for(int i = 1; i < 1000000; ++i)  if(!g[i]) solve(i);
      while(scanf("%s", s) == 1){
        if(s[0] == '0'){ puts("Yes");  continue;    }
        n = atoi(s);
        if(g[n])  puts("Yes");
        else  puts("No");
      }
      return 0;
    }
    

      

  • 相关阅读:
    深入理解计算机系统第二版习题解答CSAPP 2.2
    深入理解计算机系统第二版习题解答CSAPP 2.1
    oracle 关闭回收站
    在Razor标记内写入文本
    MVC5+EF6 入门完整教程8_1:实体数据模型
    MVC5+EF6 入门完整教程9:多表数据加载
    MVC5+EF6 入门完整教程8:EF6 Code First 数据迁移
    SQL Linq Lambda
    web及H5 的链接测试
    web安全测试之一
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/8432924.html
Copyright © 2011-2022 走看看