上一页 1 ··· 33 34 35 36 37 38 39 40 41 ··· 66 下一页
摘要: 一个需要进行转化的题目。x = (n*(n+k))/k = n*n/k + n,最后求小于等于N且是N^2的因子的数的个数。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>#include <map>using namespace std;int N;map<int,int>mp;map<int,int>::iterator it;int fun(){ int ret = 1; for (it = mp.begi 阅读全文
posted @ 2012-07-25 12:01 沐阳 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 简单的快速矩阵幂:Fn 1 1 Fn-1 = * Fn-1 1 0 Fn-2把前面的矩阵作快速幂就可以了。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>#define MOD 10000using namespace std;struct Matrix // ['meitriks]{ int a[2][2]; void New (int x, int y, int z, int w) { a[0][0] ... 阅读全文
posted @ 2012-07-25 10:05 沐阳 阅读(242) 评论(0) 推荐(0) 编辑
摘要: 该题与上题相比增加了多种分法,而不只是四条边,问题是最多能够分成多少条边。上题代码其实错了(已改),但是也过了,这题改的还纠结。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int N, seq[100], mode, use[100], flag;void dfs(int cap, int last, int num){ if (num == N) { flag = 1; return; } if 阅读全文
posted @ 2012-07-25 02:47 沐阳 阅读(321) 评论(0) 推荐(0) 编辑
摘要: 该题问给定的棍子能否组成一个正方形。首先我们要判定是否总长度是4的倍数,然后再决定是否存在某条边大于组合边长。搜索的过程中也是可以进行剪枝了。首先将边排序,我们可以假定所有的组合边由大小递减的边组成,那么我们在搜索的时候就不用再往前找边了。其次我们可以确定任何一条边都一定在一条组合边中,那么当我们以任意一条边开搜的情况下无解的话,那么我们就可以直接返回no了。最后在搜索某条边无解的情况下,我们可以把相同大小的边略过,因为前面相同长度的边都无法安排出一种方案,在少一条相同边情况下肯定也就无法给出安排了。代码如下:#include <cstdlib>#include <cstdi 阅读全文
posted @ 2012-07-25 01:02 沐阳 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 该题题义是有一个显示器,在给定了一系列的操作后,询问最后显示器所显示的区域。对于每个操作,给定一个x坐标和一个y坐标,以及三角形(等腰直角三角形)的边长。对于每个面积覆盖次数为奇数的区域是显示的,对于覆盖了0次或偶数次的区域是不显示的。那么我们可以将题目这样进行转化,我们规定了个三角形的区域,它的横纵坐标分别是x, y,边长为 r 那么这个三角形可以用一个方程组来表示,令 ci = xi + yi + r, x + y <= ci; x >= xi; y >= yi;这个图形画出来就是一个三角形区域,对于后面进来的三角形,我们同样可以写出这样一个方程,我们需要解出这两个方程组 阅读全文
posted @ 2012-07-24 21:19 沐阳 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 这个题在于唯一确定好色子的状态,其实只要知道了色子的前上右分别的点数,也就唯一确定了色子的状态,我们可以根据这三个状态来恢复整个色子的六个面的情况。这题还要注意对4进行取模(由于本身已经占了一个格子,因此要减1),直接模拟的话很有可能超时,利用switch的贯穿性质可以让我们的代码过程更加舒适。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int N, M, ti;long long int sum 阅读全文
posted @ 2012-07-24 00:45 沐阳 阅读(412) 评论(0) 推荐(0) 编辑
摘要: 这题竟然用java也可以过,因该算是最简单的吧了。当然另外的两重for循环的写法也算是很简单的了。这里就直接写素因子分解的写法。对于A中的数,我们可以将每个数都进行素因子分解,最后保留各个质数的指数,对B进行同样操作,然后在去两者指数的min值就可以了。这里要对大质数进行特殊处理。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>#include <map>#define MOD 1000000000using namespace 阅读全文
posted @ 2012-07-24 00:39 沐阳 阅读(404) 评论(0) 推荐(0) 编辑
摘要: 算出每个窗户左上角和右下角的坐标,直接模拟就行了。这题直接把sum放在G数组后面,导致sum变成了char型,错了一次,G数组第一次只开了105~~~。代码如下:#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;char G[600][600];int sum[10];int main(){ int N, M, x1, y1, x2, y2, cnt; while (scanf("%d %d", &N, &M) == 2) { 阅读全文
posted @ 2012-07-24 00:34 沐阳 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 这题直接二分就可以了,注意下二分的返回值,以后都最好手动模拟一下。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long int Int64;Int64 N, M, seq[1000005];Int64 sum(Int64 h){ Int64 ret = 0; for (int i = 1; i <= N; ++i) { if (seq[i] > h) { re 阅读全文
posted @ 2012-07-24 00:31 沐阳 阅读(258) 评论(0) 推荐(0) 编辑
摘要: 这题用也算是贪心吧,不过这里有一点数学思想。对于要取掉K位的N位数,那么我们留下来的就是N-K位,我们不妨设 T = N - K; 那么我们选择的第一位数的后面就一定要有T-1个数让我们来选,因此第一个数的选择范围就是[1, N-T+1],当我们选取了第一个数后(假设位置为P),我们第二个数的选择范围就是 [P+1, N-T-2]了,一次类推。由于我们要取的是最大的数,所以我们每次都选取区间内的最大值,用线段树来作优化就可以了。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#include 阅读全文
posted @ 2012-07-24 00:29 沐阳 阅读(275) 评论(0) 推荐(0) 编辑
上一页 1 ··· 33 34 35 36 37 38 39 40 41 ··· 66 下一页