摘要: 一、一维前缀和 前提:给一个长度为n的数列,m次询问,问[L,R]区间内数列各项和 所以,前缀和就是前面i个数的总和,所求区间和即为a[R]-a[L-1] 二、一维差分 前提:给一个长度为n的数列,对[L,R]区间加上或减去某个值,最后问[L,R]区间内数列各项和 三、二维前缀和 前提:给定一个n* 阅读全文
posted @ 2019-06-28 23:54 XXrl 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 一、快速幂 整数:求a^n,把n化为2*(k1+k2+..+km); 矩阵:注意矩阵乘法。 复杂度:O(logn) tip:取了模(根据题目要求) 1 #include<bits/stdc++.h> 2 #define mem(a) memset(a,0,sizeof(a)) 3 #define l 阅读全文
posted @ 2019-06-28 21:58 XXrl 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 思路:找基准点,使得基准点左边都比它小或相等,右边比它大。 挖坑法:若设基准点在最左边,则先从右边开始(左边开始的话,无法保证交换的数小于基数2 1 4 9),找到第一个小于基准数的数字,放入左边当前位置,放入时左++;再从左寻找第一个大于基准数的位置,放入右边当前位置,放入时右--; 关键就是,把 阅读全文
posted @ 2019-06-28 10:49 XXrl 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 1.数组中,元素的位置称为索引 2.递归,调用栈。 发现还是不会写hanoi。。: 1 #include<bits/stdc++.h> 2 using namespace std; 3 void hanoi(int n,char a,char b,char c){ 4 if(n==1) cout<< 阅读全文
posted @ 2019-04-27 17:35 XXrl 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 1.快速幂: 用11举例,11=2^0+2^1+2^3 1 int main() 2 { 3 ll a,b; 4 while(cin>>a>>b){ 5 ll ans=1,p=a; 6 while(b){ 7 if(b&1) 8 ans*=p; 9 p*=p; 10 b>>=1; 11 } 12 c 阅读全文
posted @ 2019-03-30 15:57 XXrl 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 贪心:一直超时,查了后发现要标记. 不过sun和v不写>0会出错? http://poj.org/problem?id=3040 1 #include<iostream> 2 #include<cmath> 3 #include<cstring> 4 #include<algorithm> 5 us 阅读全文
posted @ 2019-03-29 18:41 XXrl 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 1.贪心:最优队列 http://poj.org/problem?id=3253 倒推,最小的两个和在一起,加入队列(模拟倒割) #include<iostream> #include<algorithm> #include<queue> #define LL long long using nam 阅读全文
posted @ 2019-03-29 18:38 XXrl 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 int main() 6 { 7 int *p,i=1; 8 p=&i; 9 cout<<"*p: "<<*p<<endl<<"&p: "<<&p<<endl<<"p: "<<p<<endl<<"i: "<<&i<<endl; 阅读全文
posted @ 2019-03-13 18:15 XXrl 阅读(420) 评论(0) 推荐(0) 编辑
摘要: https://vjudge.net/contest/185301#problem/B 用队列记录,set的不重复性来判断 1 //#include<bits/stdc++.h> 2 #include<stdio.h> 3 #include<string.h> 4 #include<math.h> 阅读全文
posted @ 2019-01-29 16:35 XXrl 阅读(301) 评论(0) 推荐(0) 编辑
摘要: https://vjudge.net/contest/185301#problem/A 学习了好多新函数,只要关注每个单词的列宽就行了。自动切分太厉害了吧~ 1 #include<iomanip> 2 #include<stdio.h> 3 #include<string.h> 4 #include 阅读全文
posted @ 2019-01-28 16:47 XXrl 阅读(210) 评论(0) 推荐(0) 编辑