牛客每日练习----Beautiful Trees Cutting,Professional Manager,Operating System

我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。                                      ----喻言

链接: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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define pr pair
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=2000010;
int const mod=1e9+7;
const int maxn=1e5+10;
ll k;
char s[maxn];
ll ksm(ll a,ll b){
    ll r=1;
    while(b){
        if(b&1) 
			r=r*a%mod;
        a=a*a%mod;
		b>>=1;
    }
	return r;
}
int main(){
    cin>>k;
	scanf("%s",s);
    int d=strlen(s);
    ll q=ksm(2,d);
    ll p=((ksm(q,k)-1)*ksm(q-1,mod-2))%mod;
    ll jg=0;
    for(int i=0;i

链接: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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define pr pair
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=2000010;
int const mod=1e9+7;
const int maxn=1e5+10;
int n,m,k,p[300010];
int fd(int x) {
    if (p[x]<0) 
		return x;
    return p[x]=fd(p[x]);
}
void hb(int x, int y) {
    int rx=fd(x);    
	int ry=fd(y);
    if (rx==ry) 
		return;
    int t=p[rx]+p[ry];
    if (p[rx]

链接: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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define PP pair
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=2000010;
int const mod=1e9+7;
const int maxn=1e5+10;
int a[50010],vis[50010],pos[50010],mov[50010];
int main()
{
    int n,q,m;
    while(~scanf("%d %d %d",&n,&m,&q)) {
    	int jg=0;
        priority_queueque;
        for(int i=1;i<=q;i++)
            scanf("%d",&a[i]);
        for(int i=0;i<=m;i++)
            pos[i]=50001;
        memset(vis,0,sizeof(vis));
        for(int i=q;i>=1;i--) {
                mov[i]=pos[a[i]];
                pos[a[i]]=i;
        }
        for(int i=1;i<=q;i++) {
            if(jg=n&&!vis[a[i]]) {
                jg++;
                vis[a[i]]=1;
                vis[que.top().second]=0;
                que.pop();
            }
            que.push(make_pair(mov[i],a[i]));
        }
        printf("%d\n",jg);
    }
    return 0;
}

 

你可能感兴趣的:(牛客网)