LeeBlog

导航

04 2011 档案

HDU 2041 超级楼梯
摘要:这题就是一个递推的关系,不过还有一种数学方法递推#include<stdio.h>int num[45];void chart( ){ num[0] = 1,num[1] = 2; for( int i = 2; i < 45; ++i ) { num[i] = num[i-1] + num[i-2]; } }int main( ){ chart( ); int t,n; scanf( "%d",&t ); while( t--&&scanf( "%d",&n ) ) printf( "%d\n 阅读全文

posted @ 2011-04-30 21:08 LeeBlog 阅读(719) 评论(0) 推荐(0)

HDU 1879 继续畅通工程
摘要:跟畅通工程差不多,我的代码就在那上面改的#include<stdio.h>#include<stdlib.h>struct e{ int x,y,v;}val[10500];int n,m,set[105],sum;int cmp( const void *a,const void *b ){ return ( ( e * )a ) -> v - ( ( e * )b ) -> v;}int find( int i ){ return i == set[i] ? i :set[i] = find( set[i] );}void Kustra( ){ for( 阅读全文

posted @ 2011-04-30 09:02 LeeBlog 阅读(162) 评论(0) 推荐(0)

HDU 1272 小希的迷宫
摘要:这题数据真是恶心,开始敲出来了,一直WA,后来重敲一遍还是WA,最后看小白的代码才知道,还有( 0 0 ) 这种恶心的数据#include<stdio.h>#include<string.h>int set[100005],des[100005],f;int find( int x ){ return set[x] == x ? x : set[x] = find( set[x] );}void merge( int x,int y ){ int a = find( x ),b = find( y ); if( a != b ) set[a] = b; else if( 阅读全文

posted @ 2011-04-29 22:34 LeeBlog 阅读(208) 评论(0) 推荐(0)

HDU 2033 人见人爱A+B
摘要:#include<stdio.h>int main( ){ int t,h1,m1,s1,h2,m2,s2; scanf( "%d",&t ); while( t-- ) { scanf( "%d%d%d%d%d%d",&h1,&m1,&s1,&h2,&m2,&s2 ); h1 += h2,m1 += m2,s1 += s2; if( s1 > 59 ) s1 -= 60,m1++; if( m1 > 59 ) m1 -= 60,h1++; printf( "%d 阅读全文

posted @ 2011-04-29 14:26 LeeBlog 阅读(322) 评论(0) 推荐(0)

HDU 2057 A + B Again
摘要:#include<stdio.h>long long z,x,y;int main( ){ while( scanf( "%I64x%I64x",&x,&y ) != EOF ) { z = x + y; if( z < 0 ) printf( "-" ), z = -z; printf( "%I64X\n",z ); } return 0; } 阅读全文

posted @ 2011-04-29 13:50 LeeBlog 阅读(200) 评论(0) 推荐(0)

HDU 素数判定
摘要:#include<stdio.h>int x,y,f,n;int judge( int x ){ for( int i = 2; i <= x / 2;++i ) if( x % i == 0 ) { return 0; } return 1;}int main( ){ while( scanf( "%d%d",&x,&y ),x|y ) { f = 1; for( ;x <= y; ++x ) if( !judge( x*x+x+41 ) ) { f = 0; break; } puts( f ?"OK":&qu 阅读全文

posted @ 2011-04-28 21:52 LeeBlog 阅读(198) 评论(0) 推荐(0)

HDU 3032 杨辉三角 最短代码
摘要:#include<stdio.h>#include<string.h>int num[35][35],n;void chart( ){ num[1][1] = 1; for( int i = 2; i < 35; ++i ) for( int j = 1; j <= i; ++j ) num[i][j] = num[i-1][j-1]+num[i-1][j]; }int main( ){ mems... 阅读全文

posted @ 2011-04-28 16:18 LeeBlog 阅读(186) 评论(0) 推荐(0)

