Coding
编程题解
D.Y.T
这个作者很懒,什么都没留下…
展开
-
hdu1542线段树 扫描线 求面积并
各变量名称严格按照算法竞赛进阶指南的起名习惯,可结合起来研究。#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>using namespace std;#define MID ((l(p) + ...原创 2019-08-24 21:52:50 · 107 阅读 · 0 评论 -
树状数组两个模板
模板1:单点修改求区间和#include <cstdio>#pragma GCC optimize(2)typedef long long ll; const int N = 505050;ll c[N], a[N];ll n, m; void add(ll x, ll y){ for(; x <= n; x += x & -x ) c[x]+=y; ...原创 2019-08-17 15:49:49 · 85 阅读 · 0 评论 -
hdu4507 恨7不成妻 麻烦的数位dp
花了近一个下午才想明白如何用子状态的平方和更新自状态的平方和,这个题恶心到俺了。。。。hdu4507可以看看https://blog.csdn.net/LightningUZ/article/details/90619068写的超级详细。如果一个整数符合下面3个条件之一,那么我们就说这个整数和7有关—— 1、整数中某一位是7; 2、整数的每一位加起来的和是7的整数倍; 3、这...原创 2019-08-13 20:34:29 · 99 阅读 · 0 评论 -
hdu2196 computer 树形dp
hdu2196A school bought the first computer some time ago(so this computer’s id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one of settled ea...原创 2019-08-14 14:03:25 · 136 阅读 · 0 评论 -
[集训笔记7th]dp进阶之树形dp hdu1054
树形dp就是在一棵树dp, 状态转移发生在根节点与子节点,求该树在题目背景下的最优解。hdu1054题意:给一棵树,树上的每个节点可以放一个哨兵,使该节点相连的边从0变为1,求至少多少哨兵可以使树上的每一条边都从0变为1。题解:设dp[i][true]为i节点放哨兵的最优解,dp[i][false]为i节点不放哨兵的最优解,因为要使所有边都变为1,所以如果i节点不放哨兵,那么他的子节点就都要...原创 2019-08-12 18:35:23 · 140 阅读 · 0 评论 -
hdu3652 B-number 数位dp
hdu3652A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string “13” and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 an...原创 2019-08-13 15:55:17 · 134 阅读 · 0 评论 -
hdu3709 Balanced Number 数位dp
hdu3709Problem DescriptionA balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated b...原创 2019-08-14 09:26:29 · 121 阅读 · 0 评论 -
hdu6629 2019多校5 拓展KMP 模板题
hdu6629坑点:完全匹配不需要加匹配错误的1次其余就是模板s的所有后缀子串与s的最大前缀#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e6 + 10;typedef long long ll;char s[N];int nex[N],extend[N];...原创 2019-08-09 10:49:05 · 124 阅读 · 0 评论 -
poj3067 树状数组解决二维逆序对
一直在学习二维逆序对的解决方法,然后并没有搞明白,这是第一道自己搞出来的模板题。POJ3067 JAPAN题解:设东部的城市为eie_iei,西部的城市为wiw_iwi,那么如果连接e1e_1e1w2w_2w2和连接e2e_2e2w1w_1w1的两条道路想形成交叉,必然有当e1<e2e_1 < e_2e1<e2时,w1>w2w_...原创 2019-08-09 09:17:48 · 375 阅读 · 0 评论 -
[集训笔记6th]dp进阶之数位dp
学习自:https://blog.csdn.net/wust_zzwh/article/details/52100392通过一个代码片来看数位dp的特点for(int i = l; l <= r; i++){ if(check(i) == true) cnt++;}check就是题目的某些约束条件。一般是求区间内满足条件的数目。hdu2089 不要62 (和4模板题:求[l...原创 2019-08-12 18:21:41 · 123 阅读 · 0 评论 -
Function icpc2016大连网络赛H 单调栈预处理连续取模
hdu5875题解如题目。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>using namespace std;const int N = 1e5 + 100;int a[N], id[N];...原创 2019-08-29 21:03:50 · 130 阅读 · 0 评论 -
upc10214 2019我要变强弱校联训赛第十场I 字符串哈希
题意:给一个字符串,把它分成尽量多的K个子串,设子串subs1,subs2…subsksubs_1, subs_2…subs_ksubs1,subs2…subsk,要求满足subsi=subsk−i+1subs_i = subs_{k - i + 1}subsi=subsk−i+1,求KmaxK_{max}Kmax思路:两边向中间贪心,如果遇到相同的子串就插入分割线,同时K加2,如果...原创 2019-08-27 20:42:17 · 97 阅读 · 0 评论 -
upc 9601 PACKING 一个顶俩背包
题目描述It was bound to happen. Modernisation has reached the North Pole. Faced with escalating costs for feeding Santa Claus and the reindeer, and serious difficulties with security, NP Management has...原创 2019-08-09 21:01:46 · 373 阅读 · 0 评论 -
poj 2828 Buy Tickets 线段树+小思维
传送门题目大意,插队的问题,每个案例给出n,代表有n个插队的,每个给出p,v,意思是代号为v的人插在了第p个人的后面,问最后的队伍的排列?题目中一开始整个队列是空的,也就是说如果输入i,j:代表代号为j的人插在了第i个人的后面,也就是说在他之前一定有了i个人,而他的位置是i+1。离线存储,倒序更新线段树(因为后来的人好确定位置,而且先到的人的实际位置受后来的人的影响),遍历叶子结点正序输出。...原创 2019-08-29 20:18:30 · 129 阅读 · 0 评论 -
洛谷P1280 尼克的任务(图论方法解决倒序dp)
题目描述尼克每天上班之前都连接上英特网,接收他的上司发来的邮件,这些邮件包含了尼克主管的部门当天要完成的全部任务,每个任务由一个开始时刻与一个持续时间构成。尼克的一个工作日为N分钟,从第一分钟开始到第N分钟结束。当尼克到达单位后他就开始干活。如果在同一时刻有多个任务需要完成,尼克可以任选其中的一个来做,而其余的则由他的同事完成,反之如果只有一个任务,则该任务必需由尼克去完成,假如某些任务开始时...原创 2019-08-10 13:49:19 · 99 阅读 · 0 评论 -
FZU2109 Moutain Number 数位DP
One integer number x is called “Mountain Number” if:(1) x>0 and x is an integer;(2) Assumex=a[0]a[1]...a[len−2]a[len−1]x=a[0]a[1]...a[len-2]a[len-1]x=a[0]a[1]...a[len−2]a[len−1](0≤a[i]a[i]a[i]≤9...原创 2019-08-17 16:01:01 · 118 阅读 · 0 评论 -
hdu6630 2019多校5 思维递推斐波那契角度
hdu6630题意:You are given three positive integersN,x,yN,x,yN,x,y.Please calculate how many permutations of 1∼N satisfies the following conditions (We denote the i-th number of a permutation by pip_ip...原创 2019-08-09 10:41:01 · 124 阅读 · 0 评论 -
hdu1255 线段树 扫描线 求面积交
pushup与求面积并稍有不同本题有特判,样例是7.62和0.00就对了#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>using namespace std;#define MID ((l...原创 2019-08-25 11:10:37 · 115 阅读 · 0 评论 -
POJ3263 Tallest Cow差分模板练习
POJ3263FJ’s N (1 ≤ N ≤ 10,000) cows conveniently indexed 1…N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,...原创 2019-08-24 21:02:08 · 177 阅读 · 0 评论 -
Balancing Act 树的重心模板题
Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1…N. Deleting any node from the tree yields a forest: a collection of one or more trees. Define the balance of a node to be the size o...原创 2019-08-15 14:41:34 · 169 阅读 · 0 评论 -
hdu1695 莫比乌斯反演
套用反演公式后分块即可以后不要硬套莫比乌斯函数前缀和公式,会炸#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>typedef long long LL;using namespace std;const int MAX = 1e5+10...原创 2020-03-05 20:51:08 · 85 阅读 · 0 评论 -
二分图匹配问题
二分图匹配问题定义 :无向图中n个节点分成A,B两个非空集合, A∩B = ∅,并且同一集合内点互不相连, 称此无向图为二分图,A中的点称左部点, B中的点称右部点。二分图的判定:当且仅当图中不存在长度为奇数的环。染色法:void dfs(int x,int color){ v[x] = color; for(int i = head[x]; i; i = Next[i]){ in...原创 2019-09-17 15:11:33 · 367 阅读 · 0 评论 -
生成函数 入门+板子
生成函数裸用比较简单,结合卷积出组合题目较为困难.学习https://blog.csdn.net/qq_41357771/article/details/83449481http://blog.csdn.net/xiaofei_it/article/details/17042651https://blog.csdn.net/qq_40379678/article/details/88879...原创 2020-03-01 22:46:29 · 103 阅读 · 0 评论 -
zoj2706 Thermal Death of the Universe 线段树正常模拟
传送门题面Johnie has recently learned about the thermal death concept. Given that the Global Entropy always increases, it will end in the thermal death of the Universe. The idea has impressed him extrem...原创 2019-09-20 20:38:57 · 139 阅读 · 0 评论 -
51nod1556 默慈金数+乘法逆元
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int MAXN = 1000005;const int MOD = 1e9+7;typedef l...原创 2019-09-17 15:10:35 · 123 阅读 · 0 评论 -
upc13440 字符串哈希
传送门题目描述小X身为奆老,兴趣爱好广泛,他还非常喜欢研究DNA序列……小X进行了一项关于DNA序列研究,发现人某条染色体上的一段DNA序列中连续的k个碱基组成的碱基序列与做题的AC率有关!于是他想研究一下这种关系。现在给出一段DNA序列,请帮他求出这段DNA序列中所有连续k个碱基形成的碱基序列中,出现最多的一种的出现次数。输入第一行为一段DNA序列,保证DNA序列合法,即只含有A,G...原创 2019-09-18 10:47:41 · 2759 阅读 · 0 评论 -
CDQ分治
自闭week1ing每次啥题都帮不上忙,有时候全场都摸不到键盘。菜是原罪。回归正题CDQ分治在一个序列解决修改和查询问题时,可以通过折半的形式对某点之前的信息进行更新。void CDQ(int L, int R){ if L==R 只有一个元素,不用查询,返回 //此时L不等于R,说明L到R之间不止一个元素,如果被查询点k在右半区间,那么我们通过递归修改左半区间所有应该被...原创 2019-09-18 10:53:10 · 108 阅读 · 0 评论 -
p3935 Calculating 莫比乌斯反演式的套路+数论分块整理
题意:定义函数f(x)=∑i=1x[i∣x]f(x)= \sum_{i = 1}^x[i|x]f(x)=∑i=1x[i∣x],即x的因子个数,给定lll,rrr求(∑i=lrf(i))%998244353(\sum_{i=l}^r{f(i)})\% 998244353(∑i=lrf(i))%998244353求和数论题在优化复杂度时经常使用把遍历每个数变成遍历每个因子的套路,是很多题的突破口...原创 2020-03-01 22:45:00 · 132 阅读 · 0 评论 -
Palindrome POJ 3974
题意:给字符串,求最长回文子串长。hash + 二分解法 O(NlogN)O(NlogN)O(NlogN)#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef unsigned long long ull;char str[1000010];...原创 2019-08-30 19:35:11 · 92 阅读 · 0 评论 -
hdu1398 Square Coins 母函数的无上限形式
#include <iostream>#include <cstring>using namespace std;const int MAX = 301;int n,a[MAX],b[MAX],i,j,k,v[18];int main(){ for (i=1;i<=17;i++) v[i]=i*i; while ((cin>>n)&am...原创 2020-03-01 17:25:15 · 120 阅读 · 0 评论 -
hdu1711 KMP模板
hdu1711string情况下find更高效,奈何不一定是string啊#include <cstring>#include <iostream>#include <cstdio>using namespace std;const int N = 1e6 + 10;int a[N], b[N];int Next[N], f[N];int...原创 2019-09-17 15:08:56 · 123 阅读 · 0 评论 -
Al箔的期末考试
保留小数点后两位#include <stdio.h>int main(){ float answer = 12.3456; printf("%.2f", answer); //小数点后面留3位,就是printf("%.3f",answer)}输出12.35(可能是12.34)输出字符的整数值#include <stdio.h>i...原创 2019-12-19 20:20:20 · 114 阅读 · 0 评论 -
第二期STL题解
很水的题。1.#include <iostream>#include <cstdio>using namespace std;int main(){ string s, r; cin >> s >> r; if(s > r) cout << ">" << endl...原创 2020-01-19 18:44:44 · 238 阅读 · 0 评论 -
[集训回顾1th]数论模板
判质数试除法bool is_prime(int n){ if(n < 2) return false; for (int i = 2; i <= sqrt(n); i++){ if(!n%i) return false; } return true;}埃拉斯托尼筛bool p[maxn];void eratosthenes_sieve() { p[0]...原创 2019-09-18 10:50:00 · 149 阅读 · 0 评论 -
2015 icpc 合肥 queue J题 思维+线段树模拟
传送门题意:题目给出每个人前边或者后边有k个人比他高,在这个条件下排字典序最小的队伍题解:当放p这个人的时候,要保证他前边或后边能放k个比他高的人,假如p是第一个我们要放进队伍的人,那我们应该在前边或后边留出k个空来放比他高的那k个人如果p不是第一个我们要放进队伍里的人,也就是说给比p高的那k个人留的空已经被放人了,但也许这些空并没有放满,这时候我们就不知道应该如何放p,所以为了避免这k...原创 2019-09-10 18:35:52 · 171 阅读 · 0 评论 -
2019icpc徐州网络赛
E. XKC’s basketball team求大于等于aia_iai的最右边的下标j,ans = j - i - 1。#include <iostream>#include <cstdio>using namespace std;typedef long long ll;const int N = 5e5 + 50;struct Node { ...原创 2019-09-18 10:50:57 · 154 阅读 · 0 评论 -
7-7 是否同一棵二叉搜索树 (25 分)
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数N (≤10)和L,分别是每个序列插入元素的个数和需要检查的...原创 2019-11-25 18:32:58 · 395 阅读 · 1 评论 -
bzoj4001概率论 卡特兰数+生成函数+导数
#include <iostream>#include <cstdio>using namespace std;int main(){ double n; cin >> n; printf("%.9lf\n", n*(n+1)/2/(2*n-1)); return 0;}题解:首先节点为nnn的二叉树个数, 卡特兰...原创 2020-02-29 21:26:48 · 352 阅读 · 0 评论 -
2019 icpc 南昌 Fire-Fighting Hero
传送门建立超级源点把消防站看成一个点,然后两边Dijkstra即可#include<iostream>#include<cstring>#include<queue>#include<algorithm>using namespace std;#define inf 0x3f3f3f3ftypedef long long ll;t...原创 2019-09-17 15:09:06 · 115 阅读 · 0 评论 -
2019icpc沈阳H Texas hold'em Poker 大模拟
wdnmd,补题一遍过了。nmdwsm???传送门#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>using namespace std;const int N = 1e5+10;c...原创 2019-09-15 10:46:29 · 332 阅读 · 0 评论