雕刻时光

just do it……nothing impossible
随笔 - 547, 文章 - 0, 评论 - 82, 阅读 - 86万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

03 2011 档案

摘要://注意用gets(a)是 scanf("%d",&tn);后用//getchar()时WA无语View Code #include<stdio.h>#include<math.h>int gcd(int max,int min){ if(min==0)return max; else gcd(min,max%min);}int main(){ int tn; char a[19]; scanf("%d",&tn); while(tn--) { scanf("%s",&a);//注意用g 阅读全文

posted @ 2011-03-31 22:15 huhuuu 阅读(329) 评论(0) 推荐(0) 编辑

摘要:产生素数表解决View Code #include <stdio.h>#include<math.h>bool su[20009];int suu[3009];int main(){ int n,i,j,add=0; for(i=2;i<=20000;i++) su[i]=0; for(i=2;i<=10000;i++) { for(j=2;j*i<=20000;j++) { su[i*j]=1; } } for(i=1;i<=20000;i++) { if(su[i]==0) { suu[add]=i; add++; } }//产生素数表 wh 阅读全文

posted @ 2011-03-31 22:12 huhuuu 阅读(239) 评论(0) 推荐(0) 编辑

摘要:View Code #include <stdio.h>int main(){ int year,month,day; while(scanf("%d%d%d",&year,&month,&day)!=EOF) { if ( month < 3 ) { year -= 1; month += 12; } char b[7][10] = {"sunday","monday","tuesday","wednesday","thursday" 阅读全文

posted @ 2011-03-31 21:20 huhuuu 阅读(307) 评论(0) 推荐(0) 编辑

摘要:View Code #include<stdio.h>#include<iostream>#include<algorithm>using namespace std;char a[29],b[29];bool cmp(char a,char b){ return a>b;//大到小 //使abc为中a为最高位与all->1枚举相符}int main(){ int n,t,i,j; while(scanf("%d%d",&n,&t)!=EOF) { getchar(); scanf("%c" 阅读全文

posted @ 2011-03-30 18:41 huhuuu 阅读(229) 评论(0) 推荐(0) 编辑

摘要:每搜到结果就随时在ji[]记录num是搜到的步数View Code #include<stdio.h>bool map[109][109];int ji[109],n,num;bool v[109];bool ok;void dfs(int s){ int ts,i; if(ok==1) return ; if(num==n) { ok=1; return ; } for(i=1;i<=n;i++) { if(map[s][i]==1&&v[i]==0) { num++; ji[num]=i; v[i]=1; dfs(i); if(ok==1) return 阅读全文

posted @ 2011-03-30 16:23 huhuuu 阅读(220) 评论(0) 推荐(0) 编辑

摘要:直接枚举整数算余数 明显会超时枚举(小数+整数) 求方后四舍五入,后求根号后比较小数,看是否一致即可注意:费解的精度问题如:对219048452111求根号,然后对求得的数进行*10运算,到后来开始的第九位小数会变化,由4到3的变化?解决方法,直接乘1000,000,000后求第9位数View Code #include<stdio.h>#include<math.h>int main(){ __int64 l,s,j; __int64 i,n,t1; while(scanf("%I64d%I64d",&l,&s)!=EOF) { d 阅读全文

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

摘要:咋一看还以为是,求森林里树的最小和实际增加0点就是求最小生成树了……View Code #include<stdio.h>int map[309][309];int dis[309];int p[309];bool use[309];int n;void krus(){ int i,min,rj,j; for(i=0;i<=n;i++) { use[i]=0; dis[i]=map[0][i]; } use[0]=1; int add=0; for(i=0;i<n;i++) { min=99999999; for(j=0;j<=n;j++) { if(use[j] 阅读全文

posted @ 2011-03-24 20:49 huhuuu 阅读(627) 评论(0) 推荐(0) 编辑

摘要:先写个暴力的找找规律暴力:View Code看看1到18的数据有规律可循奇数到偶数时是原来的奇数累积的+奇数第几位/2偶数到奇数是(前面的奇数第几位/2)*前面的奇数第几位View Code #include<stdio.h>int main(){ int n; while(scanf("%d",&n)!=EOF) { int i,add=0,j=0; for(i=4;i<=n;i++) { if(i%2==0) { j++; add+=j; } else { add+=j*(i-2); } } printf("%d\n",ad 阅读全文

posted @ 2011-03-24 15:04 huhuuu 阅读(511) 评论(0) 推荐(0) 编辑