HDU 2010 水仙花数
摘要:#include<stdio.h>#include<stdlib.h>int n,m,a[4] = {153,370,371,407};int main( ){ while( scanf( "%d%d",&n,&m ) != EOF ) { int f = 0,c = 0; for( int i = 0; i < 4; ++i ) if( a[i] >= n && a[i] <= m ) { f ... 阅读全文

posted @ 2011-04-28 16:06 LeeBlog 阅读(499) 评论(0) 推荐(0)

HDU 2009求数列的和
摘要:水题#include<stdio.h>#include<math.h>int main( ){ double n,sum; int m; while( scanf( "%lf%d",&n,&m ) != EOF ) { sum = 0; for( int i = 0; i < m; ++i ) { sum += n; n = sqrt( n ); } printf( "%.2lf\n",sum )... 阅读全文

posted @ 2011-04-28 15:53 LeeBlog 阅读(492) 评论(0) 推荐(0)

hdu As Easy As A+B
摘要:纯水题 ,不解释#include<stdio.h>int t,n,num[1005];int main( ){ scanf( "%d",&t ); while( t-- ) { scanf( "%d",&n ); for( int i = 0; i < n; ++i ) scanf( "%d",&num[i] ); for( int i = 0,f = 1; i < n; ++i ) for( i... 阅读全文

posted @ 2011-04-28 15:39 LeeBlog 阅读(234) 评论(0) 推荐(0)

HDU 2034 人见人爱A-B
摘要:这题有两个条件,一是要A-B,这个可以用个标记,而是要排序,个人觉得先排序,再去A-B好做些.代码如下#include<stdio.h>#include<stdlib.h>#include<string.h>int num1[105],num2[105],des[105],n,m;int main( ){ while( scanf( "%d%d",&n,&m ),n|m ) { memset( des,0,sizeof( des ) ); for( int i = 0; i < n; ++i ) scanf( &qu 阅读全文

posted @ 2011-04-28 07:46 LeeBlog 阅读(956) 评论(0) 推荐(0)

HDU 1160 FatMouse's Speed 最长上升子序列 简单DP
摘要:这题开始看有点麻烦,因为又上升又下降的,但仔细想想,其实只要先处理一个变量,只剩下一个变量是不是就好处理了呢?对的?就跟最长子序列这是链接http://www.cnblogs.com/Lvsi/archive/2011/04/22/2025093.html.整体思路就是对重量排序,然后根据速度的的下降来找到最长的速度下降子序列.#include<stdio.h>#include<stdlib.h> int n,max;struct e{ int w,s,d,pri,flag;}v[1005];int cmp( const void *a,const void *b ){ 阅读全文

posted @ 2011-04-27 19:14 LeeBlog 阅读(279) 评论(0) 推荐(0)

HDU 1203 I NEED A OFFER! 简单DP
摘要:这题是Bone collector 是以姊妹题,同样的背包http://www.cnblogs.com/Lvsi/archive/2011/04/27/2030158.html不过比较大小的条件要换一下,至少有一个被选上的概率为1-( 1-dp[j-w[i]] ) * ( 1 - v[i] ),这个地方用到了高中的概率,很简单的仔细想想就过了.不多说了,来看代码把#include<stdio.h>#include<string.h>int n,m,w[10005];double v[10005],dp[10005];void DP( ){ memset( dp,0,si 阅读全文

posted @ 2011-04-27 16:00 LeeBlog 阅读(203) 评论(0) 推荐(0)

HDU 2602 Bone Collector 背包
摘要:这是一道经典的背包问题很水有两种方法,如果用二维做的话就要注意,体积要重0开始,因为测试数据很淫荡#include<stdio.h>#include<string.h>int n,V,t,val[1024],v[1024],dp[1024][1024];void DP( ){ memset( dp,0,sizeof( dp ) ); for( int i = 1; i <= n; ++i ) for( int j = 0; j <= V; ++j ) if( j >= v[i] && dp[i-1][j-v[i]] + val[i] & 阅读全文

posted @ 2011-04-27 11:16 LeeBlog 阅读(303) 评论(0) 推荐(0)

