- 博客(39)
- 收藏
- 关注
原创 字节跳动0825笔试场第二题合法表达式(动态规划)
很明显是一道动态规划的题,刚开始天真想用一维dp[n]来解决,结果发现想的太简单,比如(40)4就是不合法的,所以要用二维动态规划分情况来考虑,dp[i][0]表示长度为i且最后一位为数字(0-9)的个数,dp[i][1]表示长度为i且最后一位为右括号的个数。状态转移方程为: dp[i][0]=(dp[i-1][0]*10+(dp[i-2][0]+dp[i-2][1])*10*2LL)//...
2018-08-26 21:32:00
1045
原创 hdu 1576 ex_gcd
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2805 Accepted Submission(s): 2073 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n
2015-06-22 15:41:30
787
原创 POJ 1061 扩展gcd 线性同余方程
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95733 Accepted: 17846 Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止
2015-06-22 14:09:58
746
原创 2015东北四省赛 L题 线性筛+积性函数 求因子和
Given an interval [x, y], calculate the sum of all the factors of the whole integers from x to y (include x and y). Let describe it officially. Let's definite f (i) is the sum of factors of i, you sh
2015-06-17 20:46:19
1512
原创 hdu 5269 01字典树
ZYB loves Xor I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 306 Accepted Submission(s): 151 Problem Description Memphis loves xo
2015-06-14 19:00:14
600
原创 poj 3764 字典树求异或最大值
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4290 Accepted: 952 Description In an edge-weighted tree, the xor-length of a path p
2015-06-14 16:56:43
773
原创 poj 2001 字典树入门题(数组实现模板)
#include #include #include #include using namespace std; int ch[20*1000+200][27]; int sz; int val[20*1000+200]; char s[1010][40]; void init() { sz=1; memset(ch,0,sizeof(ch));
2015-06-14 14:52:23
447
原创 2015 辽宁省赛G题 边权排序
1576: Good Sequence 时间限制: 1 Sec 内存限制: 128 MB 提交: 12 解决: 5 [提交][状态][讨论版] 题目描述 This is the definition of the good sequence: Suppose sequence the length which is n is : A1,A2...An. If meet the
2015-06-11 23:53:54
733
原创 2015 辽宁省赛C题 dp+单调队列优化
#include #include #include #include #define ll long long using namespace std; int n,k; const int maxn=1e5+10; ll sum[maxn]; int a[maxn]; ll dp[maxn]; ll s[maxn]; int q[maxn]; ll ans[maxn]; //void de_
2015-06-11 17:18:58
614
原创 bzoj 2243 树链剖分 染色
2243: [SDOI2011]染色 Time Limit: 20 Sec Memory Limit: 512 MB Submit: 3205 Solved: 1238 [Submit][Status][Discuss] Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1、将节点a到节点b路径上所有点都染成颜色c; 2、询问节点a到节点b路径上的颜
2015-06-03 23:38:51
406
转载 cf 546 E dinic网络流优化模板
/* Author :HRW 思路:建图,最大流,注意反向边,容量,流量为0 建源点,汇点, 最后输出路径保证每条边的流量都要输出,只需之前统计有哪些边流量发生了变化 */ #include using namespace std; const int N=305; const int inf=0x3f3f3f3f; struct Edge { int from,
2015-06-03 18:36:09
473
原创 cf 547B 单调栈
#include #include #include #include using namespace std; const int maxn=2e5+10; int lst[maxn],nxt[maxn]; int a[maxn],s[maxn]; int n; int tp; int ans[maxn]; void getPos(int i) { lst[i
2015-06-03 16:10:09
703
原创 cf 547C 容斥原理
#include #include #include #include #define ll long long using namespace std; const int N =500000+10; vector fac[N]; int vis[N],cnt[N],v[N]; int n,q,a[N]; ll ans; int x; void dfs(int u,in
2015-06-03 00:36:21
953
原创 spoj375 重学树链剖分
题意:给定一棵树,告诉了每条边的权值,然后给出两种操作: (1)把第i条边的权值改为val#include #include #include #include using namespace std; //siz[v]表示以v为根的子树的节点数 //dep[v]表示v的深度(根深度为1) //top[v]表示v所在的链的顶端节点 //fa[v]表示v的父亲 //son[v]表示与v在同一重链
2015-06-02 01:01:46
540
原创 poj 1741 树的点分治
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12913 Accepted: 4128 Description Give a tree with n vertices,each edge has a length(positive integer les
2015-06-01 20:22:13
431
转载 hdu 1890 splay 区间翻转
#include #include #include using namespace std; const int maxn=100000+100; int n; struct SplayTree { int pre[maxn],ch[maxn][2],size[maxn],rev[maxn],root; void Update_Rev(int r) {
2015-05-29 10:18:13
625
原创 hdu 3487 区间翻转
#include #include #include #include #define key_value ch[ch[root][1]][0] #define ls(r) ch[r][0] #define rs(r) ch[r][1] #define ll long long const int N=300015; using namespace std; int n,q; int sz[N]
2015-05-28 19:10:09
588
原创 bzoj 1208 splay基本操作(插入,查询,删除)
1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5062 Solved: 1945 [Submit][Status][Discuss] Description 最近,阿Q开了一间宠物收养所。收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物。每个领养者都希望领养到自己满意
2015-05-21 16:26:27
1403
原创 bzoj 1588 splay入门题 (插入,查询)
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Submit: 10070 Solved: 3462 [Submit][Status][Discuss] Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况。 Ti
2015-05-21 14:01:51
624
原创 poj 2104 区间第K小 主席树入门题
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 40933 Accepted: 13377 Case Time Limit: 2000MS Description You are working for Macrohard com
2015-05-21 10:31:13
462
原创 hdu 5230 整数划分+dp+滚动数组
ZCC loves hacking Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) Total Submission(s): 223 Accepted Submission(s): 92 Problem Description Now, a Codefi
2015-05-20 01:43:09
577
原创 hdu 5229 必胜策略
题意 ZCC有N个字符串,他正在和Miss G.用这N个字符串玩一个小游戏。ZCC会从这N个串中等概率随机选两个字符串(不可以是同一个)。然后,ZCC和Miss G.轮流操作。Miss G.总是先操作的。在每轮中,操作者可以选择操作A或操作B。 操作A:在两个串中选择一个当前非空的串,然后在这个串的末尾删去一个字符。 操作B: 若当前两个串完全相同且非空,则可以使用这个操作。此时两个串
2015-05-19 21:33:57
489
原创 hdu 5228 暴力枚举
#include #include #include #include using namespace std; int has[13*4]; char s[5]; int main() { int t; cin>>t; while(t--) { memset(has,0,sizeof(has)); for(int i=
2015-05-19 00:21:49
912
原创 hdu 2993 斜率优化+二分查找
#include #include #include #include #include #define ll long long using namespace std; const int MAXN=100010; ll sum[MAXN]; int q[MAXN]; int top; long long cross(int a,int b,int c) {
2015-05-14 16:31:19
426
原创 后缀数组模板代码
#include #include #include using namespace std; //sa[i] : 表示 排在第i位的后缀 起始下标 //rank[i] : 表示后缀 suffix(i)排在第几 //height[i] : 表示 sa[i-1] 与 sa[i] 的LCP 值 //h[i]: 表示 suffix(i)与其排名前一位的 LCP值 const int N = int(2e
2015-05-13 16:47:20
436
原创 poj 1743 后缀数组+二分判定
#include #include #include #include using namespace std; //sa[i] : 表示 排在第i位的后缀 起始下标 //rank[i] : 表示后缀 suffix(i)排在第几 //height[i] : 表示 sa[i-1] 与 sa[i] 的LCP 值 //h[i]: 表示 suffix(i)与其排名前一位的 LCP值 const int N
2015-05-13 16:46:11
390
原创 hdu 5223 GCD 思维题
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 506 Accepted Submission(s): 227 Problem Description In mathematics, the greate
2015-05-12 20:04:44
552
原创 hihocoder 1166 期望dp+高斯消元
#1166 : 交换代数 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 少女幽香这几天正在学习交换代数,然而她什么也没有学会,非常痛苦。于是她开始玩起了一个简单的小游戏,来放松一下。 地面上一共有n个球,一开始有一些是黑色的,有一些是白色的。每次她随机选择一个区间(一共有n(n+1)/2个区间,每个区间有相等的概率被选
2015-05-11 23:40:41
716
原创 hiho 11 B-益智游戏(随机数+暴力求解+分解质因子)
益智游戏 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 幽香今天心情不错,正在和花田里的虫子玩一个益智游戏。 这个游戏是这样的,对于一个数组A,幽香从A中选择一个数a,虫子从A中选择一个数b。a和b可以相同。她们的分数是a*b的因子的个数。 幽香和虫子当然想要获得尽可能的高的分数,你能告诉她们应该选择哪两个数吗。 由于
2015-05-05 23:28:23
474
原创 RMQ模板(一般结合后缀数组使用)
#include #include #include #include #include using namespace std; int a[100]; int dp[100][15];//2^15足够大 int rmq(int s,int v) { int k=(int)(log(2.0*(v-s+1)*1.0)); return min(dp[s][k],dp[v-(1<<
2015-05-03 17:22:56
376
原创 CF 459E && 市赛I题
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Alt
2015-05-03 11:05:35
581
原创 hdu 3507 斜率dp优化
#include #include #include #include using namespace std; const int maxn=500000+10; int dp[maxn],q[maxn],sum[maxn]; int n,m; int getdp(int i,int j) { return dp[j]+m+(sum[i]-sum[j])*(sum[i]-sum[j])
2015-05-02 23:14:33
381
原创 hdu 2829 重学四边形不等式优化
#include #include #include #include #define ll long long using namespace std; const int maxn=1010; const int inf=1e9+7; ll cost[maxn][maxn],dp[maxn][maxn],s[maxn][maxn]; void DP(int n,int m) { fo
2015-05-02 20:56:20
330
原创 2015编程之美资格赛2题—区间dp
题目2 : 回文字符序列 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定字符串,求它的回文子序列个数。回文子序列反转字符顺序后仍然与原序列相同。例如字符串aba中,回文子序列为"a", "a", "aa", "b", "aba",共5个。内容相同位置不同的子序列算不同的子序列。 输入 第一行一个整数T,表示数据
2015-04-19 01:23:21
562
原创 hdu 5201 容斥原理+组合数取模
The Monkey King Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 207 Accepted Submission(s): 64 Problem Description As everyone known
2015-04-09 20:56:13
569
原创 hdu 5200 离线处理+思维
#include #include #include #include using namespace std; const int maxn=50000+10; struct node { int id; int val; }p[maxn],q[maxn]; int vis[maxn],ans[maxn]; bool cmp(node a,node b)
2015-04-08 21:39:00
439
原创 hdu 5199 map水题
#include #include #include #include #include using namespace std; mapa; int main() { int n,m; while(~scanf("%d%d",&n,&m)) { int x; for(int i=1;i {
2015-04-08 20:59:32
474
原创 POJ 1012 约瑟夫环推公式
#include #include #include #include using namespace std; int n,k; bool ok(int m) { int s=0; for(int i=1;i { s=(s+(m-1))%(n-i+1); if(s return 0
2015-04-08 20:09:31
427
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