链接:https://ac.nowcoder.com/acm/problem/15695
来源:牛客网
It’s universally acknowledged that there’re innumerable trees in the campus of HUST.
One day Xiao Ming is walking on a straight road and sees many trees line up in the right side. Heights of each tree which is denoted by a non-negative integer from 0 to 9 can form a tree string. It's very surprising to find that the tree string can be represent as an initial string repeating K times. Now he wants to remove some trees to make the rest of the tree string looks beautiful. A string is beautiful if and only if the integer it represents is divisible by five. Now he wonders how many ways there are that he could make it.
Note that when we transfer the string to a integer, we ignore the leading zeros. For example, the string “00055” will be seen as 55. And also pay attention that two ways are considered different if the removed trees are different. The result can be very large, so printing the answer (mod 1000000007) is enough. And additionally, Xiao Ming can't cut down all trees.
The first line contains a single integer K(1≤k≤109)(1 \leq k \leq 10^{9})(1≤k≤109), which indicates that the tree string is the initial string repeating K times.
The second line is the initial string S(1≤∣S∣≤105)(1 \leq |S| \leq 10^{5})(1≤∣S∣≤105).
A single integer, the number of ways to remove trees mod 1000000007.
示例1
复制
1
100
复制
6
Initially, the sequence is ‘100’. There are
6 ways:
100
1_0
10_
_00
__0
_0_
示例2
复制
3
125390
复制
149796
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
链接:https://ac.nowcoder.com/acm/problem/15696
来源:牛客网
It’s universally acknowledged that there’re innumerable trees in the campus of HUST.
Thus a professional tree manager is needed. Your task is to write a program to help manage the trees.
Initially, there are n forests and for the i-th forest there is only the i-th tree in it. Given four kinds of operations.
1 u v, merge the forest containing the u-th tree and the forest containing the v-th tree;
2 u, separate the u-th tree from its forest;
3 u, query the size of the forest which contains the u-th tree;
4 u v, query whether the u-th tree and the v-th tree are in the same forest.
The first line contains an integer T(T≤10)(T \leq 10)(T≤10), indicating the number of testcases.
In each test case:
The first line contains two integers N and Q(1≤N,Q≤105)(1 \leq N,Q \leq 10^{5})(1≤N,Q≤105), indicating the number of initial forests and the number of operations.
Then Q lines follow, and each line describes an operation(1≤u,v≤N,u≠v)(1 \leq u,v \leq N,u\neq v)(1≤u,v≤N,u=v).
For each test cases, the first line should be "Case #i:", where i indicate the test case i.
For each query 3, print a integer in a single line.
For each query 4, print "YES" or "NO" in a single line.
示例1
复制
1
10 8
3 1
4 1 2
1 1 2
3 1
4 1 2
2 1
3 1
4 1 2
复制
Case #1:
1
NO
2
YES
1
NO
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
链接:https://ac.nowcoder.com/acm/problem/15688
来源:牛客网
在学习Operating System的过程中,Glory遇到了这样一个问题,现在有一个大小为可以容纳N个页面的内存,硬盘内的内容被分成M个页面,用1~M来标识,一开始内存里没有任何页面,接下来用户会请求Q个页面,你需要设计一个置换算法,使得缺页发生的次数最少。缺页是指用户请求某个编号的页面,但这个页面没有在内存中的情况。发生缺页之后,你必须要把硬盘内对应的页面调入内存中,如果内存已满,你需要置换掉当前内存中的某个页面。
多组数据,请处理到输入结束。
每组数据,第一行为三个整数N,M,Q (0 < N,M,Q <= 50000)
接下来一行Q个数,表示用户请求的页面编号。
对于每组数据,输出一个数,表示最少的缺页次数。
示例1
复制
2 3 5
3 1 2 1 2
3 4 5
3 2 1 4 3
复制
3
4
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include