上一页 1 ··· 35 36 37 38 39 40 41 42 43 ··· 66 下一页
摘要: 这题有个技巧就是保留前缀和后缀级,然后利用公式 a*b MOD c = ( a MOD c * b MOD c ) MOD c。代码如下:#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define MOD 1000000007using namespace std;int N;long long a[100005], l[100005], r[100005];int main(){ while (sca 阅读全文
posted @ 2012-07-16 22:38 沐阳 阅读(291) 评论(0) 推荐(0) 编辑
摘要: 先生成蛇型矩阵,然后再筛选出素数进行标记,最后bfs。这里要注意题目要求的1-10000的之间的数路径,但是并不代表我们只要打印到这个范围的素数,因为很可能边沿的点需要走到外面的图形来完成对短路,外围的也不要打印太多,毕竟素数的个数越到外面是越稀疏的,所以打印到40000足矣。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>#include <map>#define MAXN 40000using namespace std;i 阅读全文
posted @ 2012-07-16 22:20 沐阳 阅读(382) 评论(0) 推荐(0) 编辑
摘要: 首先将7种方块拆成19种方块,然后在进行dfs组合,当然如果给定的N*M不是4的倍数的时候记得直接输出0。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int N, M, ans, END, G[35][35], many[20];int mp[20] = {1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7};char ss[50][6][6] = { { "####" 阅读全文
posted @ 2012-07-16 22:09 沐阳 阅读(5056) 评论(0) 推荐(0) 编辑
摘要: 该题题意就是求一个数最多能够开多少次方,这其中包含有负数,而且要用long long 型数据读入。首先将这个数的素因子分解求出,统计出它们的各自的个数,然后对它们的个数求一个gcd,最后输出。如果是正数的话直接输出,如果是负数的话需要将其的最大奇因子求出。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;int p[66000], cnt;long long 阅读全文
posted @ 2012-07-14 22:04 沐阳 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 问你一个数在一个连续区间,这个区间全为和数的长度。代码如下:#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#define MAXN 1300000using namespace std;int p[MAXN+5], rec[100005], N;void pre(){ int k; for (int i = 4; i <= MAXN; i += 2) { p[i] = 1; } for (int i = 3; i <= 1141; i 阅读全文
posted @ 2012-07-14 01:13 沐阳 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 代码如下:#include <cstdlib>#include <cstring>#include <cmath>#include <cstdio>using namespace std;int p[40010], a[10000], b[10000];void pre(){ for (int i = 4; i <= 40010; i += 2) { p[i] = 1; } for (int i = 3; i <= 200; i += 2) { if (!p[i]) { int k = 2 * i; fo... 阅读全文
posted @ 2012-07-14 00:33 沐阳 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 筛出素数然后直接暴力即可。代码如下:#include <cstdlib>#include <cstring>#include <cstdio>#define MAXN 10000using namespace std;int N, M, d, p[600005];int hash[10005], path[10005];void pre(){ int k; for (int i = 4; i <= MAXN; i += 2) { p[i] = 1; } for (int i = 3; i <= 105; i += 2) { if (!... 阅读全文
posted @ 2012-07-14 00:20 沐阳 阅读(418) 评论(0) 推荐(0) 编辑
摘要: 跟杭电的奇怪的楼梯非常想。代码如下:#include <cstdio>#include <queue>using namespace std;struct Node{ int x, t;}e[100005], pos;int N, K, front, tail, hash[100005];void getnewpos(int x, int a[]){ a[0] = x - 1; a[1] = x + 1; a[2] = x << 1; }int bfs(){ memset(hash, 0, sizeof (hash)); hash[N] = 1; ... 阅读全文
posted @ 2012-07-13 16:11 沐阳 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 就是将普通的二维推广到三维,方向变成了六个。代码如下:#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;int L, N, M, sx, sy, sz; struct Node{ int x, y, z, t; }e[100005], pos;int front, tail, dir[6][3] ={ 0, 1, 0, 0, -1, 0, 1, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, -1}; // 六个方向,三个坐标 cha... 阅读全文
posted @ 2012-07-13 15:56 沐阳 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 非常简单的一道搜索题,用状态压缩加DP写了一上午,写道后面越来越感觉这题状态压缩没有什么优势,每一行都与前面的行的排列有关系,因此不能够记忆化,没算完一次要把状态清空,可惜到最后还是错了。干脆直接暴力搜索。就这样过了。代码如下:#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>using namespace std;int N, K, hash_x[10], hash_y[10], ans;char G[10][10];void dfs(int x, 阅读全文
posted @ 2012-07-13 15:30 沐阳 阅读(255) 评论(0) 推荐(0) 编辑
上一页 1 ··· 35 36 37 38 39 40 41 42 43 ··· 66 下一页