题目链接:https://vjudge.net/problem/CodeForces-1076B 题意: 题目要求给定一个数,要求每次减去其最小素因数(既是素数又是其因数),问直到n=0需要做几次运算. 分析: 首先如果n为素数,则其最小素因数就是它本身,故第一次运算n:=n-n即得0,只需要一次运算.当n为偶数时,素因子恒为2,故每次减2直到0,所以运算次数为n/2次,当n为奇数是,首先减一次最小素因子,因为最小素因子一定是奇数,故奇-奇=偶,变为偶数后就按上述做法求得运算次数即可. 总结如下…
大意: 给定$n$堆石子, 两人轮流操作, 每次操作两种选择 $(1)$任选非空堆拿走一个石子 $(2)$任选石子数为$2x(x>0)$的一堆, 替换为$k$堆$x$个石子. ($k$给定) 最后无法操作则输, 求谁能赢. 根据$SG$定理可以得到 $sg(x) =   \begin{cases} mex\{sg(x-1)\},&\text{$x$为奇} \\ mex\{sg(x-1),sg(\frac{x}{2})\},  & \text{$x$为偶且$k$为奇} \\ mex\{…
E. Hexagons time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience t…
题意:一组男生女生在排队,每秒钟所有排在女生左边的男生与她相邻的女生交换位置,求女生全部换到男生前面的时间. 思路: 解法一:队伍最前面的那些女生不需要交换,后面的女生有两种状态:畅通无阻,前一个女生还没到达指定位置时到达前一个女生的下一个位置(被阻),花费时间分别为前面的男生数与前一个女生的时间+1.故从左边开始递推一遍. #include<cstdio> #include<cstring> #include<iostream> using namespace std…
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a…
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The b…
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description you the conditions of this task. There are 3 pivots: A, B, C. Initially, n disks of different diameter are placed on the pivot A: the smallest dis…
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点的方案数. 思路: 打表找规律得到的序列是0,3,6,21,60,183,546,1641,4920,14763,通过肉眼看或者oeis可以得到规律为. dp计数:dp[i][j]表示在第i步时站在位置j的方案数,j的取值为[0,3],分别表示D,A,B,C点,转移方程肯定是从其他三个点转移. 代码…
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN]; int main(void) //Codeforce…
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; ]; int main(void) //Codeforces Round #309 (Div. 2) A. Kyoya a…