摘要: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
阅读全文
摘要: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++)
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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][
阅读全文