随笔分类 - ZOJ 平时练习
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4317有可能error串包含相互的error串,所以建立fail的时候val的标记也要相互转移。View Code typedef long long ll;ll N;#define mod 1000000009 #define debug puts("wrong");#define ROOT 0const int MAX_NODE=2222;//stringnum*stringlenconst int CHI=2; //儿子数ll dp[222][MAX
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1837有dp[floor]=sum{dp[floor+i]/6}+1 (1<=i<=6) 可以列出方程,方向分up和down讨论View Code
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4712View Code int N,M;//注意题目说x为正整数,0不算int Extend_euc(int a,int b,int&x,int&y) { if(b==0) {x=1,y=0;return a;} int d=Extend_euc(b,a%b,x,y); int tmp=x; x=y; y=tmp-(a/b)*y; return d;}void modeq(int a,int b,int n) { int e,i,d,x,y,t...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showSubmission.do?submissionId=3568082View Code //确定king只有一个后可以在O(N)解决每次询问const int MM = 331630;const int maxn = 31;typedef long long int64;#define debug puts("wrong"); int N,M,Q;char ss[MM][100];set<pair<int,int> >sbt;map<string,int>mp;m
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3216View Code //复杂度O(sqrt(N)),蛮有意思的const int MM = 11111;typedef long long int64;int64 N;void solve() { int64 i,j,k,sum=0,tmp; scanf("%lld",&N); for(i=1;(i*i)<=N;i++) { tmp=N/i; sum=sum+i*(N/i-N/(i+1)); if(tmp!=i...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3221View Code //逆推const int MM = 1111111;#define debug puts("wrong")//typedef __int64 int64;const double lep=1e-10;int N,M, n,m;map<vector<int>,bool>mp;vector<int>st;vector<int>en;void get_data() { int i,j,k
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3221对于指数取欧拉函数需要注意一下,a^x%P=a^(x%phi(P)+phi(P))%PView Code //A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的应用const int MM = 1111111;#define debug puts("wrong")typedef __int64 int64;const double lep=1e-10;int64 a,b,P,n,mod;const int maxn = 3; //矩阵大小struct Ma
阅读全文
摘要:http://acm.fzu.edu.cn/problem.php?pid=1759View Code //A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的应用const int MM = 1111111;#define debug puts("wrong")typedef __int64 int64;const double lep=1e-10;int64 N,mod; char str[MM];int64 euler(int64 x) { int64 i, res=x; for(i=2;(i*i)<=x;i++) { if(x%i==
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1686View Code //存在到0边的奇数步的路,则先手胜const int MM = 11111;#define inf 0x3f3f3f3f#define debug puts("wrong")typedef long long int64;int N,M;int num[MM];void get_data() { int i,j,k; scanf("%d",&N); for(i=0;i<N;i++) scanf(
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1684View Code //重新建树,求两点间最短距离const int MM = 11111;#define inf 0x3f3f3f3f#define debug puts("wrong")typedef long long int64;int num[MM], N, tot;int chd[MM], len; //节点的儿子个数bool vis[MM];vector<int>edge[MM];struct Info{int node,s
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2838View Code //对于x,y,z树上的位置进行分类讨论/* z z t t /\ / /\ /\ x y t z y x z /\ / \ x y x y*/const int MM = 55555;int N, M;vector<...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3416注意当0也是满足条件的情况下, 假设数字分解有cnt位,则结果将会多出cnt-1个0,即ans-cnt+1为最后结果。View Code
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4013记忆化搜索,学到啦用map做映射不用担心数组开多大的问题,还有map<vector<int>,int>vis;可以对一个list进行映射,由于10^9以内的素数因子的组合很少,可以记忆化。View Code //记忆化搜索,学到啦用map做映射不用担心数组开多大的问题,还有map<vector<int>,int>vis;//可以对一个list进行映射,由于10^9以内的素数因子的组合很少,可以记忆化。const int M
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=49950-1背包,按照时间排序保证总时间最小。以后写if-else注意多continue,还有0-1背包不需要多加一维。以后注意。View Code const int MM = 1111;#define debug puts("wrong")//typedef __int64 int64;int N,M;int dp[MM][4];struct Info{int t,v;}g[MM];bool cmp(Info x,Info y) {return x.t
阅读全文
摘要: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
阅读全文
摘要:模拟栈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://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5递归模拟, 记录pair<a,b>是否被访问过。View Code const int MM = 111111;#define debug puts("wrong")#define clr(a) memset(a,0,sizeof(a))bool vis[1005][1005];int op[MM];int Ca, Cb, N;bool ff;void gao(int x) { if(x==1) puts("fill A")
阅读全文
摘要:JTrim the NailsBFS()乱搞fingernail记为goal(1<<M-1)M位的1。nail clipper记录正串和反串的状态,从初始状态搜索到变为0为最小的步数。状态压缩DP从最开始的goal,进过修减,goal变的越来越小,符合无后效性,每步记录最小。
阅读全文