摘要: 单点更新,区间求最值(也可以用线段树)图: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) 编辑