LeeBlog

导航

随笔分类 -  ACM(水题系列)

1 2 3 4 下一页

水题类
HDU 3791
摘要:这个题是考数据结构的二叉排序树,对每个输入的字符串都建立一棵二叉树,然后进行先序遍历,进行后序遍历( 因为由两个遍历可以确定一棵树 ),所以每次只要先建立一棵树,然后把他们的先序遍历和后序遍历比较,若都相等就YES,否则NO#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct Node{ int data; struct Node *lc,*rc;}node,*Link;int n,f,c,cnt;char f1[11],la1[11],f2[11],la2[11];void 阅读全文

posted @ 2011-06-13 19:14 LeeBlog 阅读(802) 评论(0) 推荐(0)

HDU 2020 绝对值排序 堆优化
摘要:用二叉排序树写一个#include<stdio.h>typedef struct Node{ int data; struct Node *lc,*rc;}node,*Link;int n,f;inline int fab( int a ){ return a > 0 ? a : -a;}void insert( Link *L,int x ){ if( *L ) { if( fab( x ) > fab( ( *L ) -> data ) ) insert( &( *L ) -> lc,x ); else insert( &( *L ) - 阅读全文

posted @ 2011-06-13 16:33 LeeBlog 阅读(625) 评论(0) 推荐(0)

HDU 1164 Eddy's research I
摘要:题意:把一个数拆成素数,从小到大排列。如果把素数全部存起来大概快一半的样子#include<stdio.h>#include<string.h>#define Max 65540int n,prime[Max+5],num[Max],c = 0;void DFS( int x ){ if( x == 0 ) return ; for( int i = 0; i < c; ++i ) { if( x % num[i] == 0 ) { printf( x == n?"%d":"*%d",num[i] ); DFS( x / n 阅读全文

posted @ 2011-05-25 09:41 LeeBlog 阅读(302) 评论(0) 推荐(0)

HDU 1397 Goldbach's Conjecture
摘要:这题用素数筛选法。。。。 不过数组要开大点。。。 否则会挂掉去#include<stdio.h>#include<string.h>#define max 1 << 15 + 1int num[max + 5],n;void fun( ){ memset( num,0,sizeof( num ) ); num[0] = num[1] = 1; for( int i = 2; i <= max / 2; ++i ) if( !num[i] ) for( int j = i + i; j <= max; j += i ) num[j] = 1;}in 阅读全文

posted @ 2011-05-23 12:25 LeeBlog 阅读(286) 评论(0) 推荐(0)

HDU 1128 Self Numbers
摘要:这题一看是水,二看还是水,最后一做就挂了,归咎于数组越界啊。我却全然不知。。。。 //62MS水过#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<ctype.h>#define Max 1000005int num[Max + 1];inline int cal( int i )//用内联快很多{ int sum = i; while( i ) { sum += i % 10; i /= 10; } return sum;}vo 阅读全文

posted @ 2011-05-23 09:37 LeeBlog 阅读(311) 评论(0) 推荐(0)

HDU 1171 Big Event in HDU 多重背包
摘要:这题是我第一次写多重背包,1RE,1WA,#include<stdio.h>#include<string.h>int n,v[55],num[55],dp[250000],sum,all;int max( int a,int b ){ return a > b ? a : b;}int main( ){ while( scanf( "%d",&n ),n > 0 ) { sum = 0; for( int i = 0; i < n; ++i ) scanf( "%d%d",&v[i],& 阅读全文

posted @ 2011-05-17 23:47 LeeBlog 阅读(274) 评论(0) 推荐(0)

HDU 2094 产生冠军
摘要:这个题开始一看是并查集,后来改了很久,怎么改也改不过,只得翻大牛的代码,原来大牛们都是这样写的,左边的为胜利者,有边的为失败者,如果左边的胜利者只有一个没在右边出现过,那么这个就是产生的冠军,否则产生不了、#include<stdio.h>#include<string.h>int set[1005],n,f,c,num[1005];char ch[1005][20];int search( char str[] ){ for( int i = 1; i < c; ++i ) if( !strcmp( str,ch[i] ) ) return i; strcpy( 阅读全文

posted @ 2011-05-13 11:40 LeeBlog 阅读(702) 评论(0) 推荐(0)

HDU 2036 改革春风吹满地
摘要:一个多边形公式s = ( x1*y2-x2*y1 ) + ( x2*y3 - x3*y2 )……( xn-1*yn - xn*yn-1 ) + ( xn*y0 - x0*yn );一个公式就OK了#include<stdio.h>int n;double x[105],y[105],sum ;int main( ){ while( scanf( "%d",&n ),n ) { sum = 0; for( int i = 0 ; i < n; ++i ) { scanf( "%lf%lf",&x[i],&y[i] 阅读全文

posted @ 2011-05-13 10:04 LeeBlog 阅读(257) 评论(0) 推荐(0)

