自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Linux 系统编程笔记-(2)文件I/O

文件I/O:通用的I/O模型目录文件I/O:通用的I/O模型1.open(), close(), read(), write()系统调用2.改变文件偏移量: lseek()文件空洞3.函数ioctl(),麻雀虽小,五脏俱全!1.open(), close(), read(), write()系统调用Linux系统中"万物皆文件".包括普通文件,设备,管道,套接...

2019-02-03 20:55:46 258

原创 Linux 系统编程笔记-(1)基本概念

一.UNIX与Linux发展史1965 年,Bell 实验室、MIT、GE(通用电气公司)准备开发 Multics 系统,为了同时支持 300 个终端访问主机,但是 1969 年失败了;1969 年,Ken Thompson(C语言之父)利用汇编语言开发了 FIle Server System(Unics,即 UNIX 的原型);1973 年,Dennis Ritchie 和 Ken...

2019-02-01 21:28:48 585

原创 POJ 1845 Sumdiv: 分解质因数 + 母函数思想 + 逆元 + 分治

首先我们来读题Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).再注意一下数据范围中文意思也不难理解求的所有约数之和 ...

2019-01-30 17:25:54 241

原创 Hdu4699 Editor: 数据结构之对顶栈(顺便记录一个小毛病)

数据结构都是工具。 本文先通过简略描述告诉大家什么是对顶栈,然后我们来读题分析为什么要使用对顶栈这一数据结构。 一、什么是对顶栈?描述:大家都知道栈是一种后进先出(LIFO, Last in, First out.)的数据结构,它至少提供两种操作:进栈和出栈。执行进出栈操作的一端叫栈顶,另一端叫栈低。进栈和出栈操作都是O(1)的复杂度。那么对顶栈顾名思义就是...

2019-01-28 18:44:47 509

原创 hdu 2489 Minimal Ratio Tree 最小生成树+枚举

题意 在n个节点中找出由m个节点组成的树,这个数的ratio最小 应为节点数量很少,最小生成树加枚举所有n个节点的情况就能过 这里用到了二进制枚举。#include <cstdio>#include <algorithm>#include <iostream>#include <vector>#include <string>#include <sstream>#includ

2017-10-14 16:57:18 234

原创 hdu 3926 hand in hand 同构图

题目说的很清楚,判断同构图。 知道了同构图的定义后就不难判断了。 同构图:  图论当中的术语,假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所有的x,y∈V均有xy∈E等价于m(x)m(y)∈E1,则称G和G1是同构的,这样的一个映射m称之为一个同构。  简单的说,就是两个图 环数相同,链数相同,这些环,链在两个图中要大小对应相等。#i

2017-10-14 14:54:50 306

原创 codeforces 837B Balanced Substring

题目大意 找一个最长的字串,满足字串中0和1的个数相同 思路 这里可以枚举做,将0看成-1,记录前缀和,那么我们只要找到一个最长的前缀和为0的字串就行了。但枚举也是有方法的,先枚举l,再从大的地方枚举r,r的减少也是有讲究的,不能每次减1,比如一个串”11111111” 在[1, 8]时前缀和之差sum[8] - sum[0] == 8,此时不满足,还要减少r来找到一个区间,使得sum[r]

2017-10-13 18:54:20 231

原创 hdu 1811 Rank of Tetris 并查集+拓扑排序

题意:给出一系列排名的信息,问你是否能确定排名,还是信息有冲突,或者信息不足。这种确定先后顺序的题目我们很自然就能想到拓扑排序,拓扑排序时就可以判出是否冲突或信息不足,冲突就是有回路,信息不足就是在确定某个是谁时有多种选择,也就是在拓扑排序时入度为0的有多个。代码如下,代码写的比较没有条理,因为之前拓扑排序用到时dfs版的,但后面想到这道题要有唯一的拓扑序列,所以应该用入度版。转换为入度后,问题变得

2017-10-07 12:36:21 193

原创 异或

昨天的cf比赛才写出两题,两题都被hack了,都是在异或上出的问题就是两个数异或,结果可能大于这两个数比如100000000B xor 11111111B = 111111111写给自己,以后不要再犯

2017-10-07 08:54:57 204

原创 hdu 1081 1559 最大子矩阵

今天写了挺多最大子矩阵的题,以前有看过书,没搞懂什么叫 “枚举起始行和终止行后,把整个矩形压缩成一维的” 可能是脑子笨,现在看这句话很通俗易懂啊。 确定一个子矩阵就是要确定四个边界嘛,上下边用枚举的方法,求和时会省下很多不必要的计算,这道题还和昨天写的:http://poj.org/problem?id=3494有点像。 都用到了压缩行,把矩形压缩成一维的思想。hdu 1081:#inclu

2017-10-05 14:06:02 191

原创 poj 3494 Largest Submatrix of All 1’s

这题是poj2559的变形,每次枚举底边,然后完全能转换为poj2559 http://poj.org/problem?id=2559解法和poj2559差不多 由于这里要频繁用栈 所以还是不要用stl的stack 我之前用了,就TLE#include <iostream>#include <vector>#include <cstring>#include <algorithm>#

