随笔分类 - 比赛总结记录
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4801每个位置记录的是左边做靠近他的和他相同大小的id,线段树维护的是最大的id (id最大也即最早出现)View Code const int MM = 555555;#define debug puts("wrong")#define L(i) i<<1#define R(i) i<<1|1int N,M;int hash[MM];int num[MM];int val[MM<<2];map<int,int&g
阅读全文
摘要:容斥原理, 纠结好久, 求N以内和N不互质的所有数的和。http://acm.hdu.edu.cn/showproblem.php?pid=3501View Code int64 tp[MM], mm;void solve() { int64 i,j,k,ans=0,tmp=N,tt,t1,ret=1; for(i=mm=0;i<cnt;i++) { if(tmp%prm[i]==0) { tp[mm++]=prm[i]; while(tmp%prm[i]==0) tmp/=prm[i]; } } ...
阅读全文
摘要:模拟栈View Code const int MM = 555555;#define debug puts("wrong")int to[MM], cnt, ans;char str[MM], ch[MM];char st[MM]; int top;void solve() { int i,j,k, n=strlen(str+1), m=strlen(ch+1); ans=0; top=0; str[0]='#'; for(i=1;i<=m;i++) { if(ch[i]==str[n]) { for(j=n-1;j>0;j--) i...
阅读全文
摘要:http://codeforces.com/problemset/problem/51/B利用stack类似与括号匹配,每个<table>ROWS</table> 划分一个模块,一个<td>TABLE</td>记录多少个CELL, stack中存的是模块的序号。View Code const int MM = 511111;const double esp=1e-8;const double lep=0.0000001;#define maxint 0x3f3f3f3ftypedef __int64 int64;#define debug put
阅读全文
摘要:http://codeforces.com/problemset/problem/51/C两次二分+贪心, 被卡精度卡了好久,发现整数点的话,结果不是整数就是 xxx.5的直接整数解决,就不会有精度问题啦。以后注意利用题目条件, double代码留作纪念。View Code const int MM = 511111;const double esp=1e-8;const double lep=0.0000001;#define debug puts("wrong")#define clr(a) memset(a,0,sizeof(a))int N,M,mm;int x[M
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4778当存在一个sum+(s[N]-s[h-1])恒不大于M时return掉View Code const int MM = 111111;#define debug puts("wrong")typedef long long int64;int N,M,ans;int s[MM];int num[MM];bool cmp(int x,int y) {return x>y;}void get_data() { int i,j,k; s[0]=0;
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4778优先队列优化下的DP,dp[i]记录的是吃到i天的最小花费,最后dp[N]即为答案。View Code const int MM = 111111;#define debug puts("wrong")typedef long long int64;//typedef __int64 int64;int64 N, cnt;struct Info{int64 x,y;}p[MM];struct Tpoint{ int64 val,dead; //Tpo
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4969询问次数那么多,本能想到线段树。对区间重标号,区间询问, 更新。View Code int N,M,K, len;int ll[MM<<2], rr[MM<<2];int ff[MM<<2];int sum[MM<<2];vector<int>edge[MM];void dfs(int u) { int i,j,k,v; ll[u]=len++; for(i=0;i<edge[u].size();i++)
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4973推出递推公式, 数据范围那么大, 矩阵乘法。View Code const int MM = 100011;const double eps = 1e-10;#define maxint 10000000#define mod 1000000007#define debug puts("wrong");//typedef __int64 int64;typedef long long int64;//const __int64 maxint = 10
阅读全文
摘要:类似贪心。http://acm.nbu.edu.cn/v1.0/Problems/Problem.php?pid=2410View Code const int MM = 22222;int N,M;int cnt;int num[MM];struct Info { int val; int id; void reset() { val=maxint; id=-1; } bool friend operator<(Info x,Info y) { if(x.val!=y.val) return x.val<y.val; e...
阅读全文
摘要:Gao The Sequence计算出一个差值数组C[i], 一种操作, 找一个delate有C[i]-=delaie,找任意多个C[j]-=D[j] (j<i) 使sum(D[j])=delate, 问能否使C[i]全部赋0.View Code #include<cstdio>#define ll long longint main(){ int n; while(~scanf("%d",&n)){ ll a,b,c,s=0,m=0; while(n--){ scanf("%lld%lld",&a,&b); .
阅读全文
摘要:DFS的过程中引用一个指针对数组的引用是很不靠谱的, 以后要引用, 尽量传一个值, 类似于用结构体, 封装一个数组。http://acm.hdu.edu.cn/showproblem.php?pid=4536View Code const int MM = 22222;int N,M, Q;struct Info { int belong[22]; int val[22];}p;vector<int>B[MM];int ret,g;int a[5][MM];Info t;void get_data() { int i,j,k; scanf("%d%d%d",&a
阅读全文
摘要:线段树维护区间最小值, 简单记录下, 下标写错啦, 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>
阅读全文
摘要: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?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
阅读全文
摘要:http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=18807#problem/J水题一道,就是到最后啦,心情很复杂,给自己一个警示, 不要放过任何水题。code:这里
阅读全文
摘要:http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=18541#problem/Hdp要搞懂
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4945变量写错悲剧。
阅读全文
摘要:From:http://blog.sina.com.cn/s/blog_694034130100wlrh.htmlFarey Sequence欧拉函数裸体,只要知道phi[x]为比X小且与X互质元素个数,预处理出phi[i]就OK了。View Code //递推预处理出phivoid get_phi() { int i,j,k; for(i=1;i<MM;i++) phi[i]=i; for(i=2;i<MM;i+=2) phi[i]>>=1; for(i=3;i<MM;i++) { if(phi[i]==i) { for...
阅读全文