HDU 1257 最少拦截系统 DP
摘要:这题是一DP题,开始我听小白的直接暴力,结果测试数据能过,但提交就wa,我哭啊,呜~~~~,我重敲了一次,结果还是悲剧,几个小时啊,我就在这悲剧,最后翻出小晨的代码,发现好简单的,百度上说是最长上升子序列,于是直接1A了,最长上升子序列就是在一个数列a1-an中,从中选取几个数,这个数组成的序列递增,并且是a1到an中这样子序列中最长那一个。这个题其实也符合最长上升子序列,只要后面有一个比前面高的,就要加一个拦截系统(要增加一个拦截系统,首先要知道前面已经有多少涛拦截系统)。//这个能A#include<stdio.h>int n,dis[100000],max,dp[100000 阅读全文

posted @ 2011-04-25 16:13 LeeBlog 阅读(378) 评论(2) 推荐(0)

HDU 2571 命运
摘要:这题很DP就是跟前面一样一步一步来,先找到一部分,然后把这部分扩大,最后至全部,最终找出全局最优解,这里要注意,他给的测试数据太淫荡了,其实|K|>100,所以max初始化时给个1111吧#include<stdio.h>#include<string.h>int n,num[25][1024],m;int main( ){ int t; scanf( "%d",&t ); while( t-- ) { scanf( "%d%d",&n,&m ); memset( num,0,sizeof( num 阅读全文

posted @ 2011-04-23 22:44 LeeBlog 阅读(195) 评论(0) 推荐(0)

DP 动态规划小结
摘要:到今天为止,动态规划入门已经有好几天题也做了几个了,其实这部分题大概都是一个规律:要找到整个问题的最优解,先找到局部的最优解,然后将范围逐渐扩大,最后扩大到全局就可以了,例如HDU 1087 super jumping!先从第一个起,先把第一个的最优解找到,然后往后增加,找到第一个到第二个的最优解,并保存在数组2中然后再增加,找到第一个到第三个的最优解,保存在第3个数组中,然后一直往后推移,一直找到全部的最优解。这其中就存在一个问题,为什么要从前面一个一个找呢?为什么不一次找完呢?那样多省时间?我想说:会用我不用啊!傻啊!你!。有狠不把前面n-1个的最优解找出来,直接找到第一个到第n个的最优解 阅读全文

posted @ 2011-04-22 23:22 LeeBlog 阅读(179) 评论(0) 推荐(0)

HDU 1003 Max Sum
摘要:本题跟最大子序列差不多,是姊妹题,其实解决了上个,这个只要解决几个地方就可以了,请注意如果有全部是负数,就把这些负数中最大的输出来。#include<stdio.h>#include<string.h>int t,n,pos,num[110000],add[110024],pri[110024];void cal( ){ int pos = 1; for( int i = 1; i <= n; ++i ) { if( add[i-1] >= 0 && (add[i-1] + num[i] >= 0) )//here { add[i] = 阅读全文

posted @ 2011-04-22 20:38 LeeBlog 阅读(172) 评论(0) 推荐(0)

HDU 1231 最大连续子序列
摘要:这题是一郁闷题,开始我想了好久没思路,最后想到前面不是做了几个类似的DP么,只要把前一个的最大子序列找到了,那当前这一个的最大子序列就好办了,因此又是一个从前往后解决的问题,不过要注意最后一组测试数据,我在这里错了好几次#include<stdio.h>#include<string.h>int k,num[10024],add[10024],pri[10024],pos;void cal( ){ int m = 0; for( int i = 1; i <= k; ++i ) { if( (add[i-1] + num[i]) > 0 && 阅读全文

posted @ 2011-04-22 17:12 LeeBlog 阅读(635) 评论(0) 推荐(0)

如何产生各种随机数
摘要:产生int型随机数#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<time.h>int main( ){ //freopen( "1.in","r",stdin ); //freopen( "3.out","w",stdout ); srand( time( NULL ) ); int t,n = 10 ; while( n-- ) { printf 阅读全文

