- 博客(21)
- 资源 (64)
- 收藏
- 关注
原创 【MZ 自测题(套路题)】
#include #include #include #define LL long longusing namespace std;const int MOD1 = 1000000007;const int MOD2 = 998244353;typedef pair pii;mapMAP;int s[110];int cnt = -1,n,m;int read_int
2016-04-26 16:46:11 860
原创 [C++]STL之map
map map是一种关联容器,存储相结合形成的一个关键值和映射值的元素。Map 是一种Pair Associative Container,意味着它的值类型为 pair<const Key, Data>. 而且也是 Unique Associative Container, 也就是任何两个元素没有相同的key值。map具有重要的属性,就是在map对象中插入一个新元素不指
2016-04-26 16:22:32 807
原创 [技巧]读入优化
int read() { int sign = 1, n = 0; char c = getchar(); while(c '9'){ if(c == '-') sign = -1; c = getchar(); } while(c >= '0' && c <= '9') { n = n*10 + c-'0'; c = getchar(); }
2016-04-26 16:06:39 404
原创 【LCA 倍增法】【codevs 1036 商务旅行】
题目题目描述 Description某首都城市的商人要经常到各城镇去做生意,他们按自己的路线去做,目的是为了更好的节约时间。假设有N个城镇,首都编号为1,商人从首都出发,其他各城镇之间都有道路连接,任意两个城镇之间如果有直连道路,在他们之间行驶需要花费单位时间。该国公路网络发达,从首都出发能到达任意一个城镇,并且公路网络不会存在环。你的任务是帮助该商人计算一下他的最
2016-04-25 17:44:42 838
原创 LCA(最近公共祖先)问题 (一)
最近共祖先对于有根树T的两个结点u、v,最近公共祖先LCA(T,u,v)表示一个结点x,满足x是u、v的祖先且x的深度尽可能大。另一种理解方式是把T理解为一个无向无环图,而LCA(T,u,v)即u到v的最短路上深度最小的点。例如,对于下面的树,结点4和结点6的最近公共祖先LCA(T,4,6)为结点2。方法(一)逐个向上找直接暴力, 求A、B的LCA,可以以先
2016-04-25 16:44:13 1268
原创 NYOJ 119 士兵杀敌(三)[RMQ例题]【解题报告】
#include#include#include#include#define inf 0x3f3f3f3f#define LL unsigned long long#define maxn 100001using namespace std;int n,q;int a[maxn];int maxsum[maxn][20],minsum[maxn][20];void RMQ
2016-04-25 16:29:13 484
原创 Sprase-Table(S-T)算法求解RMQ问题
ST算法ST算法是一种比较高效的在线算法。所谓在线算法,是指用户每输入一个查询便马上处理一个查询。该算法一般用较长的时间做预处理,待信息充足以后便可以用较少的时间回答每个查询。ST(Sparse Table)算法是一个非常有名的在线处理RMQ问题的算法,它可以在O(nlogn)时间内进行预处理,然后在O(1)时间内回答每个查询。RMQRMQ(Range Mini
2016-04-25 16:07:28 896
转载 种类并查集
简介种类并查集: 和基础并查集有很大一部分相同, 多了一个判断2个元素是否属于同一个集团(不是集合, 集合是用来判断2个元素是否能够判断他们属不属于同一个集团:有点绕, 举个例子, 假如知道1和2在不同的集团, 3和4在不同集团,我们就不能判断1和3是否属于一个集团,而集团是用来判断他们是否在同一个集团假如:已知1和2在不同集团,2和3在不同集团, 那么我们就知道1和3在同一个集团
2016-04-23 11:21:01 3216 1
原创 【裸线段树】Uestc-数据结构专题训练【A】
#include#include#include#include#include#define ll unsigned long long#define maxn 100001#define lson u<<1,l,mid#define rson u<<1|1,mid+1,rusing namespace std;int n,q;int t,a,b;struct node{
2016-04-22 23:07:28 654
原创 【线段树+离散化】Uestc-数据结构专题训练【B】
#include#include#include#include#define inf 0x3f3f3f3f#define LL unsigned long long#define left_child now<<1,l,mid#define right_child now<<1|1,mid+1,rusing namespace std;int n,q;struct node{
2016-04-22 23:01:32 514
原创 unique()去重函数
unique()函数是一个去重函数,STL中unique的函数 unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除。他是c++中的函数,所以头文件要加#include,具体用法如下: int num[100]; unique(num,mun+n)返回的是num去重后的尾地址,之所以说比不真正把重复的元素删除,其实是,该函数把重
2016-04-19 21:17:12 933
原创 【POJ 1195 Mobile phones】解题报告
#include#include#include#include#define inf 0x3f3f3f3f#define LL unsigned long long#define maxn 1025using namespace std;int s;int num[maxn][maxn];int k,a,b,c,d;int lowbit(int x){return x&(-
2016-04-18 16:37:11 301
原创 [C\C++]读入优化【技巧】
int read(){ int x=0; char ch=getchar(); while (ch'9') ch=getchar(); while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); } return x; }
2016-04-12 19:27:13 3630
原创 【codevs 1282】 约瑟夫问题 【题解】
模拟:#include"stdio.h"int main(){int m,n,i,j;int s=1;int a[30005];scanf("%d%d",&n,&m);for(i=0;i<=n;i++) a[i]=i;while(n){ i=(s+m-1)%n;//出列的下标 if(i==0) i=n; printf("%d ",a[i])
2016-04-11 16:33:48 850
原创 [codevs 1217]借教室 题解
#include#include#include#includeusing namespace std;int a[1000010];int d[1000010];int x[1000010];int y[1000010];int s[1000010],sum;int n,m,ans;bool cheak(int v){ memset(s,0,sizeof(s));sum
2016-04-11 15:19:42 697
原创 【codevs 1690】题解
#include#include using namespace std;int n,m;struct data{ int l,r,v; bool lazy; }tr[2000001];void build(int k,int s,int t){ tr[k].l=s;tr[k].r=t; if(s==t)return;
2016-04-05 22:14:17 420
原创 【codevs 2981】题解
#include#define maxn 1000005int n, m;int a[maxn],c[maxn];void update(int u,int add){ while(u<=n) { c[u]+=add; u=u+(u&(-u)); }}int sum(int u){ int ans=0; while(u>0) { ans+=c[u]; u
2016-04-05 21:26:37 516
原创 【codevs 1369】题解
#include #include using namespace std;int n , m;int a[200000 + 2];int i;int l , r;struct Node{ int l , r; int value; Node * left , * right;};int merge( int a , int b
2016-04-05 20:35:50 634
原创 【codevs 1191】题解
在一条数轴上有N个点,分别是1~N。一开始所有的点都被染成黑色。接着我们进行M次操作,第i次操作将[Li,Ri]这些点染成白色。请输出每个操作执行后剩余黑色点的个数。输入描述 Input Description输入一行为N和M。下面M行每行两个数Li、Ri输出描述 Output Description输出M行,为每次操作后剩余黑色点的个数。样例输入
2016-04-04 17:15:29 658
原创 [线段树][CODEVS 1080]题解
#include#include#include#include#define inf 0x3f3f3f3f#define LL unsigned long long#define lson u<<1,l,mid#define rson u<<1|1,mid+1,r#define maxn 200005using namespace std;struct node{ int
2016-04-04 10:58:52 762
原创 【codevs 1082】线段树练习3
#include #include #include #define ll long longusing namespace std;int a[200000],n,Q;struct edge{ int l,r,add;ll sum; }node[200000*4];void pushdown(int k){ node[k<<1].add += node[k].add; n
2016-04-04 08:33:40 534
C++_STL使用例子大全
2016-07-30
Learning the vi and Vim Editors
2016-07-28
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人