随笔分类 -  Acm

摘要:题目的意思是求构成生成树的边的最大边和最小边的差最小。枚举即可#include#include#includeusing namespace std;#define maxn 102struct node{ int x; int y; int val;}s[maxn*(maxn-1... 阅读全文
posted @ 2015-07-28 09:24 sweat123 阅读(122) 评论(0) 推荐(0)
摘要:#include#include#includeusing namespace std;#define maxn 210int map[maxn][maxn],color[maxn];int vis[maxn],match[maxn],n;int bfs(int u,int n){ int i... 阅读全文
posted @ 2015-07-25 14:11 sweat123 阅读(133) 评论(0) 推荐(0)
摘要://判断图G是否为二分图,可以用染色法。//从一点开始,把他邻接的点图为与其不同的颜色,那么只要bfs一圈一圈图。如果图的时候遇到颜色相同,//表明2个点相连,所以不是;#include#include#includeusing namespace std;#define maxn 210int m... 阅读全文
posted @ 2015-07-25 14:06 sweat123 阅读(361) 评论(0) 推荐(0)
摘要:求重要的点。那就可以通过枚举来找;先做一次最大匹配,求出匹配数。然后逐一枚举这些点。如果匹配数改变,那就是重要点;#include#includeint map[103][103],n,m,vis[103],match[103];int x[103],y[103];int dfs(int u){ ... 阅读全文
posted @ 2015-07-25 10:19 sweat123 阅读(147) 评论(0) 推荐(0)
摘要:添加lb[],rb[]数组,来标记竖边。添加num,来计算竖边的个数,因为计算周长的时候,未覆盖的竖边都要加。#include#include#includeusing namespace std;#define lson l,m,rt=L&&R>=r) { tree[rt].c... 阅读全文
posted @ 2015-07-24 20:31 sweat123 阅读(157) 评论(0) 推荐(0)
摘要:这题真的呵呵了。敲了很长时间,调了很多bug,把0 1 输出,解决了。最后想取反,怎么搞都有bug,最后还是看了大牛们的博客。不过这题真的敲得爽,调bug时基本把线段树过程全部弄了一遍。#include#include#define lson l,m,rty?x:y;}int min(int x,i... 阅读全文
posted @ 2015-07-24 13:44 sweat123 阅读(231) 评论(0) 推荐(0)
摘要:strcmp比较的是所有的长度,而strncmp可以比较前几个长度 strncmp(s1,s2,n);这样就比较了s1,s2,前n个长度的大小。 阅读全文
posted @ 2015-07-23 09:55 sweat123 阅读(260) 评论(0) 推荐(0)
摘要:百度上说 三角形三条中线构成的新的三角形的面积是原三角形面积的3/4;,用正三角形随便试一下。如果是3条高ss^2=1/((1.0/ha+1.0/hb+1.0/hc)*(1.0/ha+1.0/hb-1.0/hc)*(1.0/ha-1.0/hb+1.0/hc)*(1.0/hb+1.0/hc-1.0/h... 阅读全文
posted @ 2015-07-22 16:16 sweat123 阅读(656) 评论(0) 推荐(0)
摘要:#include#include#includeint prime[1000010];int vis[1000010];int flag;void init_prime() { int i, j; for(i = 2;i <= sqrt(1000010); ++i) ... 阅读全文
posted @ 2015-07-22 16:13 sweat123 阅读(150) 评论(0) 推荐(0)
摘要://看了很多的博客 后来队友指点才懂//sum=f(g(0))+f(g(1))+....//sum=A^(b-1)*|...|....//要将b-1换,防止出现b=0时有负一,用A^b代替,取下面的即可//这样问题成了 sum=A^b(A+A^(2k)+A^(3k)+...+A^(k(n-1)));... 阅读全文
posted @ 2015-07-22 08:47 sweat123 阅读(517) 评论(0) 推荐(0)
摘要:添加 lsum[ ] , rsum[ ] , msum[ ] 来记录从左到右的区间,从右到左的区间和最大的区间;#include#define lson l,m,rty?x:y;}void pushup(int l,int r,int rt){ int m=(l+r)/2; lsum[r... 阅读全文
posted @ 2015-07-18 17:10 sweat123 阅读(168) 评论(0) 推荐(0)
摘要:由于坐标可能很大,此时需要离散化,将值转化为对应的坐标。#include#includeusing namespace std;#define lson l,m,rt=L&&R>=r) { sum[rt]=1; if(!mark[c]) { ... 阅读全文
posted @ 2015-07-18 15:46 sweat123 阅读(193) 评论(0) 推荐(0)
摘要:给n个数字 U表示第A个数改为B。A是从0开始。Q输出最大的递增序列个数。考虑左边,右边,和最大的。#include#define lson l,m,rty?x:y;}int min(int x,int y){ return x=p) updata(p,c,lson); e... 阅读全文
posted @ 2015-07-18 15:02 sweat123 阅读(234) 评论(0) 推荐(0)
摘要:求矩阵的并,也就是要求所有的面积。那可以吧总的图形按照矩阵来切割。使其为一块一块。输入的时候用坐标表示,这里扫描线从下到上扫描。初始时让下面的边为1,上面的为-1;用一条先从下面开始想上扫描。遇到更新线段树,加入该条边,为-1时就除去改变。这样从下到上一遍扫描就可以得到线段的长度。从下到上的过程中,... 阅读全文
posted @ 2015-07-18 14:18 sweat123 阅读(234) 评论(0) 推荐(0)
摘要:/* 不是叶子节点 ,且cnt=1.注意这里,cnt=1确切的意义是什么, 应该是,可以确定,这个区间被完全覆盖了1次, 而有没有被完全覆盖两次或以上则不知道无法确定,那么怎么怎么办了, 只要加上t[lch].s + t[rch].s 即,看看左右孩子区间被覆盖了一次或以上... 阅读全文
posted @ 2015-07-18 14:07 sweat123 阅读(172) 评论(0) 推荐(0)
摘要:简单线段树hdu1166 1 #include 2 #define lson l,m,rt m)43 ret += Query(L,R,rson);44 else if(m >= R)45 ret += Query(L,R,lson);46 else4... 阅读全文
posted @ 2015-07-13 13:53 sweat123 阅读(168) 评论(0) 推荐(0)
摘要:原来听到树状数组这名字感觉很难,很高大上。学了一下发现不难。而且很好。 普通的数组修改某个值耗费为O(1),输出和为O(n);而树状数组为O(logn);lowbit(x){ return x&(-x);}返回的是x二进制最后一位1的位置; 有公式:cn=a(n-a^k+1)+.........+a 阅读全文
posted @ 2015-06-07 18:58 sweat123 阅读(255) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 struct node 5 { 6 int id; 7 int val; 8 friend bool operatorb.id;15 }16 }17 };1... 阅读全文
posted @ 2015-06-07 16:36 sweat123 阅读(203) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<queue> 3 using namespace std; 4 5 6 struct node 7 { 8 friend bool operator< (node x,node y) 9 { 10 return x.pre>y.pre;/ 阅读全文
posted @ 2015-06-07 14:04 sweat123 阅读(203) 评论(0) 推荐(0)
摘要://点双连通分量的求解//就是通过tarjan算法求出关节点时,与关节点的子树就是一个连通分量,可以通过画图得到//所以可以将与顶点u有关的边放到栈中,然后一但满足low[v]>=dfn[u](表面点u是割点)(注释:由于dfs,已经建好了u//的子树,所以栈中有顶点u的子树),就可以进行退栈,直到... 阅读全文
posted @ 2015-06-04 14:02 sweat123 阅读(507) 评论(0) 推荐(0)