雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2011年3月6日

摘要: 有规律,每次乘i后,记录第i个乘数的结果,去掉右边的零后,取1000的余数保存,继续乘i+1……View Code #include<stdio.h>int main(){ int n; while(scanf("%d",&n)!=EOF) { int a=1,i; for(i=2;i<=n;i++) { a*=i; while(a%10==0) a/=10; a=a%1000; } printf("%d\n",a%10); }} 阅读全文

posted @ 2011-03-06 21:27 huhuuu 阅读(312) 评论(0) 推荐(0) 编辑

摘要: 输出第N个丑数假设存在第k个丑数,然后想知道第k+1个丑数,可以通过枚举n个给定的质数与前k个丑数相乘,得出大于第k个丑数且最小的数,但n个给定的质数与前k个丑数相乘时显然会浪费时间,可以开pr[]数组保存第i个给定的质数已经乘到第几个丑数了思想:保存当前状态,避免重复计算……View Code #include<stdio.h>int a[109];int pr[109];int cou[1000009];int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int i,j; for(i= 阅读全文

posted @ 2011-03-06 20:46 huhuuu 阅读(231) 评论(0) 推荐(0) 编辑

2011年3月4日

摘要: 自己刷个水题,加油 阅读全文

posted @ 2011-03-04 21:49 huhuuu 阅读(95) 评论(0) 推荐(0) 编辑

2011年3月3日

摘要: View Code并查集的题目也做的差不多了,关键还是理解find(),un()的过程……接着搜索一礼拜……#include<stdio.h>#define N 30009int f[N];int all[N];int up[N];int find(int pos){ if(f[pos]==-1) return pos; int temp; temp=f[pos]; f[pos]=find(f[pos]); up[pos]+=up[temp]; return f[pos];}void un(int a,int b){ int fa=find(a); int fb=find(b); 阅读全文

posted @ 2011-03-03 22:23 huhuuu 阅读(252) 评论(0) 推荐(1) 编辑

摘要: http://acm.nuaa.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1087思路:也是并查集,逆向思维,题目要求先把边所有边连起来,再去删; 那可以这样想,先(除去需要删的边)把边连起来(这里可以排序实现),在倒着执行操作,把删边当做连边操作即可一开始把前面的边保存起来,然后去掉后面为D的边,倒着执行D和P的操作(即遇到d,就可并a,b),答案倒着输出即可View Code #include<stdio.h>#include<iostream>#include<algorith 阅读全文

posted @ 2011-03-03 19:50 huhuuu 阅读(1653) 评论(0) 推荐(0) 编辑

摘要: 可以作为入门题练习,增加信心~~View Code #include<stdio.h>#define N 50005int f[N];bool v[N];int find(int pos){ if(f[pos]==-1)return pos; return f[pos]=find(f[pos]);}int un(int a,int b){ int fa=find(a); int fb=find(b); if(fa==fb)return 0; f[fa]=fb;return 1;}int main(){ int n,m,i,a,b,ca=1; while(scanf("%d 阅读全文

posted @ 2011-03-03 16:05 huhuuu 阅读(267) 评论(0) 推荐(0) 编辑

摘要: 如果n==7,则从0枚举到222222(三进制)0看做是空格,1看做+,2看做减号-若果是1 2 3+4+5+6-7,则将其前三个数合成一个数123+4+5-7(方法是使shu[n]=3,for(1->7))View Code #include<stdio.h>#include<math.h>int shu[10];int fu[10];int bao[10];int main(){ int n; while(scanf("%d",&n)!=EOF) { int i,temp=0,first=0; for(i=1;i<=n-1;i 阅读全文

posted @ 2011-03-03 13:39 huhuuu 阅读(238) 评论(0) 推荐(0) 编辑

2011年2月28日

摘要: 学习了种类并查集,又学了离散化STL里的map容器这几题里比较侧重对find()函数的理解View Code #include<iostream>#include<map>using namespace std;#define N 10005int f[N];int r[N];map<int,int>mm;int find(int pos){ if(f[pos]==-1) return pos; int t=f[pos]; f[pos]=find(f[pos]);//使f[pos]路径压缩,指向最终根节点 r[pos]=(r[pos]+r[t])%2;//r 阅读全文

posted @ 2011-02-28 22:15 huhuuu 阅读(288) 评论(0) 推荐(0) 编辑

2011年2月27日

摘要: 把点与点的关系保存在连接矩阵里就好了,如果距离小于等于规定距离的话就赋值为1然后不断做(做符合条件)合并操作即可……View Code #include<stdio.h>#define N 1005int f[N];int d;int ji[N];struct data { int x,y;}p[N];bool map[N][N];int dis(data a,data b){ int temp=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); if(temp<=(d*d)) return 1; return 0;}int find(int p 阅读全文

posted @ 2011-02-27 18:51 huhuuu 阅读(157) 评论(0) 推荐(0) 编辑

摘要: 这道题目,理解了好久,其实只要把关系图画一下,有些概念自然就知道了……当然也使我明白了,并查集因为通过路径压缩后,一个节点的find()过程,最多需要2次递归,最多一次修改……这样题目就理解了……View Code #include <stdio.h>#define max 50000+5int f[max];int r[max];/*rank[x]表示father[x]与x的关系rank[x] == 0 表示father[x]与x是同类rank[x] == 1 表示x吃father[x]rank[x] == 2 表示father[x]吃x*/void make_set(int x 阅读全文

posted @ 2011-02-27 15:33 huhuuu 阅读(307) 评论(0) 推荐(0) 编辑