LeeBlog

导航

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

2011年5月3日 #

HDU 1106 排序

摘要: 简单排序,这里先把一个字符串按5来分成很多字符串,然后对这些字符串进行比较#include<stdio.h>#include<string.h>#include<stdlib.h>int n;char str1[1005],str2[1005][1005];void sorts( )//将字符串分成很多个{ memset( str2,0,sizeof( str2 ) ); int i = 0; while( str1[i] ) { if( str1[i]&&str1[i] == '5' )//处理前面多余的5 { ++i; c 阅读全文

posted @ 2011-05-03 19:41 LeeBlog 阅读(480) 评论(0) 推荐(0) 编辑

HDU 1201 18岁生日

摘要: 这里主要是纠结在闰年上面,没有生日的肯定是闰年的2月29,对吧,还有如果今年或18年后是闰年就要考虑,是在2月29前还是在2月29后#include<stdio.h>int judge( int x ){ if( x % 400 == 0 || ( x % 4== 0 && x % 100 != 0 ) ) return 1; return 0;}int main( ){ int y,m,d,t; while(scanf( "%d",&t )!= EOF) { while( t-- ) { scanf( "%d-%d-%d&qu 阅读全文

posted @ 2011-05-03 12:40 LeeBlog 阅读(357) 评论(0) 推荐(0) 编辑

HDU 1173 采矿

摘要: 像这种找最短距离的,只要先排序,然后找中间点就可以了,哈哈,跟着类似的还有 2083 简易板之间最短距离#include<stdio.h>#include<stdlib.h>int n;double x[1000005],y[1000005];int cmp( const void *a,const void *b ){ return *( ( double * )a ) > *( ( double * )b ) ? 1 : -1;}int main( ){ while( scanf( "%d",&n ),n ) { for( int 阅读全文

posted @ 2011-05-03 10:35 LeeBlog 阅读(558) 评论(0) 推荐(0) 编辑

HDU 2083 复习时间

摘要: 这题要自己推算一下,开始还准备用贪心的,结果弄了很久弄不出,最后看大神的报告原来是由数学推出来的m > n;f1 = ( 100 - m )*( 100 - m ) + (m - n)(m-n);f2 = ( 100 - n )*( 100 - n );用二式减去一式分析可得f2总是大于f1,所以只要直接找到一个最小的n就可以了#include<stdio.h>int n,m,min;int main( ){ int t; scanf( "%d",&t ); while( t-- ) { scanf( "%d%d",&n 阅读全文

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

HDU 1596 find the safest road

摘要: 这题就是一最短路,不过,在这里是找"最长路",所以在初始化时不能赋值为0x7fffffff,而赋为0,还有存贮是记得用double型#include<stdio.h>int n,q,des[1005],s,e;double map[1005][1005],dis[1005];double Dij( ){ for( int i = 0; i <= n; ++i ) des[i] = 0,dis[i] = 0; dis[s] = 1; for( int i = 1; i <= n; ++i ) { int pos = -1; double max = - 阅读全文

posted @ 2011-05-03 07:52 LeeBlog 阅读(222) 评论(0) 推荐(0) 编辑

2011年5月2日 #

HDU 1233 还是畅通工程

摘要: 这题是一个最小生成树,用kustra做,在给结构体排序时要用快排,不能冒泡,否则超时,这里有我冒泡的代码,你可以提交试试#include<stdio.h>#include<stdlib.h>int set[105],n,m,sum;struct e{ int x,y,v;}val[10000];int cmp( const void *a,const void *b ){ return ( ( e * )a )-> v - ( ( e * )b ) ->v;}int find( int x ){ return x == set[x] ? x : set[x] 阅读全文

posted @ 2011-05-02 13:35 LeeBlog 阅读(180) 评论(0) 推荐(0) 编辑

2011年4月30日 #

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 阅读(695) 评论(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 阅读(150) 评论(0) 推荐(0) 编辑

2011年4月29日 #

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 阅读(201) 评论(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 阅读(311) 评论(0) 推荐(0) 编辑

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