03 2013 档案
摘要:线段树维护区间最小值, 简单记录下, 下标写错啦, WA到死。http://acm.hdu.edu.cn/showproblem.php?pid=4544View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>int f_min(int x,int y) {return x>y?y:x;}int f_max(int x,int y) {return x>y?x:y;}int f_abs(int x) {return x>
阅读全文
摘要:类似与快速幂的做法View Code /*===================================================================*\ | 两个数相乘超long long乘法的取模 mod的大小要十分注意\*===================================================================*/int multi_mod(int a,int b,int c) { //(a*b)%c int ret=0; while(b) { if(b&1) { ret+=a; if(re...
阅读全文
摘要:http://codeforces.com/problemset/problem/38/EDP状态很容易想到,以后超long long 最大值的设定最好计算出一个边界, int_max的边界赋值 错误,导致WA那么多次。View Code #include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <set>#include <map>#include <queue>#include <fstream>#
阅读全文
摘要:http://codeforces.com/problemset/problem/39/A贪心 按照常数大小从小到大排序, 结果一个一个计算上来, 不影响结果正确性。View Code #include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <set>#include <map>#include <queue>#include <fstream>#include <string>#incl
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=524LCS 细节View Code #include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <set>#include <map>#include <queue>#include <string>#include <cstring>#include <algorit
阅读全文
摘要:View Code /*==================================================*\| 最长有序子序列(递增/递减/非递增/非递减)\*==================================================*/const int N = 1001;int a[N], f[N], d[N]; // d[i]用于记录a[0...i]的最大长度int bsearch(const int *f, int size, const int &a) { int l=0, r=size-1; while( l <= r )
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3523ZOJ 求使无序的序列变有序的最小花费, LIS, struct 初始化需要特别注意View Code #include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>int f_min(int x,int y) {if(x<y)return x;else return y;}int
阅读全文
摘要:Merge sortView Code #include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <algorithm>int f_min(int x,int y) {if(x<y)return x; else return y;}int f_max(int x,int y) {if(x<y)return y; else return x;}//double f_min(double x,double y) {if(x&l
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2901一般DP复杂度 O(L*N^2), 分段计算 O(lgL*N*N)View Code #include <iostream>#include <cstdio>#include <vector>#include <queue>#include <map>#include <string>#include <cstring>#include <algorithm>int f_
阅读全文
摘要:http://www.cplusplus.com/reference/cctype/isalnumView Code /* isalnum example *//*Checks whether c is either a decimal digit or an uppercase or lowercase letter.*/#include <stdio.h>#include <cctype>int main (){ int i; char str[]="c3Po..."; i=0; while (isalnum(str[i])) i++; prin
阅读全文
摘要:http://www.cplusplus.com/reference/cassert/View Code /* assert example */#include <stdio.h> /* printf */#include <assert.h> /* assert */void print_number(int* myInt) { assert (myInt!=NULL); printf ("%d\n",*myInt);}int main (){ int a=10; int * b = NULL; int * c = NULL; b=&a;
阅读全文
摘要:http://www.codeforces.com/contest/283/problem/AView Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MM = 222222;#define debug puts("wrong")typedef __int64 int64;#define lson rt<<1#define rson rt<&
阅读全文
摘要:插入排序View Code #include <iostream>#include <cstdio>#include <queue>#include <set>#include <map>#include <cstring>#include <algorithm>using namespace std;const int mod = 1000000007;const int MM = 111111;int N;int num[MM];void get_data() { int i,j,k; for(i=1;i&
阅读全文
摘要:View Code set<int ,less<int> > 集合中元素从小到大排序set<int ,greater<int> > 集合中元素从大到小排序 begin() 返回指向第一个元素的迭代器clear() 清除所有元素count() 返回某个值元素的个数empty() 如果集合为空,返回true(真)end() 返回指向最后一个元素之后的迭代器,不是最后一个元素erase() 删除集合中的元素insert() 在集合中插入元素size() 集合中元素的数目struct compare{ bool operator ()(string s1
阅读全文
摘要:View Code #include <iostream>#include <cstdio>#include <queue>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int MM = 111111; //处理字符串的最大长度#define debug puts("wrong")int Wa[MM], Wb[MM], Wv[MM], Ws[MM];int ran[MM], height[M
阅读全文
摘要:http://poj.org/problem?id=1469View Code //POJ1469#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MM=100010;int P,N;bool vis[MM];int pre[MM];int head[MM], NE;struct Edge{int v,next;}edge[MM];void add_edge(int u,int v) { edge[NE].v=v; edge[NE].next
阅读全文
摘要:View Code //POJ 1204#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ROOT 0#define debug puts("wrong")const int MM=1010;const int MAX_NODE=100100;const int CHI=26;int L,C,W;int cnt;int len[MM];int ansx[MM], ansy[MM], ansk[MM];char text[MAX
阅读全文