摘要:dp[i]=min(dp[i],dp[j]+dp[i-j]+m)//dp [i]里放着i只牛渡河最少时间View Code #include<stdio.h>int dp[2509];int a[2509];int min(int a,int b){ return a>b?b:a;}int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int i,add=0; for(i=1;i<=n;i++) { int temp; scanf("%d",&temp 阅读全文

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

摘要:dp[i][j][k]记录在i,j格子里,剩下k步可以到达终点的路径条数View Code #include<stdio.h>#include<iostream>#include<math.h>using namespace std;bool map[109][109];int fa,fb,ea,eb,add;int f[4][2]={0,-1,-1,0,0,1,1,0};int dp[109][109][19];int n,m,all;int dfs(int a,int b,int step){ if(dp[a][b][step]!=-1)return d 阅读全文

posted @ 2011-03-23 20:48 huhuuu 阅读(406) 评论(0) 推荐(0) 编辑

摘要:无限RE后,换了个oj提交,AC了DFS搜索的关键是,找到下一步的方向,与准确的回朔View Code #include<stdio.h>int map[129][129];int Max,n;int f[4][2]={{0,-1},{-1,0},{0,1},{1,0}};void dfs(int a,int b,int step){ if(step>Max) Max=step; int sa,sb,i,j; for(i=0;i<=3;i++) { sa=a+f[i][0]; sb=b+f[i][1]; int ta=sa,tb=sb,sstep=step; if(ta 阅读全文

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

摘要:注意精度高点没错的View Code #include<stdio.h>#include<math.h>#define R 6378.00#define PI 3.1415926535#define hu 360/3.1415926535/2int main(){ int t; double x1,y1,z1,x2,y2,z2,th1,th2,a1,a2,dis,q; scanf("%d",&t); while(t--) { double a=sin(30/hu); scanf("%lf%lf%lf%lf",&th 阅读全文

posted @ 2011-03-22 14:16 huhuuu 阅读(232) 评论(0) 推荐(0) 编辑

摘要:G++提交会超时,C++不会超时View Code #include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int a[209],n,m,t,i; scanf("%d",&t); bool use; while(t--) { use=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf(& 阅读全文

posted @ 2011-03-18 17:19 huhuuu 阅读(333) 评论(0) 推荐(0) 编辑

摘要:用到STL里的next_permutation(&a[0],&a[le])//说明a[0]->a[le-1]是自由排列的View Code #include<iostream>#include<string.h>#include<algorithm>using namespace std;bool cmp(char a,char b){ return a<b;}int main(){ char a[209]; while(gets(a)) { int le=strlen(a); sort(&a[0],&a[le], 阅读全文

posted @ 2011-03-18 16:28 huhuuu 阅读(768) 评论(0) 推荐(0) 编辑

摘要:nlog(n)算法View Code #include<stdio.h>#define MAXN 30009int n,a[MAXN],s[MAXN],t[MAXN];//序列存在s里int lis()//单调不降子序列nlogn算法 { int l,r,mid,len=1; a[1]=s[1]; for(int i=2;i<=n;i++) { l=1,r=len; while(l<=r) { mid=(l+r)>>1;//除2 if(a[mid]<=s[i]) l=mid+1;//不降 else r=mid-1;//二分查找 } a[l]=s[i]; 阅读全文

posted @ 2011-03-18 11:22 huhuuu 阅读(441) 评论(0) 推荐(0) 编辑

摘要:n*n的做法dp[j]=max(1,dp[i]+1) if(a[i]<a[j])View Code #include<stdio.h>int a[1009];int dp[1009];int main(){ int n; while(scanf("%d",&n)!=EOF) { int i,j; for(i=1;i<=n;i++) { scanf("%d",&a[i]); dp[i]=1; } for(i=1;i<n;i++) { for(j=i+1;j<=n;j++) { if(a[i]<a[j 阅读全文

posted @ 2011-03-17 22:29 huhuuu 阅读(232) 评论(0) 推荐(0) 编辑

摘要:sqrt(1000000*1000000)数据发生超int处理办法,sqrt(1.0*1000000*1000000)即可prim不超时View Code #include<cmath>#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;#define MAX 0x3fffffffint n,m;struct data{ int x,y;}a[1009];double map[1009][1009];bool use[1009];double dis[ 阅读全文

posted @ 2011-03-17 21:02 huhuuu 阅读(726) 评论(0) 推荐(0) 编辑