2017-10-04 21:01:55 186

原创 hdu 1506 Largest Rectangle in a Histogram

来了一个高度较小的长方形a,设a的左边有比a高的长方形b 将b pop()出来 则以b为高度的大长方形的宽度就能确定了 该长方形的右边界好确定,就是a所在的位置减一,因为a比b低,而在栈中,在b之前被pop()出来的的都比b高 左边界也好确定,就是当前栈顶的值加一,因为当前栈顶对应的高度是要小于b的高度的 栈中存放的是每个小长方形所在的位置,进而可以得出宽度#include <iostre

2017-10-04 20:14:35 158

原创 hdu 1856 More is better 并查集

题目大意是要找出一个朋友集合,这个朋友集合的大小最大,输出这个集合的大小朋友的朋友是朋友,这个很自然就会想到并查集,这里的并查集要用到路径压缩,因为点数太多,集合的大小也好处理,只要在每次合并集合时增加作为祖先的元素所对应的大小就好了#include #include #include #include #include using namespace std;typed

2017-09-20 20:14:57 166

原创 Winter is here codeforces 839d 容斥

#include #include #include #include #include #include #include using namespace std;typedef long long ll;const int MAXN = 1000005;const ll mod = 1e9 + 7;ll mypow(ll a, ll b, ll mod) // a ^

2017-09-05 20:43:57 220

原创 hdu5651 乘法逆元

判断一个字符串有多少种排列方式使得其为回文字串很明显,这个字串中最多只能有一种奇数个的字符,且这个奇数个的字符有一个要放在正中间然后就可以把回文串分为前半段和后半段前半段与后半段对称,只要求前半段的排列数就好了设前半段有n个字符,有i种字符,每种字符有m1, m2, m3, ..., mi个则答案为 n!/(m1! * m2!*m3! * ... * mi!)这里要用到乘法

2017-08-30 14:15:32 223

原创 poj 2142 扩展欧几里得

ax+by=c;求出通解x = xo + k1*i y = y0 - k2*ik1,k2,你懂的.i是变量。然后根据直线方程。s = -x0/k1;e = y0/k2;min=min{s,e},max=max{s,e}在区间[min-1,max+1]这一段内,必取极小值。枚举这一段的 i其中|x0 - k1 * i| + | y0 - k2*i| 在负无穷到s单调

2017-08-30 14:07:02 171

原创 hdu 5230 ZCC loves hacking

刚开始滚动数组错了#include #include #include #include #include using namespace std;typedef long long ll;const int MAXN = 100005;const int MAXNUM = 320;const ll INF = 0x3f3f3f3f3f3f3f3f;const int NI

2017-08-28 09:28:25 210

原创 hdu 1231

最大连续子序列http://acm.hdu.edu.cn/showproblem.php?pid=1231这题以前一直没弄懂,学了dp后回头看,觉得很容易理解,这题可以当做dp做,也可以当做贪心做定义dp[i],以i结尾的最长连续子序列的值#include #include #include #include using namespace std;t

2017-08-27 15:10:48 225

原创 poj 1837 balance

定义平衡度为天平的右边值减去左边值则当平衡度为p时挂上一个重量为w的砝码,在c位置,平衡度会变为p+w*c则平衡度为p+w*c的状态数应该加上平衡度为c时的状态数#include #include #include #include using namespace std;const int MAXN = 15005;const int INF = 0x3f3f3f

2017-08-26 13:47:48 193

原创 L3-001. 凑零钱

https://www.patest.cn/contests/gplt/L3-001dp记录路径题#include #include #include #include #include using namespace std;const int MAXN = 10005;int dp[MAXN][105];int val[MAXN];int main(){

2017-08-24 12:36:10 382

原创 hdu1874 畅通工程续

堆优化的dijkstra需要更新边边记录要去的顶点和权值#include #include #include #include #include #include #include using namespace std;const int INF = 1 << 30;const int NIL = -1;const int MAXN = 205;int

2017-08-16 09:53:06 162

原创 hdu1857 畅通工程再续

用的堆优化的prim算法写的,之前把prim与dijkstra弄混了,prim是不用更新边的#include #include #include #include #include #include #include #include using namespace std;const int INF = 1 << 30;const int NIL = -1;co

2017-08-16 09:50:33 183

原创 prim 堆优化

#include #include #include #include #include #include #include using namespace std;const int MAXN = 1005;const int INF = 1 << 30;struct Node { int u, w; friend bool operator<(const Node&

2017-08-16 09:45:56 357

原创 hdu 3397

一些放的错误,写给自己看#include #include #include #include #include #define lson rt << 1, l, m#define rson rt << 1 | 1, m + 1, r#define rclen (curlen >> 1)#define lclen (curlen - rclen)#define ge

2017-08-07 19:28:23 220

原创 hdu 3308 线段树

写给自己看,记自己错的几个点#include #include #include #include #include using namespace std;typedef long long ll;const int MAXN = int (1e5) + 5;const int INF = (1 << 30);#define lson rt << 1, l, m#

