自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 hdu 3664 DP 递推

思路:dp[i][j] 表示序列长度是i的情况下,k-value 是j 的排列数。j可以通过上一层的两种状态转移而来。一是上一层已经是j的,只能在最后插入或者找ai>i的置换。二是上层是j-1的,那么可以找出ai<=i的进行置换,一共是i-(j-1)种。递推关系式是dp[i][j] = dp[i-1][j]*(j+1) + dp[i-1][j-1]*(i-j);#include &lt...

2018-04-25 20:04:37 274

原创 fzu 2221 Running man 数学 思维

思路:在给定两队人数的情况下,三局两胜制,相同人数下runningman获胜,无论对手怎么安排,问runningman会不会胜利。假设对方的人数是m,分为奇数偶数两种情况讨论。极端情况下,对方用0去对待runningman人数最多的一次。剩下两局中runningman要赢一局。对方安排  --- 0 , x , y ,x>=y.man        --- a , b , c ,a>=...

2018-04-23 15:18:39 362

原创 Cutting Game FZU - 2268 二进制

题意:给定一块长度是n的金块,求最少分成多少块,使得1-n的所有数字都可以表示出来。这一个是对二进制的理解。#include <cstdio>using namespace std;int main() { int nTest; scanf("%d", &nTest); for(int t = 1; t <= nTest; t++) { ...

2018-04-23 14:45:33 259

原创 Just Pour the Water ZOJ - 2974 矩阵快速幂

思路:用一个N*N的矩阵的第一行来记录水量。另外一个矩阵记录转移的方式,不是很好描述,具体看代码。当k是0的时候,水量都给了自己。#include <iostream>#include <cstdio>#include <cstring>using namespace std;int n;const int N = 25;struct Matrix ...

2018-04-22 21:37:34 254

原创 ZOJ 3497 Mistwald 矩阵快速幂

思路:先将二维的坐标转换成一维的坐标,然后用矩阵存储,然后进行pci路径转移。关键点就是不能从出口处转移。#include <string>#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 26;int n,m;...

2018-04-22 21:31:43 168

原创 51Nod 1163 最高的奖励 贪心

思路1:这个是非常好的一道贪心题目!每个任务有一个最晚完成时间,用一个队列来维护到当前时间t的时候,一共完成了哪些任务。 遇到最晚完成时间大于t的,直接加入队列,与t相等的话,则置换一下,使得队列里面的值最大。#include <bits/stdc++.h>using namespace std;typedef long long ll;struct node { int...

2018-04-22 21:05:41 216

原创 51Nod 1133 不重叠的线段 贪心