HDU 1008 Elevator
摘要:#include<stdio.h>int main( ){ int n,sum,a,b; while( scanf( "%d",&n ),n ) { sum = 0; a = 0; for( int i = 0; i < n; ++i ) { scanf( "%d",&b ); sum += 5; if( b > a ) sum += ( b - a ) * 6; if( b < a ) sum += ( a - b ) * 4; a = b; } printf( "%d\n",sum ) 阅读全文

posted @ 2011-05-13 00:36 LeeBlog 阅读(237) 评论(0) 推荐(0)

HDU 2564 词组缩写
摘要:这个要注意把缩写的最后一个字符串置为0#include<stdio.h>#include<string.h>#include<ctype.h>char str[1000],s[1000];int main( ){ int t; scanf( "%d%*c",&t ); while( t-- ) { gets( str ); int i = 0,c = 0; while( str[i] ) { if( !isalpha( str[i] ) ) { ++i; continue; } if( str[i] > 'Z' 阅读全文

posted @ 2011-05-11 17:40 LeeBlog 阅读(335) 评论(0) 推荐(0)

HDU 1005 Let the Balloon Rise
摘要:水题 。。 就是从给出的字符串中找出出现次数最频繁的那一个。。。直接暴力。。 给没个字符串一个编号。。#include<stdio.h>#include<string.h>int n,c,des[1005];char ch[1005][20];int search( char str[] ){ for( int i = 0; i < c; ++i ) if( !strcmp( ch[i],str ) ) return i; return c++;}int main( ){ while( scanf( "%d",&n ),n ) { c 阅读全文

posted @ 2011-05-11 16:54 LeeBlog 阅读(227) 评论(0) 推荐(0)

HDU 2156 分数矩阵
摘要:找关系。。。。1/1 1/2 1/31/2 1/1 1/21/3 1/2 1/1出了1以外有这样的规律1/2有(3-1)*2个1/2有 ( 3 - 2 ) * 2个那么可以猜想结果为sum = n * 1 / 1 + ( n - 1 ) * 2 * 1 / 2 + ( n - 2 ) *2*1/3+.......+(n-i+1)*2*1/i;#include<stdio.h>#include<stdlib.h>#include<math.h>int n;double cal( ){ double sum = 0; sum = n; for( int i = 阅读全文

posted @ 2011-05-11 11:44 LeeBlog 阅读(280) 评论(0) 推荐(0)

HDU 1035 Robot Motion
摘要:一纯水题..... 直接深搜并记忆化加标记#include<stdio.h>#include<stdlib.h>char map[1005][1005];int des[1005][1005],m,n,s,f1,f2,inf = 0x7fffffff,dep[1005][1005],s1,s2,s3;void DFS( int y,int x,int step ){ if( des[y][x] )//若遇到回路 { f2 = 1; s2 = step; s3 = dep[y][x]; return ; } if( f1 || map[y][x] < 0 )//若遇 阅读全文

posted @ 2011-05-08 08:28 LeeBlog 阅读(251) 评论(0) 推荐(0)

HDU 2068 RPG的错排
摘要:这题跟hdu 2049 差不多,那个是从N个中选M个,这个是从N个从选1,2,3.......N/2个,错排与组合.....#include<stdio.h>long long num[28];void chart( ){ num[0] = 1; num[1] = 0; num[2] = 1; for( int i = 3; i < 28; ++i ) num[i] = ( i - 1 )*( num[i-1] + num[i-2] ); }long long f( int n,int k ){ double sum = 1; for( int i = n,j = 1; j 阅读全文

posted @ 2011-05-07 17:11 LeeBlog 阅读(308) 评论(0) 推荐(0)

HDU 1465 不容易系列之一
摘要:一个错排公式直接解决 水过#include<stdio.h>long long num[25];void chart( ){ num[1] = 0; num[2] = 1; for( int i = 3; i < 25; ++i ) num[i] = ( num[i-1] + num[i-2] ) * ( i - 1 ); }int main( ){ chart( ); int n; while( scanf( "%d",&n ) != EOF ) printf( "%I64d\n",num[n] ); return 0;} 阅读全文

posted @ 2011-05-07 09:58 LeeBlog 阅读(288) 评论(0) 推荐(0)

HDU 2617 Happy 2009
摘要:这题深受北大那题影响啊,这是链接http://www.cnblogs.com/Lvsi/archive/2011/04/10/2011484.html这题要注意happy的顺序不能变,所以要最先产生h然后a然后p,p,y,给每个字母都对应一个数组的数,要产生a时必须有h,要产生p时必须有a,要产生happy时,必须有一个h,一个a,两个p,一个y;而且要保证所有的happy都没颠倒次序,所以每一个字母的个数不能超过前面那个字母的个数( 例如hayppahppy,这种只有一个 )#include<stdio.h>#include<string.h>int n,num[5] 阅读全文

posted @ 2011-05-06 15:32 LeeBlog 阅读(267) 评论(0) 推荐(0)

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 阅读(290) 评论(0) 推荐(0)

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 阅读(382) 评论(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 阅读(279) 评论(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 阅读(267) 评论(0) 推荐(0)

1 2 3 4 下一页