摘要:开关灯问题:有n个人和n盏灯,第一个人开所有的灯,第二个人按所有2的倍数的灯的开关,第三个人按所有3的倍数的灯的开关,依此类推,求最后多少盏灯亮着解法:按奇数次则亮,偶数次则灭,所以因子数为奇数亮,所以平方数亮,所以即求n内平方数个数,为(int)sqrt(n),如n=16,根号16=4,所以平方数有1*1,2*2,3*3,4*4,即1、4、9、16四个。code:#include<stdio.h>#include<math.h>int main(){ int t,n,m; scanf("%d",&t); while(t--) { scanf
阅读全文
摘要: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",&
阅读全文
摘要:hdu1798: http://acm.hdu.edu.cn/showproblem.php?pid=1798题意:给出两个圆的圆心坐标和半径,求两圆相交面积code:#include<iostream>#include<cstdlib>#include<cstdio>#include<cmath>const double pi=acos(double(-1));double min(double x,double y){ if(x>y) return y; else return x;}int main(){ double x1,y1,r
阅读全文