自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(66)
  • 收藏
  • 关注

转载 Codeforces Round #529 (Div. 3) C. Powers Of Two

http://codeforces.com/contest/1095/problem/C题意:给n找出k个2的幂,加起来正好等于n。例如 9,4:9 = 1 + 2 + 2 + 4思路:首先任何数都能表示成2的次幂的和,其次很容易发现,n和k都是二的次幂的情况是最基础的,因为可以分成k个n/k,而n/k一定是二的次幂。所以,可以得出结论,只要n是2的次幂,且k<=n,一...

2018-12-30 00:18:00 130

转载 lintcode - 不同的子序列

给出字符串S和字符串T,计算S的不同的子序列中T出现的个数。子序列字符串是原始字符串通过删除一些(或零个)产生的一个新的字符串,并且对剩下的字符的相对位置没有影响。(比如,“ACE”是“ABCDE”的子序列字符串,而“AEC”不是)。样例给出S ="rabbbit", T ="rabbit"返回 3 1 class Solution { ...

2017-09-30 01:04:00 129

转载 lintcode - 删除数字

1 class Solution { 2 public: 3 /* 4 * @param A: A positive integer which has N digits, A is a string 5 * @param l: Remove k digits 6 * @return: A string 7 *...

2017-09-29 10:44:00 162

转载 lintcode - 统计比给定整数小的数的个数(两种方法)

1 class Solution { 2 public: 3 /* 4 * @param A: An integer array 5 * @param queries: The query list 6 * @return: The number of element in the array that are smal...

2017-09-26 22:41:00 126

转载 lintcode - 生成括号

1 class Solution { 2 public: 3 /* 4 * @param n: n pairs 5 * @return: All combinations of well-formed parentheses 6 */ 7 vector<string> generateParenthe...

2017-09-25 19:02:00 98

转载 lintcode - 房屋染色

1 class Solution { 2 public: 3 /* 4 * @param costs: n x 3 cost matrix 5 * @return: An integer, the minimum cost to paint all houses 6 */ 7 const int inf = 0...

2017-09-24 10:06:00 117

转载 lintcode - 恢复ip地址

1 class Solution { 2 public: 3 /* 4 * @param s: the IP string 5 * @return: All possible valid IP addresses 6 */ 7 vector<string> restoreIpAddresses(str...

2017-09-18 20:11:00 109

转载 lintcode - 被围绕的区域

1 class Solution { 2 public: 3 /* 4 * @param board: board a 2D board containing 'X' and 'O' 5 * @return: nothing 6 */ 7 bool flag[220][220]; 8 vector&l...

2017-09-18 20:09:00 126

转载 Lintcode 摊平嵌套的列表

1 /** 2 * // This is the interface that allows for creating nested lists. 3 * // You should not implement it, or speculate about its implementation 4 * class NestedInteger { 5 * ...

2017-09-13 00:45:00 100

转载 codeforces 620D Professor GukiZ and Two Arrays

1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn = 2000 + 50; 6 7 const long long inf = 1e18; 8 9 int n, m; 10 11 long long suma, ...

2017-08-29 23:59:00 131

转载 lintcode 解码方法

简单的动态规划 1 class Solution { 2 public: 3 4 /* 5 * @param s: a string, encoded message 6 * @return: an integer, the number of ways decoding 7 */ 8 int ...

2017-08-16 18:49:00 630

转载 Tensorflow安装教程-Win10环境下

背景:最新版的Tensoflow已经支持Python3.6首先,下载并安装Anaconda3 内置Python3.6的版本https://www.continuum.io/downloads安装时不要修改它的推荐选项接着下载并安装CUDA 8.0https://developer.nvidia.com/cuda-downloads然后下载并安装cuDNN 5.1(官方推...

2017-07-08 09:29:00 107

转载 lintcode-dfs实现二叉树的层序遍历

1 class Solution { 2 /** 3 * @param root: The root of binary tree. 4 * @return: Level order a list of lists of integer 5 */ 6 struct node{ 7 TreeNode...

2017-06-10 01:06:00 129

转载 交叉字符串

给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。样例比如 s1 ="aabcc"s2 ="dbbca"- 当 s3 ="aadbbcbcac",返回 true.- 当 s3 ="aadbbbaccc", 返回 false.dp[i][j][k] 代表 当到了s3的第i位时,s1的到了第j位 s2到了第k位。 因为i是一直向前循环...

2017-06-07 12:02:00 83

转载 二叉树非递归方式遍历

1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 /** 6 * Definition of TreeNode: 7 * class TreeNode { 8 * public: 9 * int val;10 * TreeNode *left,...

2017-06-07 00:33:00 74

转载 Uva1149

每个bin最多只能放两个,所以最佳的贪心策略是从大的开始放,如果有空间放第二个,尽量放最大的。 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn = 100000 + 10; 6 7 int t; 8 9 int n,l;10 1...

2017-05-22 23:47:00 117

转载 Uva1608

如果一个序列的所有子序列中均存在至少一个元素,这个元素在该子序列中只出现一次,则这个序列non-boring。当一个序列[x,y]中没有元素只出现一次,那么该序列不符合要求,如果有的话,设为第i个元素,则 只要[x,i-1]和 [i+1,n] 符合要求,则该序列符合要求。在O(N)的时间内预处理一个元素左右离它最近的相同元素的位置,即可在O(1)时间内查询是否这个元素在给定序列中...

2017-05-18 23:44:00 120

转载 Uva12174

1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn = 5000000; 6 7 int t; 8 9 int s,n;10 11 int a[maxn+10];12 13 int res[maxn+10];14 1...

2017-05-16 23:49:00 120

转载 UVa11093

//当汽车从第i个加油站到第j个加油站无法继续走下去的时候,这时候[i,j]区间的所有加油站都无法作为起点,因为当我们到第k个加油站的时候,起码是带着>=0的油去的,现在不带油直接从第k个开始肯定更不行了。 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 const int maxn...

2017-04-24 19:08:00 108

转载 合并果子思路

有N堆数量不同的果子,我们每次最多可以合并K堆果子,消耗体力值为合并这些堆的果子数之和,设计耗费体力最少的方案把N堆果子合并为一堆。如果我们能每次合并K堆的话,显然按照哈弗曼的思想,每次合并最小的K堆直到合并完是最优解。但很显然有不能每次合并K堆的情况,比如N=8,K=3的情况,最后剩下两堆。从N堆到1堆,减少的堆数是N-1堆,我们每次最多只能让整体减少K-1堆,所以,当 (N-...

2017-04-21 23:55:00 282

转载 UVa1471

保留有价值的数字的做法,实际上这道题因为n只有1e5,所以不需要这种优化。 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 const int maxn=200000; 6 7 using namespace std; 8 9 int t;10 11 in...

2017-04-18 14:49:00 140

转载 Uva11572

读入可以不需要存入数组#include<bits/stdc++.h>#define inf 0x3f3f3f3f//const int maxn=;using namespace std;int t;int n;int main(){ scanf("%d",&t); while(t...

2017-04-17 21:22:00 92

转载 Uva11134

#include<bits/stdc++.h>#define inf 0x3f3f3f3fconst int maxn=5000;using namespace std;int n;struct rook{ int x1,y1; int x2,y2; int id; ...

2017-04-11 19:52:00 131

转载 Uva10755

在题中的A*B*C的矩形中,当确定X1,X2,Y1,Y2时,1->z的子矩形的和为sum[x2][y2][1] -(sum[x1-1][y2][1] + sum[x2][y1-1][1] -sum[x1-1][y1-1][1] + sum[x2][y2][z+1] - sum[x1-1][y2][z+1] -sum[x2][y1-1][z+1] + sum[x1-1][y1-1...

2017-04-09 16:57:00 86

转载 Floyd判圈法

---恢复内容开始---http://blog.csdn.net/ruoruo_cheng/article/details/53100656---恢复内容结束---转载于:https://www.cnblogs.com/GeniusYang/p/6659462.html

2017-04-02 17:53:00 71

转载 Java泛型-通配符的上限和下限问题

Java的泛型中,通配符可以设置上限和下限。上限:<? extends T> ?是T和T的子类下限:<? super T> ?是T和T的父类怎么看待这个上限和下限呢 首先应该想 其实对于Java来说 <? extends T> <? super T> 是两个确定的类型,因为它不可能由你的赋值完了再确定吧。所以,对于<? e...

2017-03-18 22:42:00 378

转载 Codeforces 384E-线段树+dfs序

如果这题只传到儿子不继续向下就是裸的dfs序+线段树,继续往下传的还改变正负号,我们可以根据它的层数来确定正负号 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 #define lson (id<<1) 6 7 #define rson ((i...

2016-11-10 10:36:00 110

转载 codeforcesRound378C-dfs+树状数组

分成K个块,每个块内部dfs解决,然后用树状数组统计第i个元素前面有多少怪物已经消失,来计算当前的下标 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 const int maxn=1000; 6 7 using namespace std; 8 ...

2016-11-01 08:34:00 122

转载 一个小技巧总结

当题目是区间求和或者其他区间询问时,如果询问是离线的,而且询问涉及 l-r内有多少个不同的xxx。这个xxx可以是不同的数 不同的gcd 不同的异或和 等等这时候我们可以把询问按右端点排序,然后把a[i]的出现永远存在靠右的一边 当i==q.r的时候 求答案有三道例题hdu3333 1 Problem : 3333 ( Turing Tree ) Jud...

2016-10-25 14:29:00 90

转载 codeforces540E-树状数组求逆序对

1-1e9的数据范围 但有1e5个区间 所以可以考虑把没有涉及到的区间缩成一个点 然后树状数组求逆序对 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 const int maxn=1000000; 6 7 using namespace std; 8 9 t...

2016-10-22 20:14:00 130

转载 codeforces597C-树状数组优化dp

因为整个序列为一个1-n的排列,所以可以这样dp dp[i][j]代表长度为i,以数字j结尾的子序列 dp[i][j]=dp[i-1][1,2,3...j-1]; 这道题的答案就是 dp[k+1][1...n];用树状数组求一下前缀和 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 ...

2016-10-19 09:41:00 148

转载 Treap模板

#include<bits/stdc++.h>#define inf 0x3f3f3f3fconst int maxn=10000;using namespace std;struct node{ node* left; node* right; int value,fix,s,cnt; node(int _...

2016-10-18 17:43:00 54

转载 hdu5884

#include <cstdio>#include <queue>#include <algorithm>#include <string.h>//#include <bits/stdc++.h>using namespace std;const int maxn=100000...

2016-10-04 10:47:00 108

转载 codeforces772C

给一段序列,给你去掉所有数字的顺序,输出每去掉一个数,当前联通的子序列的最大值。倒着来,每次插入一个数,然后求联通的最大值,线段树每个节点标记一下,区间的左右是否插入了数字,还有如果有数字从左边/右边开始连续子序列的值,还有这个节点的区间是否连续。 1 #include <cstdio> 2 3 #include <algorithm&g...

2016-10-03 16:23:00 311

转载 hdu5726-GCD-ST表+二分

先用st表处理出所有l-r的GCD值,然后二分求得这些值一共出现了多少次。 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 const int maxn=100000; 6 7 using namespace std; 8 9 typedef p...

2016-08-14 10:01:00 128

转载 hdu1166-敌兵布阵-分块

把区间分成√n份降低复杂度. 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 const int maxn=50000; 6 7 const int seg=223; 8 9 using namespace std;10 11 int t,n,icase,...

2016-08-12 20:45:00 92

转载 矩形面积并-扫描线 线段树 离散化 模板-poj1151 hdu1542

今天刚看到这个模板我是懵逼的,这个线段树既没有建树,也没有查询,只有一个update,而且区间成段更新也没有lazy标记....研究了一下午,我突然我发现我以前根本不懂扫描线,之所以没有lazy标记,是因为扫描线每次只查询1-n里的所有有值的区间长度,因为只要1-n,而不会查找到某些小区间,所以也就不用lazy,而且也无需查询,每次插入完只需要 知道sum[1]是多少即可。所以一个upd...

2016-08-11 21:01:00 102

转载 完全认识树状数组

我搜遍了网络,只在topcoder的网站上了解到树状数组这个结构是在设计压缩算法时被发现的。这个数据结构真是天才的构想,膜拜!树状数组的基础是一个被构造出来的式子:C[i]=A[i]+A[i-1]+....+A[i-2^k+1];k代表i的二进制的最后连续0的个数 比如 对于1000和101000,k=3。至于这个式子是怎么被构造出来的,k为什么要代表这个。因为二进制的思想。根据...

2016-08-10 15:36:00 75

转载 Uvalive-4494-(数位dp)

题意:求a->b中的二进制出现过多少个1,很显然的数位dp,对于某一位来说,如果这位是0,那么dp[i]=dp[i-1] 如果这一位是1 那么dp[i]=dp[i-1]+1<<(pos-1)+(后缀+1);dp[pos][now] /pos表示当前的位,now表示现在是1还是0 1 #include<bits/stdc++.h> 2 ...

2016-08-08 22:18:00 90

转载 Uva12210-A Match Making Problem

对于每个数字二分找到大于等于它的数,再暴力找到第一个小于它的数 1 #include<bits/stdc++.h> 2 3 #define inf 0x3f3f3f3f 4 5 const int maxn=10000; 6 7 using namespace std; 8 9 int b,s; 1...

2016-08-08 19:31:00 69

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除