摘要:看到 5000*50000有点不敢做了……其实bool数组很快View Code #include<stdio.h>bool f[50009];int a[5009];int main(){ int c,n; while(scanf("%d%d",&c,&n)!=EOF) { int i,j; for(i=1;i<=c;i++) f[i]=0; for(i=1;i<=n;i++) scanf("%d",&a[i]); f[0]=1; for(i=1;i<=n;i++) { for(j=c;j>= 阅读全文

posted @ 2011-03-17 15:21 huhuuu 阅读(313) 评论(0) 推荐(0) 编辑

摘要:set统计太方便了View Code #include<iostream>#include<set>using namespace std;struct data{ int x,y;}a[209];int main(){ int n; set<double>set1; while(scanf("%d",&n)!=EOF) { set1.clear(); int i,j; for(i=1;i<=n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } double 阅读全文

posted @ 2011-03-16 20:42 huhuuu 阅读(229) 评论(0) 推荐(0) 编辑

摘要:用贪心做初始i=j=1当i/j>=n/m时:j++反之i++随时记录最接近的值即可View Code #include<stdio.h>double jue(double a){ if(a>0)return a; return -a;}int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF) { int ri,rj,i,j; double e=n*1.0/m,t,cha=99999999; i=1; j=1; while(i<=32767&&j<=32767 阅读全文

posted @ 2011-03-16 20:11 huhuuu 阅读(161) 评论(0) 推荐(0) 编辑

摘要:bfs搜索,两次分别从两个出口搜,开数组ste[i][j]时刻记录(更新)点i,j到出口的最短距离最后在ste[i][j]查找最大值……View Code #include<stdio.h>#include<iostream>#include<queue>using namespace std;int map[209][80];int hash[209][80];int ste[209][80];int Max;int p[4][2]={0,-1,-1,0,0,1,1,0};int w,h;struct data{ int tei; int tej; int 阅读全文

posted @ 2011-03-16 15:53 huhuuu 阅读(216) 评论(0) 推荐(0) 编辑

摘要:从这里可以发现 只要知道递推方程,就可以把dp的过程用记忆化递归表示出来其实记忆化bfs 记忆化递归 ……只要是计算某种状态后,将其保存下来的过程,都是dp!!!View Code #include<stdio.h>double dp[200][200];double di(int n,int m){ if(dp[n][m]!=-1) return dp[n][m]; if(m==0) return dp[n][m]=0; if(m==1) return dp[n][m]=(n+1)*1.0/2; if(n==0) return dp[n][m]=1.0*di(2,m-2)+1; 阅读全文

posted @ 2011-03-15 22:36 huhuuu 阅读(240) 评论(0) 推荐(0) 编辑

摘要:View Code SELECT snum,sname,ssex,sbirth,dnumFROM s--where snum='S006'WHERE dnum='d02'SELECT score,snumfrom scwhere score>=60 and score<=85SELECT snum,snamefrom swhere sname like '王_'SELECT cnum,score*1.5from scwhere cnum='c01'and score is not nullselect distinct 阅读全文

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

摘要:http://192.168.7.42/problemDetail.aspx?pid=1477前打表找规律后来对数字是一的进行统计如103对最高位开始统计若为0 ,则不处理若该位为1则总数加上后面的数:加上以1*a[i](相应表中数),03+1若为大于1的数 则乘以该数的最高位(如203 则 加上以2*a[i](相应表中数),再加上03+1,再加上100)再到低位执行直到个位数View Code #include<stdio.h>#include<math.h>int main(){ int a[10]={0,1,20,300,4000,50000,600000,700 阅读全文

posted @ 2011-03-14 21:33 huhuuu 阅读(1022) 评论(0) 推荐(0) 编辑

摘要:3个小时,A了两水题,一个因为没初始wa了6次都是自己平时马马虎虎平时就应该以比赛来看待,不要还没想清楚就提交……这段时间就锻炼正确率!!!一旦有错误,要自己独立思考,不要求助网络 阅读全文

posted @ 2011-03-12 22:30 huhuuu 阅读(129) 评论(0) 推荐(0) 编辑

摘要:简单dfs搜索用全局变量max随时记录当时搜到的面积最大即可View Code #include<stdio.h>bool hash[109][109];int all,max;int n,m;int f[4][2]={0,-1,-1,0,0,1,1,0};void dfs(int x,int y){ int i,x1,y1; for(i=0;i<4;i++) { x1=x+f[i][0]; y1=y+f[i][1]; if(x1>=1&&x1<=n&&y1>=1&&y1<=m&&hash 阅读全文

posted @ 2011-03-12 15:04 huhuuu 阅读(210) 评论(0) 推荐(0) 编辑

