LeeBlog

导航

2011年5月11日 #

HDU 2079 选课时间(题目已修改,注意读题) 母函数 || 多重背包

摘要: 今天做这题才知道原来母函数的原型不是从第二个括号开始,那不过是优化而已,除了1^n,2^n那种类型可以从2开始外其他都要从1开始。好了,上代码吧。#include<stdio.h>int n,k,m1[450],m2[450],t,a,b;int num[15],sc[15];void gf( ){ for( int i = 0; i <= num[1];i++ ) m1[i*sc[1]] = 1; for( int i = 2; i <= k;++i ) { for( int j = 0; j <= n; ++j ) for( int l = 0; l < 阅读全文

posted @ 2011-05-11 22:00 LeeBlog 阅读(612) 评论(1) 推荐(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 阅读(313) 评论(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 阅读(217) 评论(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 阅读(272) 评论(0) 推荐(0) 编辑

福州大学 括号问题

摘要: 这题当时比赛的时候想到是深搜,但当时深搜做得不多,没做得出,后来看以大牛代码才会写,主要是判断条件写得好。#include<stdio.h>#include<string.h>char str[20];int l,cnt;void DFS( int k,int num ){ if( num < 0 )//右括号不能多于左括号 return ; if( k == l ) { if( num == 0 )//当左边跟右边的括号相等且刚好到最后一个,就是一中符合条件的可能 ++cnt; return; } if( str[k] == '(' ) DFS( 阅读全文

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

HDU 1312 Red and Black

摘要: 这题忒easy了。。。。直接搜吧。。 都不用回溯的#include<stdio.h>#include<string.h>int map[25][25],des[25][25],n,m,sx,sy;void DFS( int y,int x ){ if( map[y][x] == '#'||des[y][x]||y > n || x > m ) return ; des[y][x] = 1; DFS( y - 1,x ); DFS( y + 1,x ); DFS( y,x - 1 ); DFS( y,x + 1 ); }int main( ){ 阅读全文

posted @ 2011-05-11 10:29 LeeBlog 阅读(174) 评论(0) 推荐(0) 编辑

HDU 1010 Tempter of the Bone

摘要: 这题如果是神搜的一基本题目,每次都向四个方向神搜就行了,不过要考虑剪枝,要用奇偶剪枝,否则TLE,还有用一个标记f,标记当前是否已找到来剪枝。如果还想减少时间就可以在输入时做一个标记,看当前有多少个可以走的点,如果可以走的点小于总时间t那么肯定是NO,这样要减少很多饿。。。。#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>int n,m,t,sx,sy,ex,ey,f;int maz[10][10],des[10][10];void DFS( int y,i 阅读全文

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