- 博客(34)
- 收藏
- 关注
原创 2021.07.22【NOIP提高B组】模拟 字符串匹配
思路:这题直接暴力KMPcodecodecode#include<iostream>#include<cstring>#include<cstdio>using namespace std;string s, t;long long n;long long next[1010000];int main(){ scanf("%lld", &n); n--; cin>>s>>t; string ss;..
2021-07-22 15:32:03 64
原创 2021.07.22【NOIP提高B组】模拟 书页
思路:一道简单的数学,直接求出最大文本页数,然后跳就行codecodecode#include<iostream>#include<cstdio>using namespace std;long long k, s;int main(){ scanf("%lld%lld", &k, &s); long long sum=0, t=0; for(long long i=k+1; i<=s; i++) { if(sum+i&l..
2021-07-22 15:30:55 69
原创 2021.07.21【NOIP提高B组】模拟 好数
思路:直接暴力枚举,判断细节codecodecode#include<iostream>#include<cstdio>using namespace std;string s;int k;bool com(string s, string ss){ if(s.size()>ss.size()) return 1; if(s.size()<ss.size()) return 0; return s>=ss;}int ..
2021-07-21 20:31:05 38
原创 2021.07.21【NOIP提高B组】模拟 树的统计
思路:树链剖分模板,推荐博客(https://www.cnblogs.com/chinhhh/p/7965433.html)codecodecode#include<iostream>#include<cstdio>#include<cmath> using namespace std;long long n, m, r, p;long long w[100100], head[100100], tot;long long dep[10010..
2021-07-21 20:26:26 73
原创 2021.07.19【NOIP提高B组】模拟 玉米田(加强版)
思路:直接设当前最外层的状态,然后转移记得开O2codecodecode#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize("Ofast")#pragma GCC optimize("inline")#pragma GCC optimize("-fgcse")#pragma GCC optimize("-fgcse-lm")#pragma GCC optimize("-fipa-sra")#prag..
2021-07-20 20:23:47 69
原创 【YBTOJ】数字计数
思路:这是一道比较简单的数位DP,枚举数字直接做codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;long long l, r;long long a[100];long long dp[100][20];long long dfs(long long pos, long long lend, long long sum, l..
2021-07-20 19:28:45 96
原创 2021.07.19【NOIP提高B组】模拟 概率充电器
思路:首先拓扑一遍,然后树上跑两次,一次求向下传,一次求向上传codecodecode#include<iostream>#include<cstdio>#include<queue>using namespace std;int n, deg[500100], fa[500100];int head[500100], tot;struct node{ int to, next; double w;}b[5001000];double..
2021-07-20 19:24:51 56
原创 2021.07.15【NOIP提高B组】模拟 Reflect Damage
思路:设c[i][j]表示i传给j的伤害比例,很容易列出方程,然后就可以高斯消元求解codecodecode#include<iostream>#include<cstdio>#include<cmath>using namespace std;int n, m;double a[1000][1000];double p[1000];int main(){ scanf("%d", &n); for(int i=1; i<..
2021-07-20 10:16:28 41
原创 2021.07.19【NOIP提高B组】模拟 Gcd会不会
思路:首先,得出要求的东西然后化简,用倍数法求ans,最后做一遍前缀和就行codecodecode#include<iostream>#include<cstdio>using namespace std;long long phi[1000100], a[1000010], maxx;long long p[100100], tot, ans[1001000];bool v[1000100];int main(){ long long t; s..
2021-07-19 21:58:50 61
原创 2021.07.19【NOIP提高B组】模拟 只不过是长的领带
思路:贪心,排一遍序,预处理处后缀max和前缀max,然后每次丢掉一个领带做就行codecodecode#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int n;int b[1001000], c[1001000], d[1001000], p[100100..
2021-07-19 21:56:10 47
原创 2021.07.17【NOIP提高B组】模拟 周长
思路:设f[i][j]表示状态为i,最后一个到j时的最大周长记录方案时就再开一个数组做同样处理就行codecodecode#include<iostream>#include<cstdio>#include<cmath>using namespace std;long long n, ans, ans1;long long a[1001];long long f[20][100000], an[20][100000];long long n..
2021-07-18 08:55:59 89
原创 2021.07.17【NOIP提高B组】模拟 菜地
思路:首先枚举一个中转点,然后当前半段再增加时,后端也可以增加。求最小增加高度O(n)codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;long long n;long long a[1001000], b[1001000], c[10010000];long long ans=1e18;long long max(long ..
2021-07-18 08:53:34 45
原创 2021.07.16【NOIP提高B组】模拟 连词成句
思路:首先设f[i][j]表示i-n和j-n可以匹配,那么就从后面转移过来最后输出方案时,用一个桶记录更改位置,然后一位一位匹配,最后处理一下相对位置就行了codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std; int t;char s[10010], st[10010];int f[2010][2010], g[2010][201..
2021-07-18 08:51:20 42
原创 2021.07.16【NOIP提高B组】模拟 图书馆
思路:首先设f[i][j]表示第1个人走到i点,第二个人走到j点的最小方差。根据方差化简可以看出只用维护路径和,平方和codecodecode#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int n, m;int tot, head[100100];struct node{ int to, next,..
2021-07-18 08:48:47 52
原创 2021.07.16【NOIP提高B组】模拟 下棋
思路:首先每一步操作都会点到(1, 1)这个点,所以只要一直把(1,1)这个点翻白就行要注意有多组游戏,所以最后答案要异或codecodecode#include<iostream>#include<cstdio>using namespace std;int t;int k, n, m;int ma[1000][1000];int main(){ scanf("%d", &t); while(t--) { scanf("%d", ..
2021-07-18 08:45:52 77
原创 2021.07.15【NOIP提高B组】模拟 PtyNB!
思路:很明显,这道题求x(x-1)%2n=0设At=x, Bs=y,A与B互质,则用exgcd求出特解,再求出最小整数解最后用质因数分解枚举A和Bcodecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;long long t;long long n, m, ans;long long p[1000100], tot;bool f[1..
2021-07-18 08:43:15 46
原创 2021.07.15【NOIP提高B组】模拟 Colorful Circle
思路:首先我们想到是期望DP我们设f[i][0/1]表示到i这个点,和我们设的一个空点的颜色相同或不相同的期望值f[i][1]+=f[j−1][0]∗p[i−j+1]∗(i−j+1)/Mf[i][1]+=f[j-1][0]*p[i-j+1]*(i-j+1)/Mf[i][1]+=f[j−1][0]∗p[i−j+1]∗(i−j+1)/Mf[i][0]+=f[j−1][1]∗(M−1)/M∗p[i−j+1]∗(i−j+1)+f[j−1][0]∗(M−2)/M∗p[i−j+1]∗(i−j+1)f[i]..
2021-07-18 08:39:43 47
原创 2021.07.14【NOIP提高B组】模拟 软件公司
思路:想到DP,但超时考虑二分答案,设f[i][j]表示到i个人,共完成j项1,最多可以完成多少项2codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n, m;int x[10100], y[10010];int f[300][300];bool check(int time){ memset(f, 128, s..
2021-07-14 21:55:23 39
原创 2021.07.14【NOIP提高B组】模拟 积木
思路:首先很容易想到用DP做法可是超时怎么办我们可以用组合数,计算一下答案codecodecode#include<iostream>#include<cstdio>#include<cmath>using namespace std;long long mod=1e9+7;long long n, a[20010];long long f[200100];long long qp(long long x, long long k){..
2021-07-14 21:53:35 77
原创 2021.07.13【NOIP提高B组】模拟 JIH的玩偶
思路:很容易想到倍增,维护一个max和min还有ans,之后统计就行了codecodecode#include<iostream>#include<cstdio>using namespace std;int n, f[200100][40], maxx[200100][40], minn[200100][40], ans[200100][40];int a[1001010];int main(){ freopen("tree.in", "r", st..
2021-07-13 22:08:59 34
原创 2021.07.13【NOIP提高B组】模拟 消息传递—70分
思路:对于普通DP只能n^2logn,所以加个记忆化毕竟从一个点走到另一个点它的dp值总是不会变的,所以记录那条边对应那个值就行满分做法以后或许会补code70分code 70分code70分#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int n, a[..
2021-07-13 22:07:25 45
原创 2021.07.12【NOIP提高B组】模拟 Vani和Cl2捉迷藏
思路:首先明确,这题就是要求最小路径覆盖然后最小路径覆盖=总点数-匹配数至于怎么证明还搞不懂codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n, m, ans;int dis[1000][1000], head[1011], tot;int v[1000], father[1010];struct node{ ..
2021-07-13 07:46:17 76
原创 2021.07.12【NOIP提高B组】模拟 最长公共子串
思路:首先两个区间有重叠就合并为一个区间然后弄一个双指针,维护最长长度和区间字母个数codecodecode#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;char t[10000], s[10000];int n, tot;struct node{ int l, r; int c[27];..
2021-07-13 07:44:19 36
原创 2021.07.12【NOIP提高B组】模拟 最短路径
思路:先把问题化成两个人从1开始跳到n,每个点经过一次设f[i][j]表示第一个人走到i,第二个人走到j的最短路为了每个点都走到,那么下一个点就为max(i,j)+1特判b1,b2和n的情况codecodecode#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<queue>using namespace std;i..
2021-07-13 07:41:37 54
原创 2021.07.12【NOIP提高B组】模拟 好元素
思路:直接化成a[i]+a[j]=a[n]−a[k]a[i]+a[j]=a[n]-a[k]a[i]+a[j]=a[n]−a[k]前两个用暴力枚举后hash存储就行codecodecode#include<iostream>#include<cstdio>#include<map>#include<cstring>using namespace std;int mod=25000004;int n;int a[10000];i..
2021-07-13 07:38:24 70
原创 【YBTOJ】区间圆数
思路:首先,我们设f[i][j]代表当前从低到高数第i位,有j个零,。加了一位数,0或者1,那么转移方程就是f[i][j]=f[i−1][j]+f[i−1][j−1]f[i][j]=f[i-1][j]+f[i-1][j-1]f[i][j]=f[i−1][j]+f[i−1][j−1]然后计算答案时,考虑怎样把答案全算到一种可行方案是首先让它前面全部都等于n的前面,然后这一位放0,这样就不会超界,然后再让前面全部为0,当前位为1。其中枚举i代表0的个数,每次累加答案。这样就可以枚举到全部cod..
2021-07-12 07:28:16 99
原创 【YBTOJ】B数计数
思路:这道题用数位DP首先是整除13,我们设一个res,表示当前除13的余数,然后每次计算一下就行然后就是包含13,我们设一个op,0代表没有1或3,1代表有1无3,2代表有13,详见代码codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace std;int n;int a[101];int f[100][14][3];int chec..
2021-07-11 20:58:15 118
原创 【YBTOJ】消除木块
思路:我们先预处理颜色相同且连续的为一个颜色块的长度和颜色设f[i][j][k]表示删除i到j,后面跟着有k个和j相同颜色的木块的最大分则设一个中转点l使l和j的颜色相同,则f[i][j][k]=f[i][l][k+len[r]]+f[i+1][r-1][0](先把l到j之间的方块消除)codecodecode#include<iostream>#include<cstdio>#include<cstring>using namespace st..
2021-07-09 11:29:00 128
原创 【YBTOJ】消除木块
思路:将一段两端颜色相同的涂色就相当于给 i ~ j - 1 或 i + 1 ~ j 涂色不同的就分两段codecodecode#include<iostream>#include<cstdio>#include<cstring> using namespace std;int f[1010][1010];string c;int main(){ cin>>c; int n=c.size(); memset(f, 1, ..
2021-07-09 09:28:50 95
原创 【YBTOJ】石子合并
思路:区间DP模板题codecodecode#include<iostream>#include<cstdio>using namespace std;int n;int a[1010], f[1010][1010];int sum[1010];int main(){ scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &a[i]); for(int i=1; i&l..
2021-07-08 20:53:29 71
原创 【YBTOJ】宝物筛选
思路:就是一个多重背包模板codecodecode#include<iostream>#include<cstdio>using namespace std;int n, m;int tot, a[1000100], b[1000100];int f[10000100]; int main(){ scanf("%d%d", &n, &m); for(int i=1; i<=n; i++) { int s, w, v; ..
2021-07-08 19:11:58 99
原创 【YBTOJ】货币系统
思路:用一个类似筛的东西,把不可以表示的筛出来,那就是B的货币系统codecodecode#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int t, n, a[100010], f[1000100];int main(){ scanf("%d", &t); while(t--) {..
2021-07-08 11:43:54 98
原创 【YBTOJ】采药问题
思路:模板背包codecodecode#include<iostream>#include<cstdio>using namespace std;int m, n;int w[1000100], v[1000100];int f[1000100];int main(){ scanf("%d%d", &m, &n); for(int i=1; i<=n; i++) scanf("%d%d", &w[i], &..
2021-07-07 21:38:45 77
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人