自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 poj 3321 Apple Tree

<br />思路:用数组模拟指针建图,dfs得到每个节点对应的开始时间擢和结束时间擢,然后用树状数组解决。<br />#include<iostream> using namespace std; #define maxn 100005 struct node { int ver,next; }; node g[maxn]; int adj[maxn],begin[maxn],end[maxn],c[maxn],time,e; bool app[maxn]; void insert(i

2011-02-28 13:09:00 243

原创 poj 1195 Mobile phones

<br />二维树状数组的应用<br />#include<iostream> using namespace std; #define maxn 1030 int c[maxn][maxn]; int low(int k) { return k&(-k); } void update(int x,int y,int n,int a) { for(int i=x;i<=n;i+=low(i)) for(int j=y;j<=n;j+=low(j)) c[i][j]+=a

2011-02-27 13:21:00 200

原创 poj 2352 Stars

线段树的应用挺简单的,不多说了。#include using namespace std; #define maxn 15005 struct node { int l,r,cover; }; node st[maxn*4]; int p[maxn]; int result[maxn]; int index[maxn]; void maketree(int l,int r,int i) { st[i].l=l,st[i].r=r,st[i].cover=0; int mid

2011-02-26 17:18:00 256

原创 poj 1151 Atlantis

<br />线段树的应用。<br />线段树求面积,比1177求周长方便<br />线段的覆盖长度乘以(e[i+1].x-e[i].x);<br />#include<iostream> using namespace std; #include<cstdlib> #define maxn 210 struct node { int l,r,cover; double sum,len; }; struct edge { double st,ed,x; bool inout;

2011-02-26 14:32:00 331

原创 poj 1177 Picture

线段树的应用。主要是用到如下思想:当线段覆盖的总长度发生变化时,肯定遇到了轮廓。下面博客的代码写的很好,注释很详尽,我笔算了一天,才懂了点这个经典的线段树+离散化+扫描线。http://www.cppblog.com/abilitytao/archive/2010/07/21/120927.html#include #include #include #define maxn 10010 using namespace std; struct node { int l,r,sum,cover

2011-02-26 11:08:00 807

原创 poj 2892 Tunnel Warfare

<br />线段树的应用。<br />#include<iostream> using namespace std; #define N 50005 typedef struct node * pointer; struct node { int l,r,lx,rx;//lx记录左端点起连续的未被破坏的村庄 //rx记录以右端点结束的连续的村庄 pointer left,right; }; pointer maketree(int a,int b) {

2011-02-24 15:16:00 472

原创 poj 2749 Building roads

<br />继续2-sat建图<br />这题发现:邻接表构图时,如果用指针,会超时,所以今天学习了不用指针的相当于邻接表的构图方法。<br />#include<iostream> #include<cmath> using namespace std; #define N 1005 struct node { int ver,next; }; struct dian { int a,b; }; dian sou[N],s0,s1; dian fri[N],hate[N];

2011-02-22 10:31:00 344

原创 zoj1016 Parencodings

<br />简单的找规律题<br />#include<iostream> using namespace std; #include<cstdio> #define N 25 int p[N]; int main() { int ca,n,i,temp; scanf("%d",&ca); while(ca--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",p+i); for(i=n;i>1;i--)

2011-02-21 13:41:00 318

原创 poj2723 Get Luffy Out

<br />继续对2-sat建图的理解<br />下面的博客讲的挺好<br /><br />http://hi.baidu.com/%8E%E1%D0%B3/blog/item/0a062c11ac76178e6538db55.html/cmtid/b2c6dddb2cd98c2211df9b50<br />#include<iostream> using namespace std; #define N 4100 typedef struct node* pointer; struct node

2011-02-20 22:40:00 567

原创 poj 3207 Ikki's Story IV - Panda's Trick

<br />第一次接触2-sat的题目,建图是关键,下面的文章讲的挺好的:<br />http://www.chenyajun.com/2010/01/18/4282<br />http://www.answeror.com/archives/26184<br />#include<iostream> using namespace std; #define N 2005 typedef struct node* pointer; struct node { int ver; point

