牛客小白月赛73

A.:暴力即可

import random
import sys
import os
import math
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io import BytesIO, IOBase
from copy import deepcopy
import threading
import bisect

# from sortedcontainers import SortedList
BUFSIZE = 4096


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


def I():
    return input()


def II():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(input().split())


def LII():
    return list(map(int, input().split()))


def GMI():
    return map(lambda x: int(x) - 1, input().split())


def LGMI():
    return list(map(lambda x: int(x) - 1, input().split()))




def solve():
    n=II()
    while 1:
        if n%3==0:
            print(n)
            return
        else:n+=1
#2 0-59

# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    for _ in range(1):
        solve()
# 访问 https://www.jetbrains.com/help/pycharm/ 获取 PyCharm 帮助

B.

import random
import sys
import os
import math
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io import BytesIO, IOBase
from copy import deepcopy
import threading
import bisect

# from sortedcontainers import SortedList
BUFSIZE = 4096


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


def I():
    return input()


def II():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(input().split())


def LII():
    return list(map(int, input().split()))


def GMI():
    return map(lambda x: int(x) - 1, input().split())


def LGMI():
    return list(map(lambda x: int(x) - 1, input().split()))




def solve():
    n=II()
    print(n,2*n)
#2 0-59

# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    for _ in range(II()):
        solve()
# 访问 https://www.jetbrains.com/help/pycharm/ 获取 PyCharm 帮助

C.贪心之后直接根据定义判定即可

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
const int N=1010;
int a[N];
int n,m;
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=2;i<=n;i++){
	    if(a[i]-a[i-1]<1)
	    {
	       cout<<"-1\n";
	       return ;
	    }
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
	cout<<"\n";
}
int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--)solve(); 
} 

D E:

首先一个10是由一个2和5相乘得到的,末尾有几个0=min(质因子有2的个数,质因子有5的个数)

统计前缀和 2和5的个数

要让min(s2[i]-s2[j],s5[i]-s5[j])==k

固定一个右端点,二分出左端点

x=s2[i]-k,y=s5[i]-k

因为要满足恰好是k

假设x和y都是一样的值(这里先这么想比较方便)

所以s2和s5的前缀和中要找到区间里面的值都是x的

假设x和y不一样(假设x是最小的)

要找到s2中前缀和都是x的,在这个基础上,s5中前缀和则是0到y即可

然后手画一下就知道区间怎么取值了

下面两种情况,下面s2,下面s5,注意单调递增的数组是,这个推导就留给自己推了,解释有点麻烦

 

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <queue>
using namespace std;
const int N=2e5+10;

typedef pair<int, int> PII;
int a[N];
int n,m,k;
void solve(){
	cin>>n>>k;
	vector<int> d2(n+1,0),d5(n+1,0);
	for(int i=1;i<=n;i++)
	{
	    cin>>a[i];
	    while(a[i]%2==0) d2[i]++,a[i]/=2;
	    while(a[i]%5==0) d5[i]++,a[i]/=5;
	}
	
    vector<int> s2(n+1,0),s5(n+1,0);
    for(int i=1;i<=n;i++){
        s2[i]=s2[i-1]+d2[i];
        s5[i]=s5[i-1]+d5[i];
    }

	long long res=0;
	for(int i=1;i<=n;i++)
	{
	    if(min(s2[i],s5[i])>=k)
	    {
	        int x=s2[i]-k,y=s5[i]-k;
            int l=lower_bound(s2.begin(),s2.begin()+i,x)-s2.begin();
            int r=upper_bound(s2.begin(),s2.begin()+i,x)-s2.begin()-1;
            int L=lower_bound(s5.begin(),s5.begin()+i,y)-s5.begin();
            int R=upper_bound(s5.begin(),s5.begin()+i,y)-s5.begin()-1;
	        res+=min(R,r)-min(l,L)+1;
	    }
	}
	cout<<res<<"\n";
}
signed main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--)solve(); 
}

F:dp

记录一个状态转移的上一个状态

定义是 当前是第 i 个字符,目前有 j 个位置相同,目前数总和余数是k(因为有个*所以直接往当前状态转移到下一个,尽量别往前一个转移到当前一个)

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include<functional>
using namespace std;
typedef long long LL;

const int N=55;
char s[N];
int f[N][1005][N];
int num[N];
struct node{
	int id,j,k,c;
}pre[N][1005][N];
void solve() {
	int n,b,p,K;
	cin>>n>>b>>p>>K;
	cin>>s+1;

	for (int i=1;i<=n;i++) {
		for (int j=0;j<p;j++) {
			for (int k=0;k<=K;k++) {
				f[i][j][k]=0;
				pre[i][j][k]={0,0,0,0};
			}
		}
	}
	for (int i=1;i<=n;i++) num[i]=s[i]-'a'+1;
	int has=0;
	for (int i=1;i<=n;i++) has=(1ll*has*b+num[i])%p;
	f[0][0][0]=1;
	for (int i=1;i<=n;i++) {
		for (int j=0;j<p;j++) {
			for (int k=0;k<=K;k++) {
			    if(f[i-1][j][k]==0) continue;
				for (int c=1;c<=26;c++)
				{
					int eq=c==num[i];
					f[i][(1ll*j*b+c)%p][k+eq]|=f[i-1][j][k];
					if (f[i-1][j][k]) 
					pre[i][(1ll*j*b+c)%p][k+eq]={i-1,j,k,c};
				}
			}
		}
	}
	if(!f[n][has%p][K]){
	    cout<<"-1\n";
	    return ;
	}
	function<string(int,int,int)> dfs=[&](int idx,int j,int k)->string{
	      string res;
	      char c=(char)(pre[idx][j][k].c-1+'a');
	      if(idx==0) return "";
	      int jj=j,kk=k;
	      res=dfs(pre[idx][jj][kk].id,pre[idx][jj][kk].j,pre[idx][jj][kk].k);
	      res+=c;
	      return res;
	};
	cout<<dfs(n,has,K)<<"\n";
}

int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int t;
	cin>>t;
	while (t--) solve();
	return 0;
} 

G:期望,经典不会题,看到期望就寄

从小到大插入,从前面i-1的数里面能插入i的位置,但是不能插入到严格递增序列的后面(就是最后一个位置)所以当前贡献就是(i-1)/i 

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include<functional>
using namespace std;
typedef long long LL;

const int N=2e5+10,mod=998244353;
#define int long long
int n,m,k;
int fac[N];
int qmi(int a, int k, int p)  // 求a^k mod p
{
    int res = 1 % p;
    while (k)
    {
        if (k & 1) res = (LL)res * a % p;
        a = (LL)a * a % p;
        k >>= 1;
    }
    return res;
}

void solve() {
	cin>>n;
	cout<<fac[n]<<"\n";
}

signed main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int t;
	fac[1]=0;
    for(int i=2;i<N;i++)
    fac[i]=(fac[i-1]+(i-1)*qmi(i,mod-2,mod)%mod)%mod;
	cin>>t;
	while (t--) solve();
	return 0;
} 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值