posted @ 2011-04-21 19:34 LeeBlog 阅读(1665) 评论(0) 推荐(0)

HDU 1176 免费馅饼
摘要:这题是一最优子结构的题,我开始暴力,结果一直TLE,最后听小白说这是一最优子问题,极像数塔,怎么像呢。这每一秒不就像极了每一层么,而且是从上往下时间增大的,为什么从下往上呢?因为要只到第一秒选哪个最大,就必须知道第二秒的分布情况,而要知道第二秒选哪个,就必须知道第三秒的情况,同理,可以一直往下推。这样不久像极了一个数塔么,要先解决下面的才知道上面的,而没一层的每一个又跟哪个有关系呢?显然由题意有每个只跟下面的三个有关,而且第0个和最后一个要特殊出理,所以有ch[y][++x]#include<stdio.h>#include<string.h>int n,ch[1000 阅读全文

posted @ 2011-04-20 19:12 LeeBlog 阅读(204) 评论(0) 推荐(0)

HDU 1087 Super Jumping! Jumping! Jumping! 简单DP
摘要:这是一道简单的DP,应该从前面往后面找,结果我一开始用递归,从后面往前面找,悲剧了很久这里的思想是先从第一个开始找到第一个的最优解,然后第二个,第三个。。。。而为什么要一个一个来求呢,那是因为后面的都是通过前面的来找最优解(dis[j] > max && num[j] < num[i] ),最后把全部的最优解都找到,而本题求的是全题的最优解,所以还要找到全局的最优解( Max )。#include<stdio.h>#include<string.h>int n,num[10000],dis[10000];int cal( ){ int Max 阅读全文

posted @ 2011-04-18 16:25 LeeBlog 阅读(183) 评论(0) 推荐(0)

HDU 2084 数塔 简单DP
摘要:这题是一水题,只需从第一层一直往下面找子树中较大的那一个就可以了,很快水了,不过用codeblocks编得郁闷,codeblocks上编译都过不了,直接提交就水了#include<stdio.h>int n,inf = 0x7fffffff,des[10000],num[10000];int cal( int sum,int i,int j ){ if( num[sum + j] == inf ) return 0; if( des[sum + j] ) return num[sum + j]; des[sum + j] = 1; if( j > i ) { sum += i 阅读全文

posted @ 2011-04-17 21:58 LeeBlog 阅读(194) 评论(0) 推荐(0)

文件
摘要://freopen ( "1.in", "r", stdin ); //freopen ( "1.out", "w", stdout ); 阅读全文

posted @ 2011-04-17 10:45 LeeBlog 阅读(129) 评论(0) 推荐(0)

HDU 1846 Brave Game
摘要:简单的巴什博弈,仔细分析可知要使第二个人赢,只有当(m+1)是n的因子时才会成立,所以如小白说直接puts( "" )即可;#include<stdio.h>int main( ){ int n,m,t; scanf( "%d",&t ); while( t-- && scanf( "%d%d",&n,&m ) ) puts( n % ( m + 1 ) ? "first" : "second" ); return 0;} 阅读全文

posted @ 2011-04-12 17:01 LeeBlog 阅读(184) 评论(0) 推荐(0)

HDU 3573 Buy Sticks 贪心
摘要:这题要小小的用到一点贪心的思想,哪里呢???????就是使每一根棍子在组合起来后剩余的最短,这样总的剩余也就最短,这样找出来的解便是最小解咯!小小算一下,便可知,剩余最小的分别是30 20 20 ,28 20 20 ,20 20 20,剩下来的都是两两搭配的,其实细想不用考虑哪两个搭配后剩余最小,因为就算再小也不能使三个组合起来了,最后剩下的就只能多用一条了#include<stdio.h> int min( int a,int b ){ return a < b ? a : b; } int main( ){ int x,y,z,t,sum,n; scanf( " 阅读全文

posted @ 2011-04-11 22:39 LeeBlog 阅读(203) 评论(0) 推荐(0)