1133 不重叠的线段 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注X轴上有N条线段,每条线段有1个起点S和终点E。最多能够选出多少条互不重叠的线段。(注:起点或终点重叠,不算重叠)。例如:[1 5][2 3][3 6],可以选[2 3][3 6],这2条线段互不重叠。Input第1行:1个数N,线段的数量(2 <= N <= 1000...

2018-04-22 20:48:02 176 1

原创 51Nod 1428 活动的安排 贪心

1428 活动安排问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注有若干个活动,第i个开始时间和结束时间是[Si,fi),同一个教室安排的活动之间不能交叠,求要安排所有活动,最少需要几个教室? Input第一行一个正整数n (n <= 10000)代表活动的个数。第二行到第(n + 1)行包含n个开始时间和结束时间。开始时间严格小于结束...

2018-04-22 20:33:39 149

原创 51Nod 1432 独木舟 贪心算法

思路:做了一些贪心的题目,总结出来,对于问题的定义是至关重要的。 该问题是使得最少的船将全部人载走,等价定义是每一个船载的人尽可能的多,也就是使每个船尽可能有两个人配对成功。那么进行一下排序,最大与最小组合就好了。#include <bits/stdc++.h>using namespace std;vector<int> vec;int main(){ i...

2018-04-22 20:25:22 309

原创 HDU 3652 数位DP

首先知道一个定理: (a+b)%m = (a%m+b%m)%m;思路单独拿出一位来看,是否能被13整除或者从cnt到该位有没有出现出13整除量使用mod记录,是否出现过13用have记录,have==1是前一位是1,have==2,已经出现过13.#include <iostream>#include <algorithm>#include <cstring&gt...

2018-04-13 21:58:27 209

原创 hdu Building Shops DP 递推

Building ShopsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1863    Accepted Submission(s): 665Problem DescriptionHDU’s n classrooms are on ...

2018-04-13 20:36:52 181

原创 FZU 2109 mountain number 数位dp

思路:所有的数位dp长一个模样。考虑一下,在某一位上的往下递归,可能和哪几个条件有关。1.位数2.前一位的值3.当前是奇数位还是偶数位。* 注意前导零的时候后,默认pre是最大值9。根据数位dp模板即可写出#include <cstdio>#include <iostream>#include <algorithm>#include <cstring...

2018-04-13 20:28:30 151

原创 51Nod 1007 正整数分组 递推 DP

题目链接思路:问题是:将所有的正整数分为两组,使得两组的差最小。再将问题转化一下。在使用n个数,分为两组的的所有情况下的差的最小值。dp[i][j]代表用了前i个数,j这个差有没有出现过。那么n个数分为两组的差的全部情况可以有num[n]和dp[n-1][0-maxn]推出。#include <bits/stdc++.h>using namespace std;const in...

2018-04-13 19:47:17 182

原创 ZOJ 4020 Traffic Light 浙大校赛 BFS

题目链接思路 这个题的思路很清楚,只不过第一次用到了三维数组。记录一下吧。#include <bits/stdc++.h>using namespace std;const int N = 1e5+10;int sx,sy,fx,fy;int n,m;int dir[2][2][2] = {{{1,0},{-1,0}},{{0,1},{0,-1}} } ;struct node {

2018-04-13 19:25:09 354

原创 FZU - 2150 两点BFS 技巧

题目链接 思路 题意非常简单,最多两个点同时开始烧,最少的花费时间。 暴力枚举一下,我的做法是使用一个标记来记录两个火堆的到达时间以及各自烧了多少。写完之后看了题解。发现有更简单的做法就是不考虑哪个火堆烧的,只记录是否被烧到以及烧到该点的最短时间。#include <iostream>#include <cstdio>#include <algorithm>#include<queue>

2018-04-13 18:13:32 233

原创 1091 线段的重叠 区间重叠

题目链接思路 保证思路的有序性。 如果拿出来每一条边与其他边进行比较,那么一定可以得出答案。 但是一条边[l,r]只能和与它有交集的边产生可能。那么进行排序,按照左端点,在某条边的l大于当前选择的边的r时break。 能否在O(n)的算法处理呢? 也就是说,枚举的区间是有选择性的。假设当前选定的区间是A。 那么之后的区间有ECDE四种情况,再加上 无交集的情况。 1.如果是B,C,E,

2018-04-13 17:19:21 319

原创 Codeforces 6A 三角形

给定四条边,看是否构成三角形。记一个规律,就是连续的三个数最可能构成三角形。#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;algorithm&gt;using namespace std;int main(){ int num[4]; for (int i=0;i&lt;4;i++) ...

2018-04-08 22:59:19 214

原创 51Nod 1009 1042 数位DP

题目链接 给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数。 例如:n = 12,包含了5个1。1,10,12共包含3个1,11包含2个1,总共5个1。 Input 输入N(1 <= N <= 10^9) Output 输出包含1的个数 Input示例 12 Output示例 5思路: 初学数位dp第二题。

2018-03-31 17:52:58 147

原创 51Nod LCS 最长公共子序列 打印路径

题目 给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的)。 比如两个串为: abcicba abdkscab ab是两个串的子序列,abc也是,abca也是,其中abca是这两个字符串最长的子序列。 Input 第1行:字符串A 第2行:字符串B (A,B的长度 <= 1000) Output 输出最长的

2018-03-31 17:14:26 235

原创 Codeforces 618B - Guess the Permutation

题目链接思路:第i行的最大值就是数组中的第i个。知道这个规律就可以暴力找了。#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;algorithm&gt;#include &lt;cstring&gt;using namespace std;int n;int nums[60][60];int line[60];...

2018-03-29 23:06:54 192

原创 POJ 1328 区间点选择 贪心

题目链接题目大意:选取最少的放雷达的点,使得每一个点都可以被探测到。思路:1.错误的贪心算法#include &lt;stdio.h&gt;#include &lt;string.h&gt;#include &lt;stdlib.h&gt;#include &lt;math.h&gt;#include &lt;algorithm&gt;#include &lt;iostream&gt;...

2018-03-24 23:32:25 206

原创 蓝桥杯 十六进制转八进制 字符串处理

问题描述   给定n个十六进制正整数,输出它们对应的八进制数。 输入格式   输入的第一行为一个正整数n (1&lt;=n&lt;=10)。   接下来n行,每行一个由0~9、大写字母A~F组成的字符串,表示要转换的十六进制正整数,每个十六进制数长度不超过100000。 输出格式   输出n行,每行为输入对应的八进制正整数。  【注意】 ...

2018-03-11 14:57:46 384

原创 LeetCode 139. Word Break 字符串 DP

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may a...

2018-02-28 13:24:36 267

原创 LeetCode 72. Edit Distance 115. Distinct Subsequences 字符串 DP

72. Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operati...

2018-02-28 11:03:00 145

原创 LeetCode 90. Subsets II 递归

Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,2]

2018-02-28 10:42:56 220

