02 2012 档案
摘要:编辑器加载中...
阅读全文
摘要:#include<iostream>#include<cstdio>#include<cstring>using namespace std;int num,hash[14],flag[14]={0};void DFS( int cnt,int n ){ if( cnt == n+1 ) { num++; return ; } for( int i = 1; i<= n ; i++ ) { if( !flag[i] ) { hash[cnt]=i; int Flag = 0;...
阅读全文
摘要:#include<iostream>#include<cstdio>using namespace std;int num[1024],flag,save[1024],number,N;void DFS( int n, int sum ,int cnt){ if( sum == number ) { flag = 1; for( int i = 0; i< cnt ; i++ ) { printf( i==0?"%d":"+%d",save[i] ); } puts( "" ); ret...
阅读全文
摘要:简单搜索题:#include<iostream>#include<cstdio>#include<cstring>using namespace std;class Node{public: int x,y;};Node queue[424];int d[4][2]={0,-1,1,0,0,1,-1,0};char map[24][24];int BFS( int x, int y ){ int end =0 ,first = 0; Node t; t.x = x; t.y = y; queue[end]=t; end++; while( first <
阅读全文
摘要:该题用到二分的方法:#include<iostream>#include<algorithm>#include<cstdio>using namespace std;class Node{public: int h,w; };bool cmp( Node a ,Node b ){ if( a.w == b.w ) return a.h > b.h; return a.w < b.w; }Node doll[20024];int Doll( int n ){ int sum=0; int hash[20024]={0}; for( int i =
阅读全文
摘要:该题用广搜比较好,这里要处理好就是X*2的时候,我们知道如果一步一步地走也就最多终点与起点相减的绝对值,那么我们就不能超过终点加上他们的绝对值;#include<iostream>#include<cstdio>#include<cstring>using namespace std;class Node{public: int time,number;};Node queue[200024];int BFS( int A, int B ){ bool hash[200024]={0}; int dis = abs( A - B ); int first=0
阅读全文
摘要:一道典型的搜索题。#include<iostream>#include<cstdio>#include<cstring>using namespace std;char map[124][124];int n,m;int d[8][2] = { -1,-1,0,-1,1,-1,-1,0,1,0,-1,1,0,1,1,1 };void DFS( int x, int y ){ for( int i = 0 ; i< 8 ; i++ ) { int dx = x + d[i][0]; int dy = y + d[i][1]; if( map[dx][dy
阅读全文
摘要:该题是一道,成段更新,单点查询(简单线段树+简单DP),这个题与http://poj.org/problem?id=1436思想差不多,这里我就不重复了,这里就是要处理最大值的问题也就是DP;我有的方法就是以该条边的两个端点往下搜索,如果下面有可见的边,选择值的那条边,然后再进行更新;#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;class Node{public: int l ,r , sum,cover; };
阅读全文
摘要:题目大意:在一个平面内,有一些竖直的线段,若两条竖直线段之间可以连一条水平线,这条水平线不与其他竖直线段相交,称这两条竖直线段为“相互可见”的。若存在三条竖直线段,两两“相互可见”,则构成“线段三角形”。给出一些竖直的线段,问一共有多少“线段三角形”。首先处理端点问题:想象一下若同一x位置有两条线段,y坐标为1~2和3~4。其实中间的空当2~3之间是可以引水平线段的,而这里我们都用整数处理,那条水平线段就被忽略了,可能会导致有一些水平相互可见的线段在计算中被忽略了,这里我们扩大y坐标之间的空间,这时我们就可以多出一个整数来便于我们的整数处理,这样就可以简单地处理端点问题,并且它对于所有情况都有
阅读全文
摘要:该题是个大水体。在这里我设一个color(相当于lazy)来记录这个区间改变的颜色,在更新的时候,我是把值往下更新的,这样就可以保证下面颜色改变同时也可以对下次的颜色改变没影响;这里我设立了一个全局变量Color[]里面的每个值代表一种颜色,false代表不存在,true代表存在;我们往下搜索的时候如果遇到color不为零时我没就把Color[color]=true;赋值之后就不要往下搜索因为color已经代表这个区间了;最后来个暴力搜索所有的出现的颜色;#include<iostream>#include<cstdio>#include<string.h>
阅读全文
摘要:该题与http://poj.org/problem?id=3667是同一类型的题目,这里就不多说了,因为HOTEL注释的比较详细。#include<cstdio>#include<iostream>#include<vector>using namespace std;class Node {public: int l,r; int l_value,r_value; int cover; };Node tree[250024];class Tree{public: void Maketree( int l,int r, int cnt ); void ...
阅读全文
摘要:该题是道成段更新,寻找空间(经典类型,求一块满足条件的最左边的空间)代码的注释比较详细,这里就不多说了。#include<iostream>#include<cstdio>#include<cstring>using namespace std;class Node{public: int l ,r; int l_value,r_value,max; /*l_value从左节点数起的最大连续空闲区间 r_value从右节点起的最大连续空闲区间 max//整个区间的最大连续空闲区间 */ int cover; //当前区间的占用情况,...
阅读全文
摘要:题意:有一块长方形的广告板,往上面贴广告,然后给n个1*wi的广告,要求把广告贴上去,如果前面的行可以贴,就要贴前面的并且要靠左贴,前面的贴不下就贴在下面,广告的高度是wi,如果能贴在上面输出最小的高度,如果不能就输出-1。解题思路:如果以行数为区间,建立线段树,他给的h有10^9次,是创不了10^9这么大的数组的。然而我们知道给定N个广告,应为宽度一定,那么最高也不会超过N;只是我们可以开4×N为数组来建树;我把最后树的叶子节点表示广告牌的高度,并且左边的高度小于右边的;而父节点存储子节点的最大剩余值,如果最大值都比wi都小,则表示该节点不可能贴上广告,那么我们就要回朔到上一个节点
阅读全文
摘要:该题是一道区间求和的问题,同时对区间值进行改变,这里我们用到lazy,以便我们不要更新到每个节点,直到我们要用到时我们才往下传递,这样就可以节省时间;#include<cstdio>#include<iostream>#include<cstring>using namespace std;class Node{ public: int l,r,mid; long long lazy,sum;};Node tree[400024];long long num[100024];class Tree{ public: void Maketree( in...
阅读全文
摘要:该题是一道简单的线段树题目,关键就是区间更新的问题,更新时不要更新到每个节点,而是更新到他们的包括他们的所有节点的父节点就可以了,当有新的更新时,就把父节点的原先的更新更新到子节点,这样就可以尽量保证不必要的重复更新。#include<iostream>#include<cstdio>#include<cstdlib>using namespace std;class Node{public: int l,r,mid; int value;};Node tree[400024];class Tree{public: void Maketree( int l,
阅读全文
摘要:这是一道简单的入门的线段树的题目:#include<cstdio>#include<iostream>#include<cstdlib>using namespace std;class Node{public: int l,r,mid; int max,count;};Node tree[800024];int num[200024];class Tree{public: int Max( int a,int b ) { return a>b?a:b; } int Qestion( int l,int r,int cnt ); void M...
阅读全文
摘要:该题可以用树状数组也可以用线段数;树状数组:#include<stdio.h>#include<stdlib.h>#include<string.h>int c[50024],sum[50024],N;int lowbit(int x){ return x&(-x); }int SUM(int n){ int sum=0; while(n){ sum=sum+c[n]; n-=lowbit(n); } return sum; }void add(int n,int num){ while(n<=N){ ...
阅读全文

浙公网安备 33010602011771号