Shirlies
宁静专注认真的程序媛~
摘要: 应该是第一次搞二叉树的题目,这一题貌似难度有点大啊,有人的代码写的很简洁易懂,VERY GOOD!也是初次接触cin.clear(),挺有意思的。我个人认为这位解释的比较好http://zhidao.baidu.com/question/252322814.html?fr=qrl&cid=866&index=3还有就是那个好的代码了http://www.sunnybtoc.com/page/M0/S625/625828.html 阅读全文
posted @ 2012-02-02 20:59 Shirlies 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 数学题,求积分……#include "stdio.h"#include "math.h"int main(){int cn;scanf("%d",&cn);while(cn--){double x0,y0;double x1,y1,x2,y2;double a,b,c;scanf("%lf%lf",&x0,&y0);scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);a=(y1-y0)/((x1-x0)*(x1-x0 阅读全文
posted @ 2012-01-19 22:07 Shirlies 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 我是用笨方法做的,首先找出该值的范围,然后分奇数偶数讨论。#include "stdio.h"#include "math.h"int main(){int n;int temp;while(scanf("%d",&n)==1&&n){temp=(int)pow(n,0.5);if(temp*temp==n){if(temp%2==0)printf("%d 1\n",temp);elseprintf("1 %d\n",temp);continue;}if(temp%2== 阅读全文
posted @ 2012-01-18 21:20 Shirlies 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 用double就可以了Double(双精度浮点型)变量存储为 IEEE 64 位(8 个字节)浮点数值的形式,它的范围在负数的时候是从 -1.79769313486232E308 到 -4.94065645841247E-324,而正数的时候是从 4.94065645841247E-324 到 1.79769313486232E308(来自百度)#include "stdio.h"#include "math.h"int main(){double n,p;double temp;while(scanf("%lf%lf",&n 阅读全文
posted @ 2012-01-18 20:41 Shirlies 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 欧拉函数φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3欧拉公式那么φ(12)=12*(1-1/2)*(1-1/3)=4)#include "stdio.h"int prime[10000]={1,2,3};int main(){int t;int n;int count;int i,k=3,j,ok;for(i=4;i<32768;i++){ok=1;for(j=1 阅读全文
posted @ 2012-01-18 17:26 Shirlies 阅读(166) 评论(0) 推荐(0) 编辑
摘要: a/gcd(a,b)与b/gcd(a,b)互素就可以做出来了……#include "stdio.h"int gcd(int a,int b){if(a%b==0)return b;elsereturn gcd(b,a%b);}int main(){int a,b;int t,temp;int i;scanf("%d",&t);while(t--){scanf("%d%d",&a,&b);temp=a/b;for(i=2;i<1000000;i++){if(gcd(i,temp)==1){break;}}p 阅读全文
posted @ 2012-01-18 16:22 Shirlies 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 思路是:通分后求分子的最小公倍数,在除以通分后的分母(看了别人的思路才知道分数的最小公倍数是这样求的,起初只是知道要求公倍数,但是不知道怎么求,汗,我可怜的数学啊~~~)#include "stdio.h"__int64 gcd(__int64 a,__int64 b){if(a%b==0)return b;elsereturn gcd(b,a%b);}int main(){int T;__int64 t1,q1,t2,q2,ts,kq,t;scanf("%d",&T);while(T--){scanf("%I64d/%I64d %I6 阅读全文
posted @ 2012-01-18 10:07 Shirlies 阅读(370) 评论(0) 推荐(0) 编辑
摘要: #include "stdio.h"#include "math.h"int is_prim(int n){int i;for(i=2;i<=sqrt(n);i++)//晕,这里用i*i<=n就超时了,没有头绪,莫名其妙,网上看了别人的代码,就将它改成这样,竟然A了,汗~~~……………………哈,忽然想到是为什么了,理由是:当循环到i=46340时i*i<n;但i=46341时i*i=2147488281,超过了int的最大值,溢出变成负数,仍然满足i*i<n!n不是太大的话,运气好还能碰上101128442溢出后等于2147483 阅读全文
posted @ 2012-01-17 23:12 Shirlies 阅读(323) 评论(0) 推荐(0) 编辑
摘要: #include "iostream"#include "stdlib.h"#include "string.h"typedef struct{int p;int w;}rice;int cmp(const void *a,const void *b){ rice *c=(rice *)a; rice *d=(rice *)b;return c->p-d->p;}int main(){int n,m;int c;rice r[1005];scanf("%d",&c);while(c--){sca 阅读全文
posted @ 2012-01-17 21:47 Shirlies 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Problem DescriptionAcmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Internet bar doing problems overnight. So many girls want to meet and Orz him. But Orz him is not that easy.You must solve this problem first.The problem is :Give you a sequence of distinct integers, choose 阅读全文
posted @ 2012-01-17 21:08 Shirlies 阅读(253) 评论(0) 推荐(0) 编辑