雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
上一页 1 ··· 31 32 33 34 35 36 37 38 39 ··· 50 下一页

2011年8月5日

摘要: 先写个暴力的,明天写个hash,或是后缀数组View Code #include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<stack>#include<set>#include<algorithm>using namespace std;char ss[30009];char cc[30009];int main(){ int n; while(scanf("%d",&n)!=EOF) { 阅读全文

posted @ 2011-08-05 22:26 huhuuu 阅读(261) 评论(0) 推荐(0) 编辑

2011年8月2日

摘要: 经典的dp,对我这种菜鸟有难度啊。。。由于石头可以围成一个环,所以要原来数据*2用记忆化搜索,其实就是dpView Code #include<stdio.h>#include<string.h>int a[209];int maxdp[209][209];int mindp[209][209];int sum[209][209];int max(int a,int b){ if(a>b)return a; else return b;}int min(int a,int b){ if(a>b)return b; else return a;}int dfs 阅读全文

posted @ 2011-08-02 18:13 huhuuu 阅读(1656) 评论(0) 推荐(0) 编辑

2011年8月1日

摘要: 在家没事干就要多做做比赛才是。。。 C题是搜索题 N个数字之间放N-1个"+","-","*" ,"/" 使每位不存在为k的数字。。。 注意点,超int,注意除数不为0,当结果为0是特判 //long long 注意0#include<stdio.h>#include<iostream>#inclu 阅读全文

posted @ 2011-08-01 22:37 huhuuu 阅读(441) 评论(0) 推荐(0) 编辑

2011年7月29日

摘要: 有向图强连通分量的Tarjan算法有个比较好的讲解http://www.byvoid.com/blog/scc-tarjan/zh-hans/学习一下,贴个比较好的模板View Code #include <iostream>#include <stack>using namespace std; const int MAXN = 10000 + 10; // 点的最大数量const int MAXM = 50000 + 10; // 边的最大数量 // 假设对边u-->vstruct EDGE{ int v; // 从u点出发能到达的点v int next; / 阅读全文

posted @ 2011-07-29 16:07 huhuuu 阅读(256) 评论(0) 推荐(0) 编辑

摘要: 开始用floyd可以,不过时间太慢了(N*N*N)后来枚举牛做DFS连通性检验,O(N*M)View Code #include<stdio.h>#include<string.h>int net[1009][1009];bool visit[1009];int cow[109];int c[1009];void dfs(int x){ c[x]++; visit[x]=1; for(int i=1;i<=net[x][0];i++) { if(!visit[net[x][i]]) dfs(net[x][i]); }}int main(){ int k,n,m; 阅读全文

posted @ 2011-07-29 10:03 huhuuu 阅读(243) 评论(0) 推荐(1) 编辑

2011年7月28日

摘要: 暴力枚举下,可以发现规律View Code #include<stdio.h>long long a[1000009];int main(){ a[1]=1; int n,i,id=1; while(scanf("%d",&n)!=EOF) { id=1; for(i=2;i<=n;i+=2) { a[i]=a[i+1]=(a[i-1]+a[id])%1000000000; id++; } printf("%lld\n",a[n]); } return 0;} 阅读全文

posted @ 2011-07-28 18:19 huhuuu 阅读(286) 评论(0) 推荐(0) 编辑

摘要: //有N个数,对于任一个数来说,其它的数有多少个是它的约数可以先把数存储在struct data{ int v;//该数字出现的次数 int add;//该数字的约数总数}node[1000009];枚举 存在的node[],在此基础上更新它的公倍数即可。。。View Code 阅读全文

posted @ 2011-07-28 15:40 huhuuu 阅读(497) 评论(0) 推荐(0) 编辑

摘要: 好久没写搜索的题目了500*500深搜肯定不行求最小步长,BFS,坐标有(-500,500),+500搞定ps:把状态量写成 i, j一类的,容易不混淆坐标。。。以前用X,Y表示一直要与数学里的坐标搞错的,囧写完由于用c提交CE了一次,cpp提交,一次AC...View Code #include<stdio.h>#include<iostream>#include<queue>#include<string.h>using namespace std;bool hash[1009][1009];int diri[4]={0,-1,0,1};in 阅读全文

posted @ 2011-07-28 14:52 huhuuu 阅读(632) 评论(0) 推荐(0) 编辑

摘要: 感觉这种从左向右统计的题目都可以用到栈来优化单调栈,从左向右扫ps:STL里的栈是比较快的,自己是、手写的栈效率跟它差不多啊。。。View Code #include<stdio.h>#include<iostream>#include<stack>using namespace std;int a[80009]; int main(){ int n; while(scanf("%d",&n)!=EOF) { int i; for(i=0;i<n;i++) scanf("%d",&a[i]); s 阅读全文

posted @ 2011-07-28 13:52 huhuuu 阅读(304) 评论(0) 推荐(0) 编辑

2011年7月27日

摘要: 暴力亦可过,同没意思。。。有个O(n)的算法从左向右扫{while{if(栈顶元素.h>当前元素.h) 入队,更新栈顶元素对应的牛的V ,结束while循环else 出队}直到队列为空}再从右向左View Code #include<stdio.h>#include<iostream>#include<stack>using namespace std;struct data{ int h,v,no;}node[50009];int all[50009];int main(){ int n; while(scanf("%d",&am 阅读全文

posted @ 2011-07-27 21:31 huhuuu 阅读(362) 评论(0) 推荐(0) 编辑

上一页 1 ··· 31 32 33 34 35 36 37 38 39 ··· 50 下一页