2012年7月25日

摘要: pku1125: http://poj.org/problem?id=1125题意:群发短信:给出n个群发者,输出的第i行的第一个输出k表示第i个发信息者可以给k个人发短信,接着输出k对数据,每对两个数分别表示被联系者的编号和与其联系时间,问由哪个人群发短信花费的时间最短,转化为最短路问题即为:给出每个点到其他点的距离,求所有点到其他点最长距离的最小值,并输出该起点解法:floyd求出每个点到各点的最短路,再枚举各点,求出各个最大值,再取最小值code:#include<iostream>#include<cstdio>#include<cstdlib>in 阅读全文
posted @ 2012-07-25 22:02 acmer-jun 阅读(179) 评论(0) 推荐(0) 编辑
摘要: hdu2141: http://acm.hdu.edu.cn/showproblem.php?pid=2141题意:给出3个数列a、b、c,再给出s个x,问是否存在a[i]+b[j]+c[k]=x解法:先让a+b,得到和数列sum,并排序,再给c排序,再二分搜sum中是否存在sum[i]=x-c[j]code:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;bool cmp(int a,int b){ return 阅读全文
posted @ 2012-07-25 21:50 acmer-jun 阅读(149) 评论(0) 推荐(0) 编辑
摘要: hdu2272: http://acm.hdu.edu.cn/showproblem.php?pid=2272题意:给出n个人的预期排名,问怎样的排名使得所有人的实际排名与预期排名之差的绝对值的和最小贪心法:将预期排名从小到大排序,再从1~n名依次给他们排名,则所求值最小。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>using namespace std;struct str{ char s[30]; 阅读全文
posted @ 2012-07-25 21:41 acmer-jun 阅读(172) 评论(0) 推荐(0) 编辑
摘要: hdu2117: http://acm.hdu.edu.cn/showproblem.php?pid=2117题意:输入n和m(1<=n<=10^7,1<=m<=10^5),求1/n小数点后第m个数解法:模拟除法。code:#include<iostream>#include<cstdio>#include<cstdlib>int main(){ int m,n,s,x; while(scanf("%d%d",&n,&m)!=EOF) { s=1; for(int i=0;i<=m;i++) 阅读全文
posted @ 2012-07-25 21:35 acmer-jun 阅读(138) 评论(0) 推荐(0) 编辑
摘要: hdu2116: http://acm.hdu.edu.cn/showproblem.php?pid=2116题意:输入k(2<=k<=64),再输入x,y(-2^(k-1)<=x,y<=2^(k-1)-1),判断x+y是否溢出(即是否超出[-2^(k-1),2^(k-1)-1])解法:若直接相加可能溢出,所以用max-x>y和min-x<y来判断.code:#include<iostream>#include<cstdio>#include<cstdlib>int main(){ long long int x,y,ma 阅读全文
posted @ 2012-07-25 21:32 acmer-jun 阅读(197) 评论(0) 推荐(0) 编辑
摘要: hdu2115: http://acm.hdu.edu.cn/showproblem.php?pid=2115题意:输入n组名字和对应的时间(分:秒),要求按时间长度由短到长排序,并输出对应排名,若时间一样,则按名字字典序排序,名次可以并列。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;struct name{ char v[200],w[200]; int 阅读全文
posted @ 2012-07-25 21:27 acmer-jun 阅读(136) 评论(0) 推荐(0) 编辑
摘要: hdu2114: http://acm.hdu.edu.cn/showproblem.php?pid=2114题意:求x=1^3+2^3+3^3+……+n^3结果的后四位。解法:原式x=((n*(n+1))/2)^2,求后四位,即求x%10000,由公式(a*b)%m=((a%m)*(b%m))%m,(a/2)%m=(a%m)/2可求。code:#include<iostream>#include<cstdio>#include<cstdlib>int n;int main(){ int s; while(scanf("%d",& 阅读全文
posted @ 2012-07-25 21:21 acmer-jun 阅读(150) 评论(0) 推荐(0) 编辑
摘要: hdu2138: http://acm.hdu.edu.cn/showproblem.php?pid=2138题意:给出n个数,求素数个数解法:为了不超时,加速法:求出65535内的素数,对于65535以后的数,若不能被这些素数整除,则为素数。证明如下:对于大于65535的整形非素数,有两种情况,一种是至少有一个因子在65535内,另一种是所有因子都在65535内,但是65536*65535>int,所以第二种不可能。code:#include<iostream>#include<cstdio>#include<cstdlib>int v[65536] 阅读全文
posted @ 2012-07-25 21:14 acmer-jun 阅读(155) 评论(0) 推荐(0) 编辑
摘要: hdu2135: http://acm.hdu.edu.cn/showproblem.php?pid=2135题意:旋转一个n*n的矩阵,m为负代表逆时针,m为正代表顺时针,输出旋转后的矩阵code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>char v[20][20];int main(){ int m,n; while(scanf("%d%d",&n,&m)!=EOF) { getchar(); for(int i=0 阅读全文
posted @ 2012-07-25 21:08 acmer-jun 阅读(148) 评论(0) 推荐(0) 编辑
摘要: hdu2133: http://acm.hdu.edu.cn/showproblem.php?pid=2133题意(解法):已知0年1月1日是周6,输入一个日期,问星期几code:#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>int tianshu1[]={31,28,31,30,31,30,31,31,30,31,30,31};int tianshu2[]={31,29,31,30,31,30,31,31,30,31,30,31};char tab[7][ 阅读全文
posted @ 2012-07-25 21:04 acmer-jun 阅读(182) 评论(0) 推荐(0) 编辑

导航