2017-08-07 10:14:40 198

原创 poj 2528

http://www.cnblogs.com/kevince/p/3893531.html  线段树,需要离散化#include #include #include #include #include #include #define lson rt << 1, l, m#define rson rt << 1 | 1, m + 1, rconst int MAXN = 200

2017-08-04 14:34:11 173

原创 Who Gets the Most Candies? 线段树

用模拟每一轮有人跳出后的人数变化因子个数可打表算出#include #include #include #include #include using namespace std;const int MAXN = 500005;typedef long long ll;#define lson rt << 1, l, m#define rson rt << 1 |

2017-08-04 08:55:26 200

原创 Buy Tickets 线段树

因为后来的人插队会影响先来的人的位置所以从后往前处理最后一个人的位置是可以直接确定的,就是r[i]+1因为对于前一个人来说,前一个人加入队列是后一个人是不存在的,所以在处理完后一个人后要把后一个人占的位置给删去#include #include #include #include using namespace std;const int MAXN = 200005;typedef

2017-08-03 15:30:43 156

原创 Billboard 线段树

每次贴公告时都尽可能上线段树中的val表示在[l,r]范围内黑板所剩的最大宽度每次查询都先往左查询,这样就可以优先贴在靠上的地方#include #include #include using namespace std;const int MAXN = 200005;struct Node { int l, r; long long val; int mid() {

2017-08-03 15:23:59 204

原创 hdu 2711 Lost Cows

#include using namespace std;const int MAX = 8005;//先把牛从小到大排好,然后一个个取,取完要把相应牛删除//很明显取的时候取当前第pre[i]+1大的数字struct Node { int l, r, num;//num代表[l, r]区间的数字个数 int mid() { return (l + r) >> 1; }}Tree[

2017-08-02 20:24:12 251

原创 扩展欧几里得

#include <iostream>#include <algorithm>#include <cstring>#include <functional>#include <cstdio>#include <vector>#include <queue>#include <limits>using namespace std;typedef long long ll;const

2017-08-02 17:39:51 144

原创 L2-011. 玩转二叉树

L2-011. 玩转二叉树https://www.patest.cn/contests/gplt/L2-011时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越给定一棵二叉树的中序遍历和

2017-08-02 12:46:26 171

原创 Boolean Expressions

描述The objective of the program you are going to produce is to evaluate boolean expressions as the one shown next: Expression: ( V | V ) & F & ( F | V )where V is for True, and F is for False.

2017-08-02 09:47:56 218

原创 poj 1011

//剪枝//挺难想的//也挺难懂//http://www.bilibili.com/video/av10046345/?from=search&seid=9872190969825285872#page=18#include #include #include #include #include using namespace std;int n;int Sticks[7

2017-07-23 17:33:41 246

原创 poj 1724

这题需要简直到达某个城市c的路径有许多条,可能会有一些花的钱相同但路径不同的路线。也就是说 我们走到城市c只花了m1的钱,从另一条路走到c却花了多余m1的钱,那么这条路没有必要继续走下去,要么到不了,要么路径长度和之前的路是一样的,总之不会小于那个花钱少的路线#include #include #include #include using namespace

2017-07-21 20:37:13 189

原创 poj 3468 线段树

#include #include #include #include #include using namespace std;const int MAXN = (int)1e5 + 10;struct Node{ long long sum; int add;//延迟标记 int left, right; int mid() { return (left + right

2017-07-16 13:04:57 173

原创 拨钟问题 穷举法

http://cxsjsxmooc.openjudge.cn/2017t2summerw1/b///一种操作执行0-3次是有意义的,便可枚举每种操作执行的次数。#include #include #include #include #include using namespace std;int oriClocks[9];int clocks[9];const cha

2017-07-16 13:00:46 517

原创 pat 05-树9 Huffman Codes

#include #include #include #include #include #include #include #include using namespace std;typedef struct BiTNode { char key; int weight; BiTNode *lchild, *rchild; BiTNode(char k = '\0',

2017-05-29 15:42:52 211

原创 hdu1284 钱币兑换

1.把问题看成整数划分f(n, m) 为把n划分为最大值不超过m的划分总数:f(n, m) = 1; (m == 1)          n个1               f(n, n);  (m > n)   最大值m不可能大于n               f(n, m - 1) + 1; (m == n)   1个n 加上 最大值为n-1的个数           

2017-05-27 15:24:11 231

原创 hdu1249 三角形

用N个三角形最多可以把平面分成几个区域?一条直线和三角形的一角相交,会产生两个交点,从而新产生一条线段,这条新产生的线段便对应着新生成的面,即两个交点-->一个面。因为题目是三角形和三角形进行相交,产生的交点既是原来图像的交点,也是新加入的三角形的交点,即一个交点-->一个面。所以:新增一条直线,最多新增交点个数为原来三角形个数*2,因为直线可以和原来每个三角形的其中一个角相交。

2017-05-27 13:11:35 332

空空如也

空空如也

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

TA关注的人

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