摘要: 单点更新,区间求最值(也可以用线段树)图:http://baike.baidu.com/picview/1420784/1420784/0/55a628d10b98f02b9a50276e.html#albumindex=0&picindex=0#include<stdio.h>#include<string.h>int n,num[200009],p[200009];int max(int a,int b){ return a>b?a:b;}int lowbit(int t){ return t&(-t);}void change()//找最大值 阅读全文
posted @ 2013-04-15 13:02 宛如 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 树状数组的应用一:单点更新,区间求和http://baike.baidu.com/view/1420784.htm设节点编号为x,那么这个节点管辖的区间为2^k(其中k为x二进制末尾0的个数)个元素int Lowbit(x){ return x&(-x);}如:x =1: 1 &-1(设位数为8)0000 0001 & 1111 1111 = 1x = 6:6 & -6 0000 0110&1111 1010 = 2总结一下,其实就是:求出2^k(其中k: x 的二进制表示数中, 右向左数第一个1的位置),如6的二进制表示为110,向左数第零个为0,第一 阅读全文
posted @ 2013-04-15 12:56 宛如 阅读(156) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<algorithm>using namespace std;struct node{ int number,num,price;}hotel[1009];int cmp(node a,node b){ return a.price<b.price;}int main(){ int T,n,i,t,g,m; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf(&qu 阅读全文
posted @ 2013-04-15 12:51 宛如 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 新学到cmp还可以这样写,更简单int cmp(wood a,wood b){ if(a.l!=b.l) return a.l<b.l; return a.w<b.w;}表示先对l升序排列,如果相等,再对w升序排列#include<stdio.h>#include<algorithm>#include<iostream> /*要写这两个才能用sort*/using namespace std; /* */struct wooden{ int l,w;}wood[5009];int cmp(wooden a,wooden b){ if(a.l< 阅读全文
posted @ 2013-04-15 12:49 宛如 阅读(192) 评论(0) 推荐(0) 编辑
摘要: /*头文件:#include <algorithm>using namespace std;1.默认的sort函数是按升序排。对应于1)sort(a,a+n); //两个参数分别为待排序数组的首地址和尾地址2.可以自己写一个cmp函数,按特定意图进行排序。对应于2)例如:int cmp( const int &a, const int &b ){ if( a > b ) return 1; else return 0;}sort(a,a+n,cmp);是对数组a降序排序又如:int cmp( const POINT &a, const POINT &a 阅读全文
posted @ 2013-04-15 12:47 宛如 阅读(140) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h>int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};char a[100][100];int sum,w,h;void sousuo(int x,int y){ int next_x,next_y; for(int i=0;i<=3;i++) { next_x=x+dir[i][0]; next_y=y+dir[i][1]; if(next_x<0||next_x>=h||next_y<0||next_y>=w) continue; if( 阅读全文
posted @ 2013-04-14 15:49 宛如 阅读(104) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h>int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}};int z;char a[110][110];int b[110][110];void sousuo(int xi,int xj){ for(int i=0;i<=7;i++) { if(a[xi+dir[i][0]][xj+dir[i][1]]=='@'&&b[xi+dir[i][0]][xj+dir[i][1]]==0) 阅读全文
posted @ 2013-04-14 15:48 宛如 阅读(128) 评论(0) 推荐(0) 编辑
摘要: //也可以用生成树的思想做,但要注意是有向边 //生成树的做法:http://blog.sina.com.cn/s/blog_64107d290100h59k.html#include<stdio.h>#include<string.h>int s,e,flag;int vis[10009],map[1009][1009];void dfs(int a){ int i; if(a==e) flag=1; if(flag) return; vis[a]=1; for(i=0;i<26;i++) { if(map[a][i]&&!vis[i]) dfs 阅读全文
posted @ 2013-04-14 15:47 宛如 阅读(160) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>int n;int a[50],b[25],c[25];void dfs(int j){ int i; if(j==n&&a[c[n]+1]==1) { for(i=1;i<=n;i++) { if(i==1)printf("%d",c[i]); else printf(" %d",c[i]); } printf("\n"); } for(i=2;i<=n;i++)//将剩下的未选的数历遍查找符合条件的,都查找过了就会结束 { if(b[i]!=0&&a 阅读全文
posted @ 2013-04-14 15:45 宛如 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 奇偶剪枝:把map看作0 1 0 1 0 11 0 1 0 1 00 1 0 1 0 11 0 1 0 1 00 1 0 1 0 1从 0->1 需要奇数步从 1->0 需要偶数步那么设所在位置 (si,sj) 与 目标位置 (di,dj)如果abs(si-sj)+abs(di-dj)为偶数,则说明 abs(si-sj) 和 abs(di-dj)的奇偶性相同,需要走偶数步如果abs(si-sj)+abs(di-dj)为奇数,那么说明 abs(si-sj) 和 abs(di-dj)的奇偶性不同,需要走奇数步理解为 abs(si-sj)+abs(di-dj) 的奇偶性就确定了所需要的步 阅读全文
posted @ 2013-04-14 15:44 宛如 阅读(201) 评论(0) 推荐(0) 编辑