上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 182 下一页
摘要: 简单题View Code #include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;#define maxn 105int n;int f[maxn];int main(){ //freopen("t.txt", "r", stdin); scanf("%d", &am 阅读全文
posted @ 2013-03-17 20:04 undefined2024 阅读(407) 评论(0) 推荐(0)
摘要: 广搜View Code #include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;#define maxn 10000000int n;long long q[maxn];long long work(){ int front = 0; int rear = 0; q[rear++] = 1; while (1) { long long temp = q[front++]; if ((temp * 10) % n... 阅读全文
posted @ 2013-03-17 19:46 undefined2024 阅读(599) 评论(0) 推荐(0)
摘要: 题意:给出n,求n!的位数。分析:首先想到的是用log10(n!)=log10(1)+log10(2)+...+log10(n)。但是由于log10运行时间较长,会超时,所以可以先将log10(1)~log10(maxn)存入数组,则省去了多次调用的时间浪费。但是有一种更好的做法就是利用stirling公式。stirling公式:lim(n→∞) (n/e)^n*√(2πn) / n! = 1虽然本题中的n并不是正无穷,但是求出的n!的位数还是不会出现误差的。所以我们直接以此公式整理出log10(n!)=log10(sqrt(2 * acos(-1) * n)) + n * log10(n / 阅读全文
posted @ 2013-03-17 19:09 undefined2024 阅读(719) 评论(0) 推荐(0)
摘要: 模拟,注意1号第一次投出球后其thinking方向不改变。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 35int n, m;int d[maxn];int dir[2] = {-1, 1};bool vis[maxn];void input(){ char st[5]; scanf("%d", &m); m--; for (int i 阅读全文
posted @ 2013-03-17 18:36 undefined2024 阅读(382) 评论(0) 推荐(0)
摘要: 题意:两个数列,第一行的数字可以和第二行的数字连线。连线有如下条件,被连上的两数字必须相等,且每个数字只能连一条线,每条连线必须与且仅与另一条连线相交,相交两连线上的数字不能相等。问最多能连多少条线。分析:dp。f[i][j]表示第一行的前i个数字和第二行的前j个数字最多能连几条线,则f[i][j]=max(f[i-1][j],f[i][j-1],f[k-1][l-1]+2)。k是第一行前i-1个数字中最右一个能与第二行j位置连线的数的位置。l同理。这样状态转移为n,状态为n^2,总的时间复杂度为n^3。但是我们可以不用每次顺序查找k,l的值,我们进行预处理。数组last_equal1[i][ 阅读全文
posted @ 2013-03-15 14:48 undefined2024 阅读(434) 评论(0) 推荐(0)
上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 182 下一页