LeeBlog

导航

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) 编辑

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 阅读(559) 评论(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) 编辑