HDU 2037 今年暑假AC 赤裸裸的 贪心
摘要:这道题是一道赤裸裸的贪心题,在这以前我只是看了贪心的思想,还没实现过,今天看了别人这道题代码才知道AC的代码原来是这样写的,小小水一下;这是一道典型的贪心算法,只要每一步都选占用时间最小的同时要使剩余时间最大的,也就是说,没一会你都要找一个结束最早的.当你找到第一个后,一定要使剩余的时间最长,以后每选一个都要考虑这个问题,这样你每一步都最优的话,结果也是最优的;具体做法就是先按结束的时间进行排序,然后每次取最小的,但是要保证和前面取的那个没有冲突#include<stdio.h>#include<stdlib.h> struct r{ int s,e; }act[124 阅读全文

posted @ 2011-04-11 21:06 LeeBlog 阅读(255) 评论(0) 推荐(0)

北大原题 我爱你啊 字符串处理
摘要:在这里我找到了找字符串子串的一种好方法,下面介绍给大家I:我爱你啊查看提交统计提问时间限制:1000ms内存限制:65536kB描述ftiasch是个十分受女生欢迎的同学,所以她总是收到许多情书。虽然她十分有魅力,然而她却是个低调的人。因此她从来不会告诉别人她到底收到了多少情书。ftiasch的好朋友1tthinking想知道她到底收到了多少情书。1tthinking知道,ftiasch每次收到一封情书,就会在日记最后写下一个包含"luvletter"子序列的串。比如现在ftiasch的日记是alduddvdletterflusvletetedr,那么ftiasch可能受到 阅读全文

posted @ 2011-04-10 16:07 LeeBlog 阅读(1141) 评论(0) 推荐(0)

HDU 2100 Lovekey
摘要:这是一大数题,直接套模板,其实跟十进制差不多,不过把对10取余改成对26取余就行了,水过#include<stdio.h>#include<string.h>#define max 250int num[max];char str1[max],str2[max];void cal( ){ memset( num,0,sizeof( num ) ); int len1 = strlen( str1 ),len2 = strlen( str2 ); for( int i = 0; i < ( len1 > len2 ? len1 : len2 ); ++i )/ 阅读全文

posted @ 2011-04-09 17:51 LeeBlog 阅读(252) 评论(0) 推荐(0)

