2012年5月25日

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3792n为负数,静态查询,用树状数组写,蛋疼可见一斑。打素数表的时候内层循环对i再加一个判断,是为了防止i*j因为溢出而恒真(引用自sx老祖)View Code #include <iostream>using namespace std ;const int MAX=100001;int prime[MAX],tree[MAX],num[MAX];int lowbit(int i){ return i&(-i);} void update(int x,int val){ for(int 阅读全文
posted @ 2012-05-25 14:37 LegendaryAC 阅读(315) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2368初中数学题,圆幂定理View Code #include <iostream>using namespace std ;int main(){ double r,w,l; int nCase=1; while(scanf("%lf",&r),r) { scanf("%lf%lf",&w,&l); if(r*r-(w/2)*(w/2)<(l/2)*(l/2)) printf("Pizza %d does not f 阅读全文
posted @ 2012-05-25 12:55 LegendaryAC 阅读(166) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1984字符串处理View Code #include <iostream>#include <string>using namespace std;int main(){ int t,n; char str[110]; scanf("%d",&t); for(int cas=1;cas<=t;cas++) { scanf("%d %s",&n,str); str[n-1]='\0'; printf(" 阅读全文
posted @ 2012-05-25 06:22 LegendaryAC 阅读(161) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1996递推View Code #include <iostream>#include <string>using namespace std;int main(){ int t; __int64 dp[30]={0,3}; for(int i=2;i<30;i++) dp[i]=dp[i-1]*3; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); printf(&quo 阅读全文
posted @ 2012-05-25 05:26 LegendaryAC 阅读(203) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1985小学计算题View Code #include <iostream>#include <string>using namespace std;int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++) { double n; string d; cin >> n >> d; if(d=="kg") printf("%d %.4l 阅读全文
posted @ 2012-05-25 05:08 LegendaryAC 阅读(225) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2393判断直角三角形View Code #include <stdio.h>#include <string.h>int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("Scenario #%d:\n",cas); if(a*a 阅读全文
posted @ 2012-05-25 04:31 LegendaryAC 阅读(209) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2391一路逆着推过去View Code #include <stdio.h>#include <string.h>const int INF=100000000;int map[1001][1001],dp[1001][1001];int Max(int a,int b,int c){ int max=-INF; if(a>max)max=a; if(b>max)max=b; if(c>max)max=c; return max;}int main(){ int t. 阅读全文
posted @ 2012-05-25 04:04 LegendaryAC 阅读(216) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1708不能直接用string加,最后的位数很多,会超内存。一定注意特殊处理k=0和k=1的情况。最后有空行View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <algorithm>using na 阅读全文
posted @ 2012-05-25 03:52 LegendaryAC 阅读(166) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3501继续欧拉函数,关键点是求小于n且与n互质的数的和。公式是Eular(n)*n/2,简略证明如下:原问题等价于一个数n,如果a与它互质,那么n-a也与它互质;反证法,假设n与a互质,n与n-a不互质设n和n-a的最大公约数为m,则n=p*m,n-a=q*m所以a=(p-q)*m,推导出a和n有公约数m,与假设矛盾View Code #include <iostream>#include <cstdlib>#include <cstring>#include <st 阅读全文
posted @ 2012-05-25 02:00 LegendaryAC 阅读(124) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1787依然是欧拉函数的模板题,求有多少个小于等于N且不与N互质的数,减去N本身再减去和N互质的就好了,小于N且和N互质的数的个数就用欧拉函数算了View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <al 阅读全文
posted @ 2012-05-25 00:48 LegendaryAC 阅读(164) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2824同上一题,裸欧拉函数View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <algorithm>using namespace std;const int MAX=3000001;int ph 阅读全文
posted @ 2012-05-25 00:09 LegendaryAC 阅读(161) 评论(0) 推荐(0) 编辑
 
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1286裸欧拉函数,欧拉函数是求比n小的数中有多少个与n互质View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <algorithm>using namespace std;const int MA 阅读全文
posted @ 2012-05-25 00:04 LegendaryAC 阅读(288) 评论(0) 推荐(0) 编辑