hdu 1404 找sg ***

HDU 1404  Digital Deletions

一串由0~9组成的数字,可以进行两个操作:1、把其中一个数变为比它小的数;2、把其中一个数字0及其右边的所以数字删除。

两人轮流进行操作,最后把所以数字删除的人获胜,问前者胜还是后者胜。

字符串长度为1-6,前者胜输出Yes,否则输出No.

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<queue>
 7 #include<map>
 8 using namespace std;
 9 #define MOD 1000000007
10 const int INF=0x3f3f3f3f;
11 const double eps=1e-5;
12 typedef long long ll;
13 #define cl(a) memset(a,0,sizeof(a))
14 #define ts printf("*****\n");
15 const int MAXN=1000000;
16 int m,tt;
17 bool sg[MAXN];
18 void fun(int n)
19 {
20     int i,j,k;
21     char ss[10];
22     sprintf(ss,"%d",n);
23     int len=strlen(ss);
24     for(i=0;i<len;i++)  //在每位上添加数字
25     {
26         int temp=n;
27         char tss[10];
28         strcpy(tss,ss);
29         while(tss[i]<‘9‘)
30         {
31             tss[i]+=1;
32             sscanf(tss,"%d",&temp);
33             sg[temp]=1;
34         }
35     }
36     if(len!=6)
37     {
38         int temp=n;
39         int base=1;
40         for(i=len;i<6;i++)
41         {
42             temp*=10;
43             for(j=0;j<base;j++)
44             {
45                 sg[temp+j]=1;
46             }
47             base*=10;
48         }
49     }
50 }
51 void init()
52 {
53     sg[0]=1;
54     for(int i=1;i<MAXN;i++)
55     {
56         if(!sg[i])
57         {
58             fun(i);
59         }
60     }
61 }
62 int main()
63 {
64     int i,j,k,ca=1;
65     #ifndef ONLINE_JUDGE
66     freopen("1.in","r",stdin);
67     #endif
68     cl(sg);
69     init();
70     char s[10];
71     while(scanf("%s",s)!=EOF)
72     {
73         int n=0;
74         if(s[0]==‘0‘)
75         {
76             printf("Yes\n");
77             continue;
78         }
79         int len=strlen(s);
80         for(i=0;i<len;i++)
81         {
82             n*=10;
83             n+=s[i]-‘0‘;
84         }
85         if(sg[n])   printf("Yes\n");
86         else printf("No\n");
87     }
88 }
时间: 2024-08-12 00:29:15

hdu 1404 找sg ***的相关文章

HDU 2082 找单词 --- 母函数

HDU 2082 找单词 起码通过这题,知道了母函数是什么东西,值得一做. /* HDU 2082 找单词 --- 母函数 */ #include <cstdio> #include <cstring> const int N = 50; int num[30], c1[N + 10], c2[N + 10]; int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); /

hdu 2082 找单词(母函数|多重背包)

http://acm.hdu.edu.cn/showproblem.php?pid=2082 每一个字母的价值固定,但数目不定.所以每个字母对应的表达式也不同,若第i个字母的个数为a[i],价值为i,那么它的母函数为(1+x^i+x^(2i)+.....+x^(a[i]*b[i])).那么将i属于[1,26]的母函数相乘得到的x^m(1<=m<=50)的系数相加就是答案. #include <stdio.h> #include <iostream> #include &

hdu 1239 找素数对

题意:给你一个大于4的整数m和一个真分数a/b,求最佳素数对p.q,使得a/b<=p/q<=1且pq<=m.最佳即为满足条件的pair中pq最大的一对. 各种打表 zsd:素数的提取 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include<

HDU 1286 找新朋友(欧拉函数模板)

HDU 1286 找新朋友 题意:中文题. 思路:欧拉函数的纯模板题,没什么好说的,主要是理解欧拉函数的意义. 在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等. 例如φ(8)=4,因为1,3,5,7均和8互质.   ----by度娘. #include <stdio.h> int eular(int n){ int ret = 1; for(int i = 2; i*

取石子的几个找sg函数的问题

1.light oj 1296 :传送门 规则,n堆,每次可以从一堆取1到n/2个. 分析: 打表找sg规律,发现 if n&1 sg(x)=sg(x/2); else sg(x)=x/2; 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1000; /*打

Caocao&#39;s Bridges HDU - 4738 找桥

题意: 曹操在赤壁之战中被诸葛亮和周瑜打败.但他不会放弃.曹操的军队还是不擅长打水仗,所以他想出了另一个主意.他在长江上建造了许多岛屿,在这些岛屿的基础上,曹操的军队可以轻易地攻击周瑜的军队.曹操还修建了连接岛屿的桥梁.如果所有的岛屿都用桥连接起来,曹操的军队就可以很方便地部署在这些岛屿之间.周瑜无法忍受,他想毁掉曹操的一些桥梁,把一个或多个岛屿与其他岛屿分开.周瑜身上只有一颗炸弹,是诸葛亮留下的,所以他只能毁掉一座桥.周瑜必须派人带着炸弹去炸毁那座桥.桥上可能有警卫.轰炸队的士兵人数不能少于一

HDU 3032 (SG打表找规律)

题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围比较大,所以最好通过SG打表的结果找出规律在解. sg(4k+1)=4k+1;sg(4k+2)=4k+2;sg(4k+3)=4k+4; sg(4k)=4k-1; 1 2 4 3 5 6 8 7 Sample Input232 2 323 3 Sample OutputAliceBob SG打表找规律

(SG) hdu 1404

Digital Deletions Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2130    Accepted Submission(s): 747 Problem Description Digital deletions is a two-player game. The rule of the game is as follo

hdu 2082 找单词(母函数)

找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4971    Accepted Submission(s): 3537 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找