原创 LeetCode 93. Restore IP Addresses 递归,分治

Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given “25525511135”, return [“255.255.11.135”, “255.255.111.35”]. (O

2018-02-28 09:47:56 225

原创 LeetCode 96. Unique Binary Search Trees 1&2

Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 题目链接题目描述 给定n个不同元素,求可以构成多少种BST?思路 这一

2018-02-27 11:49:22 150

原创 二叉树的遍历 迭代 LeetCode 94 144 145

这里简要介绍一下树的迭代方式遍历前序遍历 leetcode 94 使用栈来模拟递归,出栈时候访问结点。前序遍历先访问左子树,再访问右子树,那么入栈时相反,即先入右子树,再入左子树。那么出栈的时候就是前序遍历的顺序。class PreOrder { ArrayList<Integer> result = new ArrayList<>(); public ArrayList<I

2018-02-27 11:23:16 146

原创 数据结构-树

1. 树的定义 2. 树的性质和概念 3. 二叉树的定义与二叉排序树的基本操作- 树的定义 树是一种“一对多”的数据结构,是n(n≥0)个结点的有限集,其中n=0时称为空树 - 树的性质 1.根节点唯一 2.结点n>1时,除去根结点的其他结点构成若干个互不相交的有限集T1,T2…,其中每一个集合又是一棵树,称为根的子树 3.结点拥有的子树数称为结点的度(Degree),度为0的结

2018-02-26 19:30:41 160

原创 LeetCode 4. Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 =

2018-02-26 17:09:49 138

原创 LeetCode 25. Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of

2018-02-26 17:00:10 138

原创 LeetCode 23.Merge k Sorted List 合并k个有序链表(后补)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目描述 讲k个有序链表合并为一个链表,并且保持有序状态。 思路1 将所有的链表的头结点放到最小堆里面,每提取一个结点,就将该结点的下一个结点放在堆里。public class MergeKSort

2018-02-26 16:46:51 172

原创 LeetCode 148.Sort List 链表排序

Sort a linked list in O(n log n) time using constant space complexity. 题目链接题目大意 对一个链表进行排序,复杂度在O(nlogn)内。 思路 我写的是归并排序,注意分开后的左边链表的尾结点的next置null。public class SortList { public ListNode

2018-02-26 16:34:46 465

原创 数据结构 链表知识及常用操作(Java)

在链表的各种问题中,经常需要用到找中间结点,类似二分法,这时候就需要一个快慢指针的方法。public ListNode getMiddle(ListNode head) { if ( head==null || head.next==null ) return head; ListNode slow = head,fast = head; while

2018-02-24 23:28:13 278

原创 Leetcode Permutation sequence

The set[1,2,3,…,n]contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): “123” “132” “213”

2018-02-24 22:02:18 166

原创 HDU 1584 蜘蛛牌 搜索 回溯

题目:  深度优先搜索,一张牌只能放在比它大1的牌上面,i 是当前牌,遍历从i+1到10 ,如果有未被标记的数字,就是放的位置。我一开始想的是i只能放在i+1上,仔细一想,在顺着i+1像10的遍历过程中,我们已经标记过的数字都放在了正确的位置。从1到9为起点遍历所有情况即可。#include #include #include #include using namespace

2017-05-21 16:21:30 301

原创 Not Equal on a Segment CodeForces - 622C

特殊处理!学习一发#include using namespace std; const int N = 2e5+10; int pre[N]; int data[N]; int main(){ int n,q; int h,t,val; cin>>n>>q; for ( int i=1; i<=n; i++ ) { scanf("%d",&data[i]

2017-05-18 22:22:44 188

原创 超类 子类 java核心技术第五章

继承关系! 以manager与employee为例子,在manager与employee之间存在明显的关系 - 每一个manager都是employee。即“ is-a ” 关系。这是继承关系的一个明显特征。public class Manager extends Employee { ......}employee类被称为 子类,派生类或者孩子类,employee类被称为父类

2017-05-18 12:29:55 556

原创 Catch That Cow POJ 3278 BFS 广度优先搜索

很久没有写bfs,wa了好多发。注意点:1  一定要加book标记2  当n>k的时候只能进行-1的操作 (剪枝)3 要判断是否越界之后再判断是否标记过 4 不超出最大边界#include #include #include #include #include #include using namespace std; struct node {

2017-05-10 22:50:10 279

原创 Sudoku Extension UVALive - 4763 搜索

题目:思路非常明确, 九宫的深搜 ,一开始写的时候一直是wa,因为在从当前行换到下一行的时候坐标变换一直有问题,学习了大神的一个变量的深搜,然后转换成坐标的办法。  #include using namespace std;const int N = 12; char mp[N][N]; int row[N][N],col[N][N]; int flag[N][N];

2017-05-10 15:45:50 266

空空如也

空空如也

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

TA关注的人

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