上一页 1 ··· 148 149 150 151 152 153 154 155 156 ··· 182 下一页
摘要: 题意:给出n,求欧拉函数,欧拉函数euler(n)表示小于等于n的与n互质的数的个数,在欧拉函数,认为如果两数最大公约数为1,则两数互质。所以,n与1也互质,且euler(1)=1。分析:计算公式为:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有不重复的质因数,x是不为0的整数。View Code #include #include #include #include #include usingnamespace std;unsigned euler(unsigned x){// 就是公式 unsi... 阅读全文
posted @ 2011-05-20 16:28 undefined2024 阅读(536) 评论(0) 推荐(0)
摘要: 学会了使用map,首先#include <map>,然后声明map<A,B>,map可以当B类型数组用,下标为A类型。成员函数find()可以查找数组中元素,如果没找到返回值为成员函数.end()的值。找到了返回下标。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <map>using namespace std;#define maxm 1005int m, n;string 阅读全文
posted @ 2011-05-20 16:04 undefined2024 阅读(204) 评论(0) 推荐(0)
摘要: 与poj2593相同View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 100003int f[maxn], fleft[maxn], fright[maxn];int n;void input(){ for (int i = 0; i < n; i++) scanf("%d", &f[i]);}void work1(){ fleft[0 阅读全文
posted @ 2011-05-20 14:59 undefined2024 阅读(308) 评论(0) 推荐(0)
摘要: dp,分别从左侧和右侧求最大子段和,然后把fleft[i]变成0~i区间中最大子段和,fright以此类推。然后枚举中间分割点。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 100003int f[maxn], fleft[maxn], fright[maxn];int n;void input(){ for (int i = 0; i < n; i++) s 阅读全文
posted @ 2011-05-20 14:54 undefined2024 阅读(271) 评论(0) 推荐(0)
摘要: 暴力做就可以过。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 10000005int ans[maxn];int main(){// freopen("t.txt", "r", stdin); int p1, p2; ans[0] = 1; p1 = 0; p2 = 0; for (int i = 1; i <= 100 阅读全文
posted @ 2011-05-20 14:06 undefined2024 阅读(174) 评论(0) 推荐(0)
上一页 1 ··· 148 149 150 151 152 153 154 155 156 ··· 182 下一页