上一页 1 ··· 168 169 170 171 172 173 174 175 176 ··· 182 下一页
摘要: 本来想到二分查找,后来发现直接使用pow,floor和ceil就可以。这些函数在cmath中。View Code #include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){ freopen("D:\\t.txt", "r", stdin); int b, n; while (scanf("%d%d" 阅读全文
posted @ 2011-02-28 12:28 undefined2024 阅读(235) 评论(0) 推荐(0)
摘要: 这一题学会了两个东西:1.cmath中的exp(x)函数是用来求e的x次幂。2.对于double类型scanf时要用%lf,printf时要用%f。这个题就是个套公式的简单题View Code #include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int getid(char *st){ if (strcmp(st, "T") == 0) return 0 阅读全文
posted @ 2011-02-28 11:15 undefined2024 阅读(669) 评论(0) 推荐(0)
摘要: 题意:对于4*n+1(n为自然数)组成的集合,乘法在该集合中是封闭的。现规定h-prime是这个集合的数字中只有1和本身能整除的数(不含1)。其余为h合数。从h合数中划分出一部分数字,这些数是由两个h素数相乘得到的,称之为h-semi。现要求在指定1~n范围内有多少个h-semi。分析:筛法,就是把h合数全筛掉,开始默认所有的都是h素数,然后枚举两个数,把他们的乘积筛掉。这道题要求h-semi,所以我们要改进一下,把原来的true false标注变为0(h素数), 1(非h-semi的合数), 2(h-semi)的标注。在筛的过程中如果发现枚举的两个数暂时没被筛掉,我们就把他们的乘积标注为h- 阅读全文
posted @ 2011-02-27 11:19 undefined2024 阅读(733) 评论(0) 推荐(0)
摘要: BFS,注意判断数组是否越界,注意处理n==k的情况View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <queue>using namespace std;#define maxn 100005struct Item{ int step, pos; Item() { } Item(int s, int p) : step(s), pos(p) { }};int visited[maxn];int main 阅读全文
posted @ 2011-02-25 21:56 undefined2024 阅读(470) 评论(0) 推荐(0)
摘要: 题意:给定每个矩形的高度以及底边在数轴上的起点和终点。各矩形间可能有重叠。问它们覆盖的总面积是多少。分析:线段树的题,开始以为不能用线段树,因为如果在已经插入了许多又瘦又高的楼的情况下,插入一个又矮又宽的楼横跨他们的话,就会对中间相交部分进行许多次修改复杂度远大于O(logn)。后来看了答案才知道,可以先把楼房按照高度从小到大排序,这样就不会出现这样的情况了。后来wa的原因是建树的范围比实际范围大了1个单位。另外,跨度横坐标需要离散化。#include #include #include #include #include using namespace std;#define MAX_INT 阅读全文
posted @ 2011-02-25 20:35 undefined2024 阅读(1005) 评论(0) 推荐(0)
上一页 1 ··· 168 169 170 171 172 173 174 175 176 ··· 182 下一页