![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
HDU
穷源溯流
路很长,尽管走便是。
展开
-
HDU 6601 Keen On Everything But Triangle(主席树+思维)
const int N=2e5+5; int n,m; int i,j,k; int a[N]; struct Ndoe { int sz; int l,r; }t[N<<5]; int root[N],tot=0; //int b[N];void update(int &x,int y,int l,int r,int pos){ x=++tot; t[x...原创 2021-04-26 13:56:26 · 172 阅读 · 0 评论 -
HDU 6486 Flower
const int N=1e5+5; int n,m; int i,j,k; ll a[N];int main(){ rush(){ sd(n); for(int i=1;i<=n;i++) sll(a[i]); sort(a+1,a+1+n); ll ans=a[n]; ll sum=0; for(int i=1;i<n;i++){ ...原创 2021-04-25 08:54:45 · 107 阅读 · 0 评论 -
HDU 6483 A Sequence Game(主席树+线段树)
const int N=1e5+5; int n,m,_; int i,j,k; int a[N]; struct Node { int l,r; int sum; }t[N<<5]; int root[N],tot=0; map<int,int> vis; void update(int &x,int y,int pos,int c,int l,int...原创 2021-04-24 16:20:34 · 151 阅读 · 0 评论 -
HDU 6534 Chika and Friendly Pairs(莫队+离散化+树状数组)
const int N=3e4+5; int n,m,_; int i,j,k; int a[N*3]; int lo[N],up[N]; int b[N*3]; int ans[N]; int block=0,cur=0,now; int vis[3*N]; struct Query { int l,r; int id,bel; bool operator<...原创 2021-04-18 20:24:35 · 164 阅读 · 0 评论 -
HDU 6533 Build Tree(贪心)
const int N=1e6+5; int n,m,_; int i,j,k; ll a[N]; ll sum[N];int main(){ ll d,c; ll p; while(~sd(n)){ sll(d); sll(c); sll(p); for(int i=1;i<=n;i++) sll(a[i]),a[i]=a[i]; if(d==0 || c==0){ put...原创 2021-04-17 18:17:32 · 213 阅读 · 0 评论 -
HDU 6570 Wave(暴力)
const int N=1e6+5; int n,m,_; int i,j,k; int a[N]; vector<int> v[N];int go(int x,int y){ int cur=1,ans=0,last=0; int nx=v[x].size(),ny=v[y].size(); int cnt=nx+ny; int i=0,j=0; while(cnt --> 0){ ...原创 2021-04-10 18:54:43 · 143 阅读 · 0 评论 -
HDU 6576 Worker(最小公倍数)
const int N=1e6+5; int n,m,_; int i,j,k; ll a[N],b[N];ll gcd(ll a,ll b){ if(b==0) return a; else gcd(b,a%b); }ll lcm(int o,int p){ return o/gcd(o,p)*p;}int main(){ ll n,m; while(~sll(n)){ sll(m); ...原创 2021-04-10 18:39:49 · 182 阅读 · 0 评论 -
HDU 4348 To the moon(可持久化线段树)
const int N=1e5+5; int n,m,_; int i,j,k; int a[N]; struct Node { int l,r; ll sum,lazy; }t[N<<5]; int root[N],tot=0;void push_up(int x){ t[x].sum=t[t[x].l].sum+t[t[x].r].sum;}void build...原创 2021-04-07 10:43:34 · 128 阅读 · 0 评论 -
HDU 6621 K-th Closest Distance(主席树+二分)
const int N=1e6+5; int n,m,_; int i,j,k; int a[N]; struct Node { int l,r; int sz; }t[N<<5]; int root[N],tot=0; vector<int> v;//int getid(int x){ return lower_bound(v.begin(),v.end(),x)-...原创 2021-04-07 08:50:42 · 126 阅读 · 0 评论 -
HDU 4417 Super Mario(主席树)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <sstream>#include <queue>#include <vector>#define rush() int T;cin>>T;while(T--)#define ms(a,b) me...原创 2021-04-03 16:30:21 · 165 阅读 · 0 评论 -
HDU 1847 Good Luck in CET-4 Everybody!(SG 函数)
const int N=1e3+5; int n,m; int i,j,k; int sg[N]; bool vis[N];void getSG(){ for(int i=1;i<N;i++){ ms(vis,0); for(int j=1;j<N && i-j>=0;j<<=1){ vis[sg[i-j]]=1; } ...原创 2021-03-01 15:47:07 · 163 阅读 · 0 评论 -
HDU 1848 Fibonacci again and again(nim游戏+sg函数)
const int N=1e3+5; int n,m; int i,j,k; int sg[N]; bool vis[N]; const int fibo[15]={1,2,3,5,8,13,21,34,55,89,144,233,377,610,987};void getSG(){ for(int i=1;i<N;i++){ ms(vis,0); for(int j=0;j<15 && i-fibo[j]>...原创 2021-02-27 23:13:54 · 139 阅读 · 0 评论 -
HDU 1846 Brave Game(SG函数)
const int N=1e3+5; int n,m; int i,j,k; int sg[N]; bool vis[N];void getSG(){ ms(sg,0); for(int i=1;i<=n;i++){ ms(vis,0); for(int j=1;j<=m && i-j>=0;j++){ vis[sg[i-j]]=1; //将之前访问过的 sg 所代表的整数标记 } for(int j...原创 2021-02-27 23:02:06 · 159 阅读 · 0 评论 -
HDU 1247 Hat’s Words(Trie)
给出多个单词组成单词表,问这些单词中有哪些可以拆成两个单词,并按字典序输出按字典序输出自然要借助 set,对于每一个单词,我们将其正序放入字典树,再将其逆序放入字典树,这样存在两颗字典树对于每一个单词将进行询问,如果可以由两个单词表示,那么一定存在位置x,使得 1~x 为一个单词,x+1~len 为一个单词,只要找是否存在这样的x 即可const int N=5e4+5; int n,m; int i,j,k; int t[N*50][26][2]...原创 2021-02-23 14:50:36 · 134 阅读 · 0 评论 -
HDU 3065 && 多校2009 病毒侵袭持续中(AC自动机)
AC自动机 构建完之后,由于特征码都不相同,所以沿着失配边走逐个统计即可注意有多组输入const int N=1e5+5; int n,m; int i,j,k; char s[(int)1e3+5][55]; int tot=0,t[N][128]; int vis[N],f[N]; int ans[N]; char ch[(int)2e6+5];void insert(char *s,int id){ int r...原创 2021-02-21 11:19:14 · 159 阅读 · 2 评论 -
HDU2896 && 多校2009 病毒侵袭(AC自动机)
利用 ac自动机 将源码字符串中出现的特征码找出来,用 set 存储即可const int N=1e5+5; int n,m; int i,j,k; char s[N]; int tot=0,t[N][128]; int vis[N],f[N]; set<int> all;void insert(char *s,int id){ int rt=0; for(int i=0;s[i];i++){ ...原创 2021-02-21 10:19:56 · 160 阅读 · 0 评论 -
HDU 3374 String Problem(KMP+最小表示法)
对于给出的每一个字符串,可以将其任意旋转,输出其字典序最小的位置及出现次数,字典序最大的位置以及出现次数出现次数是指:将字符串 s 旋转可以得到的与 s 相等的个数用最小表示法和最大表示法表示出字典序最大和最小的两个个字符串对于出现个数,例如: abcabcab,其生成元为 abc ,n-next[n] 为其长度,但是其包含不完整的生成元 ab,那么出现次数只能为 1#include <iostream>#include <cstdio>#inc...原创 2021-02-10 16:16:28 · 156 阅读 · 0 评论 -
HDU 2609 How many(最小表示法)
有 n 个字符串,可以对他们进行任意次旋转,问最少出现多少相同的字符串由于可以任意旋转,所以每个字符串的最小表示法相同,加 set/map 去重即可#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <sstream>#include <set>#define rush() ...原创 2021-02-10 15:30:59 · 152 阅读 · 0 评论 -
HDU 2072 单词数(Trie)
注意审题,有多组测试样例,每组一行#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <sstream>#define rush() int T;cin>>T;while(T--)#define ms(a,b) memset(a,b,sizeof a)#define lowb...原创 2021-02-07 15:21:37 · 221 阅读 · 0 评论 -
HDU 1251 统计难题(Trie)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define rush() int T;cin>>T;while(T--)#define ms(a,b) memset(a,b,sizeof a)#define lowbit(x) ((x)&(-x))#define inf (1e1...原创 2021-02-07 14:52:58 · 269 阅读 · 1 评论 -
HDU 4300 && 多校2012 Clairewd’s message(KMP+思维)
先给出 26 个字母,表示 26 个字母分别对应的密文在给出一个字符串,要求添加字符或不添加,保证构造之后的字符串前半部分是密文,后半部分是明文要求添加的字符尽可能少题目还是比较有难度的,首先假设给出的字符串长度为 n,那么密文的长度一定 >=n/2,那么如果 n 是奇数,密文长度 >n/2这样将前半段密文转化为明文,所求的 next[n] 即为真正明文的长度,因为长度不可以超过 n/2但是如果字符串比较特殊,那么需要利用 next 的性质,将明文长度减小...原创 2021-02-05 15:48:01 · 244 阅读 · 0 评论 -
HDU 3336 Count the string(KMP+DP)
求字符串中的每一个前缀在字符串中的出现个数样例解释 :a 出现两次,ab 两次 ,aba 一次,abab 一次next[i] 不为 0,说明出现过前缀,改前缀的贡献会在出现一次,所以 dp[i]=dp[next[i]]+1#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define rush() int T;c...原创 2021-02-05 11:03:19 · 220 阅读 · 0 评论 -
HDU 1358 Period(KMP)
求一个字符串中所有的循环串,对于每一个循环串要求周期 T>1,输出循环串最后一个字母的下标和循环串的周期#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define rush() int T;cin>>T;while(T--)#define ms(a,b) memset(a,b,sizeof a)...原创 2021-02-04 11:40:01 · 163 阅读 · 0 评论 -
HDU 3746 Cyclic Nacklace(KMP)
KMP 算法中知道 x=n-next[n] 为最小循环节,那么 n/x 为循环次数,如果 n%x!=0,说明 x 并不是循环节判断 n/x 是否大于等于 2 即可#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define rush() int T;cin>>T;while(T--)#define ms...原创 2021-02-04 11:08:16 · 187 阅读 · 0 评论 -
HDU 1686 Oulipo(KMP)
给出两个字符串 t,s 求 s 中有多少个 t(包括重叠部分字符串)#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define ss(a) scanf("%s",a)#define pd(a) printf("%d\n",a)#define rush() int T;cin>>T;...原创 2021-02-03 22:03:23 · 187 阅读 · 0 评论 -
HDU 2087 剪花布条(KMP)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define ss(a) scanf("%s",a)#define pd(a) printf("%d\n",a)using namespace std;typedef long long ll;const int N=1e3+5; int n,m; ...原创 2021-02-03 21:36:32 · 194 阅读 · 0 评论 -
HDU 4638 Group(莫队)
给出一个长度为 n 的序列,每次查询给一个区间,问区间可被分成多少个连续的段其实思路并不是很难,考虑任意一个值 x ,被删除后 ,判断 x+1,x-1 是否存在,这样推出答案以后长记性了,一定要先扩充区间。const int N=1e5+5; int i,j,k; int n,m,t; int a[N]; struct Node { int l,r; int bel,id; bool op...原创 2020-11-26 15:23:17 · 147 阅读 · 0 评论 -
HDU 5213 Lucky(莫队+容斥)
给出 n 个数和数字 k,有 m 此询问,每次给出两个区间 [l,r] [u,v] ,问每次询问时,从两个区间内各选一个数字 x,y ,问有多少个二元组使得 x+y=k 成立本来是打算直接用两个莫队来维护这两个区间,但是超时了,想想也是,有 e7 的级数这个题可以将这两个区间和并,因为注意到 l,r,u,v 的关系是单调递增的,所以合并之后用一个莫队来解决,为了满足题目中所说,分别从两个区间中选择 x,y ,所以从区间 [r+1,v] 和 [l,u-1] 中选择的另一个数字是不合法的,所...原创 2020-11-25 11:05:36 · 169 阅读 · 0 评论 -
HDU 1756 Cupid‘s Arrow(转角法)
转角法判断点在多边形内部模板题const int N=1e3+5; int i,j,k; int n,m,t; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){} }a[N],p;typedef Point Vector ;Vector operator-(Vector a,Vector b){ return Vector(a.x...原创 2020-11-23 08:47:24 · 205 阅读 · 0 评论 -
HDU 3756 && UVALive 4986 Dome of Circus Dome of Circus(计算几何基础+三分)
Sample Input11.00 0.00 1.0021.00 0.00 1.000.00 1.50 0.5031.00 0.00 1.000.00 1.50 0.50-0.50 -0.50 1.00Sample Output3.000 1.5002.000 2.0002.000 2.000原创 2020-11-18 10:20:10 · 138 阅读 · 0 评论 -
HDU 4355 Party All the Time(三分)
const int N=5e4+5; int i,j,k; int n,m,t; double a[N],x[N];double calc(double pos){ double ans=0; for(int i=1;i<=n;i++) ans+=a[i]*pow(fabs(pos-x[i]),3); return ans;}int main(){ //IOS; int num=0; rush(){ ...原创 2020-11-18 09:57:16 · 176 阅读 · 0 评论 -
HDU 4135 Co-prime(容斥原理+质因数分解)
求在一个区间 [a,b] 内,有多少个数与 n 互质将 n 质因数分解,利用容斥原理求解在 [1,a-1] , [1,b] 中有多少个数可以被 n 整除,剩下的数就是与 n 互质的数了 int i,j,k; ll n,m,t; //int a[N]; vector<int> prime;void get_factor(int n){ prime.clear(); for(int i=2;i*i<=n;i++)...原创 2020-11-07 10:45:44 · 189 阅读 · 0 评论 -
HDU 2841 Visible Trees(容斥原理+质因数分解)
有个人站在坐标 (0,0) 点处,从 (1,1) 开始有树,问在 (n,m) 的方格内,能看到多少棵树因为从原点看去,我们可以想象成一条正比例函数图像,即 y=kx ,当我们去看 (x,kx) 点时,会被 (x/gcd,kx/gcd) 的树所遮挡,所以我们只需要知道 gcd(x,y)=1 时的树有多少个即可就上述所说 gcd(x,kx)=1 时,当满足x=1 / k 不为整数的时候,而且当 x=1 时所可以看到的树,在 x=2 时不会再次看到,即不会有重复所以可以枚举 x ,对于...原创 2020-11-07 10:15:47 · 217 阅读 · 0 评论 -
HDU 2204 Eddy‘s爱好(容斥原理)
我觉得题目改成求有多少个 m ,可以写成 m^k<=n 比较好理解因为 n <=1e18 而 2^60>1e18 ,所以=1,在把指数变得更小就没有意义了所以打表素数到 60 为止因为 2*3*5*7>60 所以可知最多指数由三位质数组成所以先求出 n 最多可以承受的指数范围(即不变为 1 的指数范围)剩下的交给容斥就好了const int prime[18]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,5...原创 2020-11-05 18:31:46 · 111 阅读 · 0 评论 -
HDU 1796 How many integers can you find(容斥原理模板)
有 m 个数字,求 1~n-1 中有多少个数可以被这 m 个数字整除在一个区间 [1,n] 内,可以被 x 整除的数有 n/x 个,但是当有多个 xi 时,会有重合的部分,所以计算所选取的 x[] 的 lcm ,利用容斥原理,很容易解决const int N=3e5+5; int i,j,k; int n,m,t; int a[N];int main(){ IOS; while(cin>>n>>m){ ...原创 2020-11-05 17:01:55 · 151 阅读 · 0 评论 -
HDU 2802 F(N)(寻找循环节)
按照题意打表 1e9 一定超时,所以一定存在规律,将上述公式化简为 f(n)=f(n-2)+3*n*(n-1)+1 后进行打表,找到循环节之后,问题就解决了const int N=1e5+5;const ll mod=2009; int n,m,t; int i,j,k; int a[N]; ll dp[N],cur;void init(){ dp[1]=1; dp[2]=7; for(i=3;i<=100000;i...原创 2020-10-20 21:40:48 · 202 阅读 · 0 评论 -
HDU 3579 Hello Kiki(中国剩余定理)
给出一个数 n ,再分别给出 2n 个数 a[i],和 r[i],表示n个同余方程组:x mod a[i]= r[i] , 求满足方程组的最小正整数 x,若不存在 输出 -1const int N=100+5;const ll mod=21252; int n,m,t; int i,j,k; ll a[N],r[N];ll ex_gcd(ll a,ll b,ll &x,ll &y) //ax+by=gcd(a,b){ ll g...原创 2020-10-20 17:57:32 · 220 阅读 · 1 评论 -
POJ 3370 && HDU 1808 Halloween treats (鸽巢原理)
有 m 个小孩,n 个数,每个数代表糖果的数量,是否能够拿任意数量的糖果 sum,使得 sum%m==0 ,如果有输出下标 i(可能有多组输出样例,输出任意一种),不能的话输出 no sweetsconst int N=1e5+5; int n,m,t; int i,j,k; int a[N]; int sum[N] , pos[N]; void init(){ ms(sum,0); ms(pos,-1); sum[0...原创 2020-10-15 10:30:48 · 170 阅读 · 0 评论 -
HDU 1698 Just a Hook(lazy)
const int N=1e5+5; int n,m,t; int i,j,k; //int a[N]; struct Node { int l,r; int lazy; void update(int x) { lazy=x; } }node[N<<2];void build(int l,int r,int id){ ...原创 2020-09-28 23:07:33 · 157 阅读 · 0 评论 -
HDU 1754 I Hate It(区间查询+单点修改)
const int N=2e5+5; int n,m,t; int i,j,k; int a[N]; struct Node { int l,r; int maxx; }node[N<<2];void push_up(int id){ node[id].maxx=max(node[id<<1].maxx,node[id<<1|1].maxx);}void bui...原创 2020-09-28 21:58:09 · 156 阅读 · 0 评论