HDU 2054 A == B ?
摘要:JAVAimport java.io.*;import java.util.*;import java.math.*;import java.io.BufferedInputStream; public class aa{ public static void main( String[] args ) { BigDecimal a,b; Scanner cin = new Scanner(System.in); while( cin.hasNext() ) { a = cin.nextBigDecimal(); b = cin.nextBigDecimal(); a = a.stripTra 阅读全文

posted @ 2011-04-09 13:47 LeeBlog 阅读(750) 评论(0) 推荐(0)

HDU 1402 A * B Problem Plus
摘要:这是大数相乘的一模板题;先把两个字符串变成ASCII码(不能和倒置放在一块,否则会出错),然后把他们全部倒置,然后再将他们相乘,最后再进位,不过这样会超时,将会在近段时间内发布不超时的代码#include<stdio.h>#include<string.h>#include<stdlib.h>#define Max 100000int num[Max];char str1[Max] = {0},str2[Max] = {0};void cal( ){ int len1 = strlen( str1 ),len2 = strlen( str2 ); for( 阅读全文

posted @ 2011-04-09 10:30 LeeBlog 阅读(390) 评论(0) 推荐(0)

strchr strstr
摘要:strchr函数原型extern char *strchr(const char *s,char c),在字符串*s中找第一个出现c的位置,如果没有则返回NULLstrstr函数原型strstr原型:extern char *strstr(char *haystack, char *needle),在字符串*haystack种查找第一次出现needle的位置,如果没有则返回NULL注意一下,接收这两个函数的返回值必须是字符串类型的指针,否则编译无法通过 阅读全文

posted @ 2011-04-08 22:08 LeeBlog 阅读(248) 评论(0) 推荐(0)

HDU 1316 How Many Fibs? 大数
摘要:Javaimport java.io.*;import java.util.*;import java.math.*;public class aa{ public static void main( String[] args ) { BigInteger f[] = new BigInteger[505],a,b; f[1] = BigInteger.valueOf(1); f[2] = BigInteger.valueOf(2); for( int i = 3; i < 505; ++i ) f[i] = f[i-1].add( f[i-2] ); Scanner cin = ne 阅读全文

posted @ 2011-04-08 21:21 LeeBlog 阅读(345) 评论(0) 推荐(0)

HDU 1541 Stars
摘要:这题让我情何以堪啊,悲剧了以下午,居然是审题不仔细,我原以为是对应输出每个星星的等级,后来突然发现是求每个等级的星星数目;这题是个树状数组的题,因为只要算左下角的星星数目( 包括正左,正下 ),而且给出数据的方式又是先按X轴排列,再按Y轴排列( 按这样的方式算出来的等级都不会变了,因为这样它的左下方不能再加星星了,这样就可以直接看它左下方的星星数目,即相应的等级),使得我们可以用树状数组来做,当到( a,b )点时,只要看小于a( a的左下方星星 )的数目就可以知道这个星星是多少等级了,然后再把这个等级的星星数目增加1这样就很轻松的算出结果了#include<stdio.h>#in 阅读全文

posted @ 2011-04-07 21:18 LeeBlog 阅读(269) 评论(0) 推荐(0)

HDU 1196 lowest bit
摘要:这题是树状数组的一入门题,lowest bit 就是将相应的十进制转换成二进制,在这个二进制数种从右往左数第一个不为0的位置的权值,有一种简单的做法#include<stdio.h>int main( ){ int n; while( scanf( "%d",&n ) ,n ) printf( "%d\n",n&( -n ) );}比较常规的做法#include<stdio.h>int main( ){ int n,x,y; while( scanf( "%d",&n ) ,n ) { 阅读全文

posted @ 2011-04-07 13:25 LeeBlog 阅读(249) 评论(0) 推荐(0)

lucky number 被恶心到的一题目
摘要:Problem F:Lucky numbersTime Limit:1000MS Memory Limit:65536KTotal Submit:108 Accepted:14 Description Digits 6 and 8 are lucky, while all others are unlucky. An integer is lucky if it contains only lucky digits in decimal notation. We would like to know the K-th lucky positive integer. Input The firs 阅读全文

posted @ 2011-04-05 22:42 LeeBlog 阅读(1003) 评论(0) 推荐(0)

输入密码
摘要:int inputps(char p1[]){ int i=0; char ch; while((ch=getch())&&ch!=13) { if(ch==27) return 0; if( ch==8 && i !=0 ) { printf( "\b \b" ); p1[--i] = 0; } else if(ch==8&&i==0) co... 阅读全文

posted @ 2011-04-05 17:39 LeeBlog 阅读(451) 评论(0) 推荐(0)

HDU 2689 sort it
摘要:此题就是求冒泡的次数,用冒泡做时间比较长,用树状数组做比较快#include<stdio.h>int num[1024],n;int main( ){ while( scanf( "%d",&n ) != EOF ) { for( int i = 0; i < n; ++i ) scanf( "%d",&num[i] ); int count = 0; for( int i = 0,f = 0; i < n - 1; ++i ) { f = 0; for( int j = 0; j + 1< n - i; + 阅读全文

posted @ 2011-04-05 14:23 LeeBlog 阅读(203) 评论(0) 推荐(0)

hdu 1166 敌兵布阵 树状数组 模板题
摘要:这题是树状数组入门的一模板题,非常基础,被小白成为"赤裸裸"的入门题,哈哈,一个plus,一个sum全部搞定#include<stdio.h>#include<string.h>#define lowbit( x ) ( x )&( -x )int tree[50024],num,n;void plus( int num,int x ){ while( x <= n ) { tree[x] += num; x += lowbit( x ); } }int sum( int x ){ int sum = 0; while( x ) { s 阅读全文

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