摘要: 该题WA了上午,呜呜.......最后,幸亏lvsi的提醒,把getsum函数改为long long 型就过了,该题与poj 2992 Divisors是同一类型这里我们就不累叙了,这里要注意的就是2与5的对数,我们就把2与5成对处理掉,因为2*5=10,我们就可以忽略2与5成对的情况; 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 int hash[500024]={0}; 6 int prime[100000]; 7 int 阅读全文
posted @ 2011-11-18 15:38 wutaoKeen 阅读(293) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<string.h> #include<stdlib.h>int Prime( int prime[] ){ int i,j,count=0; for( int i=2;i<=500;i++ ) { int j=2,t=i/2; for( ;j<=t;j++ ) if( i%j==0 ) break; if( j==( t+1 ) ) { prime[count++]=i; } } return count;}in... 阅读全文
posted @ 2011-11-17 17:42 wutaoKeen 阅读(296) 评论(0) 推荐(0) 编辑
摘要: 该题是一道简单的DP题,我采用两头分别求最大的和,先顺序求每个数段的最大和,然后反过来求每个数段的最大的和;分析:先求顺序从左到右到该数的最大和;反序就是SUM[i-1]=SUM[i]+num[i-1#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ int n,T,num[50024],sum[50024],a,SUM[50024]; scanf( "%d",&T ); while( T-- ) { memset( sum,0,sizeof( sum 阅读全文
posted @ 2011-11-17 17:23 wutaoKeen 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 该题是一个DFS的应用,该题的关键在于建立一个结构体来存储要你填入的数据,这要就不会像无头苍蝇一样乱搜索,同时也会剪枝不少;同时就是判断横竖不能又重复的,也就是不能等于你要填入的数据,还有一点就是每个小3*3的矩阵要是1-9不能重复,这里就对该坐标x/3*3就可以了;#include<stdio.h>#include<stdlib.h>#include<string.h>struct node{ int x,y; }q[100];int map[9][9],res,flag;bool judge( int n,int num ){ for( int i=0; 阅读全文
posted @ 2011-09-21 21:33 wutaoKeen 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 这题就是是一个最小生成树问题,题目意思,给你一个数n接下来有n-1行,每一行代表一个地点与多个地点相连结,例如:A 2 B 12 I 25代表A与连接2地方B,I并且价钱为12,25;#include<stdio.h>#include<stdlib.h>struct t{ int x,y,time;}kru[1024];int set[27];int find( int x ){ return set[x]==x?x:set[x]=find( set[x] ); }int cmp( const void *a,const void *b ){ return ( ( t. 阅读全文
posted @ 2011-09-19 11:28 wutaoKeen 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 这个题是AC自动机的模版题;#include<stdio.h>#include<stdlib.h>#include<string.h>struct node{ int flag; node *ch[26],*fail; }*q[1000024];node *empty( ){ node *t=( node * )malloc( sizeof( node ) ); memset( t->ch,NULL,sizeof( t->ch ) ); t->flag=0 ; t->fail=NULL ; return t; }void build_ 阅读全文
posted @ 2011-09-18 20:14 wutaoKeen 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 这题就是注意一下当状态为1是就把这两给点合并到一个集合;#include<stdio.h>#include<stdlib.h>struct t{ int x,y,flag,cost; }kru[5024];int set[124];int cmp( const void *a,const void *b ){ return ( ( t * )a )->cost-( ( t * )b )->cost; }int find( int x ){ return x==set[x]?x:set[x]=find( set[x] ); }int kruscal( i... 阅读全文
posted @ 2011-09-18 11:13 wutaoKeen 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 我用G++提交就TLE了,而用C++提交就过了,这题就是一个并查集与克鲁斯卡尔。#include<stdio.h>#include<stdlib.h>struct t{ int x,y,cost; }kru[25024];int set[524];int cmp( const void *a,const void *b ){ return ( ( t * )a )->cost - ( ( t * )b )->cost; }inline int find( int x ){ return set[x]==x?x:set[x]=find( set[x] ); . 阅读全文
posted @ 2011-09-18 11:09 wutaoKeen 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 刚开始知道要用记忆化搜索,然而自己仍然去试了一下暴力DFS,TLE之后我就死心了,就利用记忆化搜索,就是用一个标记hash标记已经拜访过的;#include<stdio.h>#include<stdlib.h>#include<string.h>char num1[224],num2[224],num3[424];int len1,len2,len3,flag,hash[224][224];void DFS( int a,int b,int c ){ if( len3==c ) { flag=1; return ; } if(... 阅读全文
posted @ 2011-09-17 19:41 wutaoKeen 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 该题是一道记忆化搜索,这题与HDU 1248 漫步校园是一样的,这里不解释了。#include<stdio.h>#include<stdlib.h>#include<string.h>const int inf=0x7fffffff;struct t{ int x,y; }q[1000024];int n,m,hash[1024],dis[1024],map[1024][1024];void empty(){ for( int i=0;i<=n;i++ ) { hash[i]=0; dis[i]=inf; ... 阅读全文
posted @ 2011-09-17 16:44 wutaoKeen 阅读(148) 评论(0) 推荐(0) 编辑