上一页 1 ··· 139 140 141 142 143 144 145 146 147 ··· 182 下一页
摘要: 快排,然后从左至右找到第c个在区间内的数。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 100005struct Elem{ int p, v;}f[maxn];bool operator < (const Elem &a, const Elem &b){ return a.v < b. 阅读全文
posted @ 2011-05-29 22:15 undefined2024 阅读(201) 评论(0) 推荐(0)
摘要: 树状数组View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 500005struct Elem{ int p, v;}s[maxn];int f[maxn];int pos[maxn];int ar[maxn];bool operator < (const Elem &a, const Elem & 阅读全文
posted @ 2011-05-29 22:04 undefined2024 阅读(329) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 1006int f[maxn];int main(){ //freopen("t.txt", "r", stdin); int t; scanf("%d", &t); while (t--) { 阅读全文
posted @ 2011-05-29 21:38 undefined2024 阅读(172) 评论(0) 推荐(0)
摘要: 题意:田忌赛马,两人各n匹马,每匹马有个速度,快的能胜慢的,赢一场赚200,输一场输200,平一场不赚钱。每次大王先出马,然后田忌再出马应对。问田忌最多赢赚多少钱。分析:可以用贪心,但是这里说一下dp的做法。dp,O(n^2)f[i][j]表示用他的前i匹马与对方的前j匹马,赢的得200,平的不得,其余一律输200,最多能多少钱。if (h1[i] > h2[j])f[i][j] = max(f[i - 1][j - 1] + 200,f[i - 1][j] - 200, f[i][j - 1] - 200);else if (h1[i] == h2[j])f[i][j] = max(f 阅读全文
posted @ 2011-05-29 20:38 undefined2024 阅读(471) 评论(0) 推荐(0)
摘要: 简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define N 1000005bool is[N];int prm[N];int getprm(int n){ int i, j, k = 0; int s, e = (int )(sqrt(0.0+n) +1); memset(is, 1, sizeof(is)); prm[k++] = 2 阅读全文
posted @ 2011-05-29 19:27 undefined2024 阅读(154) 评论(0) 推荐(0)
上一页 1 ··· 139 140 141 142 143 144 145 146 147 ··· 182 下一页