UVA 1558 - Number Game 题目链接 题意:20之内的数字,每次能够选一个数字,然后它的倍数,还有其它已选数的倍数组合的数都不能再选,谁先不能选数谁就输了,问赢的方法 思路:利用dp记忆化去求解,要输出方案就枚举第一步就可以,状态转移过程中,选中一个数字,对应的变化写成一个函数,然后就是普通的博弈问题了,必胜态之后必有必败态,必败态之后全是必胜态 代码: #include <stdio.h> #include <string.h> const int N = 10…
题目连接:uva 11885 - Number of Battlefields 题目大意:给出周长p,问多少种形状的周长为p的,而且该图形的最小包围矩阵的周长也是p,不包含矩形. 解题思路:矩阵高速幂.假设包括矩形的话,相应的则是斐波那契数列的偶数项,所以相应减去矩形的个数就可以. #include <cstdio> #include <cstring> using namespace std; typedef long long ll; const ll MOD = 987654…
Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2…Sk. Each group Sk con…
Addition Chains An addition chain for n is an integer sequence with the following four properties: a0 = 1 am = n a0<a1<a2<...<am-1<am For each k ( ) there exist two (not neccessarily different) integers i and j ( ) with ak =ai +aj You a…
11885 - Number of Battlefields 题意:给周长.求能围成的战场数目.不包含矩形. 思路:详细的递推没递推出来,可是看了网上一个规律,假设包含矩形的答案应该是斐波那契数列(可是奇数情况为0),然后减去矩形数目就是答案,矩形数目为n / 2 - 1,用矩阵高速幂就能求了. 详细的递推过程哪位大神能指点下. .. 代码: #include <stdio.h> #include <string.h> const long long MOD = 987654321…
题意: N 为合数,对于任意一个在(1,N)之间的数满足 anmodn=a,则称N为Carmichael number,对于给定的N,判断是否为Carmichael number. 分析: 素数区间筛法+快速幂 代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; typedef long long ll; const int maxn = 65005; const…
Description An addition chain for n is an integer sequence with the following four properties: a0 = 1 am = n a0<a1<a2<...<am-1<am For each k ( ) there exist two (not neccessarily different) integers i and j ( ) with ak =ai +aj You are give…