LeeBlog

导航

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 19 下一页

2011年5月6日 #

HDU 2160 母猪的故事 水题... 斐波拉契数

摘要: #include<stdio.h>long long num[25];void chart( ){ num[0] = 0; num[1] = 1; num[2] = 2; for( int i = 3; i < 25; ++i ) num[i ] = num[i-1] + num[i-2]; }int main( ){ chart( ); int t,n; scanf( "%d",&t ); while( t-- ) { scanf( "%d",&n ); printf( "%I64d\n",num[ 阅读全文

posted @ 2011-05-06 13:36 LeeBlog 阅读(282) 评论(0) 推荐(0) 编辑

2011年5月5日 #

HDU 1286 找新朋友 筛选法

摘要: 这题要用到筛选法的思想,否则直接TLE,这题我很郁闷,原以为这题用这种方法肯定要超时的,就一直不敢用,没想到水了.郁闷#include<stdio.h>#include<string.h>int n,num[40000];int main( ){ int t; scanf( "%d",&t ); num[0] = num[1] = 0; while( t-- ) { scanf( "%d",&n ); memset( num,0,sizeof( num ) ); for( int i = 2; i <= n 阅读全文

posted @ 2011-05-05 11:00 LeeBlog 阅读(372) 评论(0) 推荐(0) 编辑

HDU 3792 Twin Prime Conjecture 这题要用筛选法......

摘要: 开始我直接打表一直不能过,后来知道有删选法这一东西,水过62MS#include<stdio.h>#include<string.h>int num[100005],c[100005];void shuaixuan( )//筛选法{ memset( num,0,sizeof( num ) ); for( int i = 2; i < 100005; ++i ) for( int j = 2; i * j < 100005; ++j ) num[i*j] = 1;}void chart( )//预处理{ num[1] = 1; memset( c,0,size 阅读全文

posted @ 2011-05-05 10:13 LeeBlog 阅读(269) 评论(0) 推荐(0) 编辑

HDU 1215 七夕节 筛选法

摘要: 这题我开始暴力,结果TLE,后来想到这种题应该都有精简的方法,就去网上搜,没想到新学了一招,筛选法,估计最小公倍数也能这样做了,哈哈#include<stdio.h>#include<string.h>long long num[500005];void shaixuan( ){ for( int i = 1; i < 500005; ++i ) num[i] = 1; for( int i = 2; i < 500005; ++i ) for( int j = 2; j * i < 500005; ++j ) num[i*j] += i; }int 阅读全文

posted @ 2011-05-05 09:32 LeeBlog 阅读(258) 评论(0) 推荐(0) 编辑

2011年5月4日 #

HDU 1258 Sum It Up

摘要: 这题郁闷了,排序过不了,后来仔细想想不用排序, 于是果断删了,没想到删了再杭电能过,在北大不能过,真郁闷了这题是以简单DFS,在搜到时把结果存起来,然后再暴力搜索,看是否已存在这样的sum,最后一次性输出来就o了.先贴一神代码把.... 这个hdu poj 都能过( 这个算法非常好.以后对于组合问题都能这么干了 )#include<stdio.h>int t,n,num[20],flag,res[20];void DFS( int p,int s,int nu ){ if( s == t ) { flag = 1; for( int i = 0; i < nu; ++i ) 阅读全文

posted @ 2011-05-04 22:40 LeeBlog 阅读(212) 评论(0) 推荐(0) 编辑

HDU 1016 Prime Ring Problem DFS + 记忆化搜索

摘要: 说实话,这题真没做出来,思路有,但是有问题一直不能解决,后来别人提供的思路.不多说了....这题就是要求形成一个环,没两个相邻的数之和不能为素数,当然最后一个要考虑他跟第一个的关系,这里的DFS其实只要递归一个东西,而我递归的东西却一直不对,主要受变形课影响,其实递归的东西肯定是当前的数目,然后把当前的数存在数组里,以便下一次递归的时候可以跟这一次的数比较....#include<stdio.h>#include<string.h>int n,num[25],des[25];int gcd( int n ){ int f = 0; if( n == 2 || n == 阅读全文

posted @ 2011-05-04 20:04 LeeBlog 阅读(219) 评论(0) 推荐(0) 编辑

HDU 2072 单词数

摘要: 这里跟前面两个字符串处理差不多,http://www.cnblogs.com/Lvsi/archive/2011/05/03/2035640.htmlhttp://www.cnblogs.com/Lvsi/archive/2011/05/04/2036156.html#include<stdio.h>#include<string.h>int n;char str[10005],ch[1005][1005];void sort( ){ int i = 0; while( str[i] ) { if( str[i] == ' ' ) { ++i; cont 阅读全文

posted @ 2011-05-04 10:02 LeeBlog 阅读(361) 评论(0) 推荐(0) 编辑

HDU 1062 Text Reverse

摘要: 这题一水题 .... 据说可以用函数做 ( strtok) ,没用,没看懂,自己写了一个.. 水果,不过记住中间有很多空格要原样输出......还有把字符串分开后,在每个后面都得赋值ASCII为0额#include<stdio.h>#include<string.h>int n,c;char str[1005],ch[1005][1005];void sort( ){ int i = 0; while( str[i] ) { int j = 0; while( str[i] == ' ' ) ch[c][j++] = str[i++]; ch[c][j] 阅读全文

posted @ 2011-05-04 09:49 LeeBlog 阅读(356) 评论(0) 推荐(0) 编辑

2011年5月3日 #

HDU 3293 sort

摘要: 这里最好用qsort排序,而在写cmp函数时要注意,对rank进行排序是从大到小,所以那里不要写反了,还有排序优先级是origin,,rank,字典序,这里别弄错了,我悲剧额,对rank排序一直是错的,最后听小白一说才恍然大悟,在此鸣谢小白,直接上代码#include<stdio.h>#include<stdlib.h>#include<string.h>struct e{ char w[25],o[25],l[25];}p[505];int n;int cmp1( char s1[],char s2[] ){ if( s1[0] == s2[0] ) re 阅读全文

posted @ 2011-05-03 22:44 LeeBlog 阅读(218) 评论(0) 推荐(0) 编辑

HDU 1862 EXCEL排序

摘要: 这个很水用个结构体,不过排序要用快排,别用冒泡,否则超时.TLE 我就悲剧了一次#include<stdio.h>#include<stdlib.h>#include<string.h>struct e{ char t[20],name[20]; int s;}p[100005];int n,c;int cmp1( const void *a,const void *b ){ struct e f1 = *( (e *)a ),f2 = *( ( e * )b ); return strcmp( f1.t,f2.t );}int cmp2( const vo 阅读全文

posted @ 2011-05-03 20:24 LeeBlog 阅读(280) 评论(0) 推荐(0) 编辑

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 19 下一页