摘要:http://mail.bashu.cn:8080/BSoiOnline/showproblem?problem_id=2111#top 阅读全文

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

摘要:一开始看还以为状态100种,搜索深度10000层,明显要爆内存或时间看了nocow解释,每种状态里每六个灯循环,就可以将基础状态找出:(按钮4:当按下此按钮,将改变所有序号是3*K+1(K>=0)的灯。例如:1,4,7...)这里可以发现循环一共就8种bool map[8][6]={ {0,0,0,0,0,0}, {0,0,1,1,1,0}, {0,1,0,1,0,1}, {0,1,1,0,1,1}, {1,0,0,1,0,0}, {1,0,1,0,1,0}, {1,1,0,0,0,1}, {1,1,1,1,1,1}};bu[8]={1,2,1,1,2,1,2,0};//达到每种状态的步 阅读全文

posted @ 2011-03-10 22:08 huhuuu 阅读(443) 评论(0) 推荐(0) 编辑

摘要:View Code #include<stdio.h>char s[100009];bool hash[100009];int main(){ int a,b,i,j; int t; scanf("%d",&t); while(t--) { scanf("%d",&b); { if(b<0) { printf("-"); b=-b; } a=1; for(i=0;i<=b;i++) { hash[i]=0; } int add=1; int qian; qian=a/b; a=a%b; hash 阅读全文

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

摘要:View Code ABEDFCHGCBADEFGHif n<=0 return; int p=先序中的字母在中序中的位置。 Build(p,(char *)pre+1,(char *)mid); //递归构造左子树的遍历 Build(n-1-p,pre+p+1,mid+p+1); //递归构造右子树的遍历#include <stdio.h>#include <string.h>#define MAXN 1000char mid[MAXN],pre[MAXN],ans[MAXN];void Build(int n,char *pre,char *mid,char 阅读全文

posted @ 2011-03-10 14:25 huhuuu 阅读(216) 评论(0) 推荐(0) 编辑

摘要:注意是顺时针转!!!View Code #include<stdio.h>#define N 360bool a[5][N+N];int v[5];int main(){ int i,j; int n; while(scanf("%d",&v[0])!=EOF) { for(i=0;i<5;i++) { for(j=0;j<360;j++) { a[i][j]=0; } } int add=0; int fi,end; scanf("%d",&n); for(i=1;i<=n;i++) { scanf(&qu 阅读全文

posted @ 2011-03-09 19:04 huhuuu 阅读(199) 评论(0) 推荐(0) 编辑

摘要:要知道,a[100]字符串的首地址与char *a 是不一样的,a[100]字符串的首地址不是指针,char *a就是指针!!!View Code //swap(char *a,char *b)#include<iostream>#include<string.h>using namespace std;void swap(char *a,char *b){ int al,bl,i; al=strlen(a)+1; bl=strlen(b)+1; if(al<bl)al=bl; int temp; for(i=0;i<al;i++) { temp=a[i]; 阅读全文

posted @ 2011-03-08 19:59 huhuuu 阅读(1621) 评论(0) 推荐(0) 编辑

摘要:主要用到公式(表示m个数里存在1的个数最多n的组合数)而这个公式的实现过程是递归,遇到n==0||m==0返回1后回归,有值时也返回值后回归思路就是,先看左边第1位(不存在1时)的组合数是否小于di,若小于则说明左边第1位存在1…^View Code #include<stdio.h>unsigned int dp[33][33];unsigned swap(int a,int b) { if(a==0||b==0)return 1; if(dp[a][b]!=0)return dp[a][b]; return dp[a][b]=swap(a-1,b-1)+swap(a,b-1); 阅读全文

posted @ 2011-03-08 19:49 huhuuu 阅读(260) 评论(0) 推荐(0) 编辑

摘要:有时候一个人就会默默的沉默有时候不知道自己的方向有时候感觉就像在做梦有时候脑海里一直挥之不去你的脸有时候希望一切都没有发生有时候希望我就像晴天娃娃有时候希望你会回心转意有时候也希望你过得更好有时候有多么想见你有时候希望可以不再见到你———————— 阅读全文

posted @ 2011-03-07 17:59 huhuuu 阅读(143) 评论(0) 推荐(0) 编辑

摘要:有规律,每次乘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 阅读(318) 评论(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 阅读(234) 评论(0) 推荐(0) 编辑

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

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

摘要: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 阅读(255) 评论(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 阅读(1664) 评论(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 阅读(270) 评论(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 阅读(240) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示