2011-02-19 20:13:00 308

原创 poj 1236 Network of Schools

<br />tarjan求强连通分量,task a 是入度为0的新节点,task b 是max(入度为0,出度为0),当整个图是一个强连通分量是,输出1,0<br />#include<iostream> using namespace std; #define N 105 typedef struct node* pointer; struct node { int ver; pointer next; }; int low[N],ord[N],id[N],stk[N],cnt,sc

2011-02-19 13:03:00 230

原创 poj 2553 The Bottom of a Graph

<br />解题思路:用tarjan求强连通分量,缩图为G’,map[id[i]]==0,id[i]表示节点i的新节点,map[]==0说明新节点的出度为0,则i即为所求的节点,the bottom of the graph<br />#include<iostream> using namespace std; #include<cstdlib> #define N 5005 typedef struct node* pointer; struct node { int ver; po

2011-02-19 11:29:00 296

原创 poj 2186 Popular Cows

照着别人的博客写了生平第一题tarjan强连通分量,不得不佩服tarjan,我笔算了tarjan,整个过程是有了一定的理解,但是为什么是正确的,只能膜拜tarjan了。下面的博客写的很好,对tarjan强连通分量做了比较详细的解释http://blog.sina.com.cn/s/blog_62ebd4410100g53w.html#include using namespace std; #define N 10005 typedef struct node* pointer; struct no

2011-02-18 18:27:00 332

原创 poj 2236 Wireless Network

<br />并查集的简单应用<br />一个集合中的电脑能够通信<br />每次修好一台电脑,都要进行合并集合<br />#include<iostream> #include<cmath> using namespace std; #define N 1005 #define eps 0.000001 int set[N],s[N]; struct point { int x,y; }; point p[N]; double dist(point p1,point p2) {

2011-02-17 13:33:00 234

原创 poj 1988 Cube Stacking

<br />还是并查集的高级应用<br />思想和食物链一样,就是下面那篇博客的思想:<br />http://blog.csdn.net/xiaomajiyue/archive/2011/02/16/6188553.aspx<br />嘻嘻,再次提到了食物链,看来彻底搞懂食物链真的很重要<br />#include<iostream> using namespace std; #define N 30005 int c[N],p[N],r[N]; void init(int n) { for

2011-02-17 09:41:00 267

原创 poj 1703 Find them, Catch them

<br />并查集的高级应用。<br />与a bug‘s life 一摸一样,只是换了一个情景。<br />所以还是那句话,建议把食物链好好搞懂,这题也就迎刃而解了。<br />#include<iostream> using namespace std; #define N 100005 int p[N],r[N]; void init(int n) { for(int i=1;i<=n;i++) { p[i]=i; r[i]=0; } } int find(int

2011-02-17 08:57:00 247

原创 poj2492 A Bug's Life

<br />这题也是并查集的高级应用。<br />我就不多讲了,做这题之前,我建议把食物链好好搞懂,那么这题就自然而然会了,食物链有三种性别,而这里只有两种关系,更加简单,所以食物链一定要搞懂。<br />#include<iostream> using namespace std; #define N 2005 int p[N],r[N]; void init(int n) { for(int i=1;i<=n;i++) { p[i]=i; r[i]=0; } } i

2011-02-16 21:24:00 289

原创 poj 1182 食物链

<br />并查集的高级应用。<br />有必要先看一下这两篇博客:<br />http://wxdlut.blog.163.com/blog/static/128770158200982754311269     http://www.cppblog.com/tortoisewu/archive/2009/09/15/85501.html<br />然后对一些自认为比较纠结的地方进行阐述,我纠结了三天。<br />在一个集合中(能确定任意两者之间的关系),并不是所有的点对根的相对关系是正确的,只有根和父节

2011-02-16 17:06:00 715 3

空空如也

空空如也

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

TA关注的人

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