A

  第一题明显统计,注意0和long long(我WA,RE好几次)

/*
* Problem: A. Matrix
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; int a, n, b[4444], c[44444];
char s[4444]; int main(/*int argc, char **argv*/) {
int i, j, x;
long long ans; scanf("%d", &a);
scanf(" %s", s + 1);
n = strlen(s + 1);
for (i = 1; i <= n; ++i)
b[i] = s[i] - '0';
memset(c, 0, sizeof c);
ans = 0;
for (i = 1; i <= n; ++i) {
x = 0;
for (j = i; j <= n; ++j) {
x += b[j];
++c[x];
}
}
if (a) {
for (i = 1; i <= 40000 && i * i <= a; ++i)
if (a % i == 0 && a / i <= 40000)
ans += static_cast<long long>(c[i]) * c[a / i] * (i * i == a ? 1 : 2);
} else
ans = static_cast<long long>(c[0]) * (n * (n + 1) - c[0]);
printf("%I64d", ans); fclose(stdin);
fclose(stdout);
return 0;
}

B

  用背包算出每个价值是否出现过,然后贪心即可。

/*
* Problem: B. Free Market
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; int n, d, c[55], f[500010]; int main(/*int argc, char **argv*/) {
int i, j, sum, ans1, ans2; scanf("%d%d", &n, &d);
sum = 0;
for (i = 1; i <= n; ++i) {
scanf("%d", c + i);
sum += c[i];
}
memset(f, 0, sizeof f);
f[0] = 1;
for (i = 1; i <= n; ++i)
for (j = sum; j >= c[i]; --j)
f[j] |= f[j - c[i]];
ans1 = 0;
ans2 = 0;
while (ans1 < sum) {
for (j = ans1 + d <= sum ? ans1 + d : sum; j > ans1; --j)
if (f[j])
break;
if (j <= ans1)
break;
ans1 = j;
++ans2;
}
printf("%d %d", ans1, ans2); fclose(stdin);
fclose(stdout);
return 0;
}

C

  不懂证明,求解释。。。

D

  做法是随机算法(没有想到啊。)

/*
* Problem: D. Ghd
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 1000010; int n;
long long a[MAXN], ans;
std::vector<long long> e, v; long long gcd(long long a, long long b) {
return !b ? a : gcd(b, a % b);
} int main(/*int argc, char **argv*/) {
int i, j, x; // freopen("D.in", "r", stdin);
// freopen("D.out", "w", stdout); scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%I64d", a + i);
srand((unsigned)time(0));
ans = 0;
while (clock() < 3000L) {
x = static_cast<long long>(rand()) * rand() % n + 1;
e.clear();
v.clear();
for (i = 1; static_cast<long long>(i) * i <= a[x]; ++i)
if (a[x] % i == 0) {
e.push_back(i);
if (static_cast<long long>(i) * i != a[x])
e.push_back(a[x] / i);
}
std::sort(e.begin(), e.end());
v.resize(e.size(), 0);
for (i = 1; i <= n; ++i)
++v[std::lower_bound(e.begin(), e.end(), gcd(a[x], a[i])) - e.begin()];
for (i = 0; i < static_cast<int>(e.size()); ++i) {
for (j = i + 1; j < static_cast<int>(e.size()); ++j)
if (e[j] % e[i] == 0)
v[i] += v[j];
if (v[i] + v[i] >= n)
ans = std::max(ans, e[i]);
}
}
printf("%I64d", ans); fclose(stdin);
fclose(stdout);
return 0;
}

E

  二维分治。

/*
* Problem: E. Empty Rectangles
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; int n, m, k;
char s[2505][2505];
long long a[2505][2505]; inline long long sum(int r1, int c1, int r2, int c2) {
return a[r2][c2] - a[r1 - 1][c2] - a[r2][c1 - 1] + a[r1 - 1][c1 - 1];
} long long go(int r1, int c1, int r2, int c2) {
if (r1 == r2 && c1 == c2)
return sum(r1, c1, r2, c2) == k;
if (r2 - r1 > c2 - c1) {
long long cnt = 0;
int m = (r1 + r2) >> 1;
int up[k + 1], dw[k + 1];
for (int i = c1; i <= c2; i++) {
for (int x = 0; x <= k; x++)up[x] = m - r1 + 1, dw[x] = r2 - m;
for (int j = i; j <= c2; j++) {
for (int x = 0; x <= k; x++) {
while (up[x] && sum(m - up[x] + 1, i, m, j) > x)
--up[x];
while (dw[x] && sum(m + 1, i, m + dw[x], j) > x)
--dw[x];
}
for (int x = 0; x <= k; x++) {
cnt += (long long)(up[x] - (x ? up[x - 1] : 0)) * (dw[k - x] - (k - x ? dw[k - x - 1] : 0));
}
}
}
return cnt + go(r1, c1, m, c2) + go(m + 1, c1, r2, c2);
} else {
long long cnt = 0;
int m = (c1 + c2) >> 1;
int up[k + 1], dw[k + 1];
for (int i = r1; i <= r2; i++) {
for (int x = 0; x <= k; x++)up[x] = m - c1 + 1, dw[x] = c2 - m;
for (int j = i; j <= r2; j++) {
for (int x = 0; x <= k; x++) {
while (up[x] && sum(i, m - up[x] + 1, j, m) > x)up[x]--;
while (dw[x] && sum(i, m + 1, j, m + dw[x]) > x)dw[x]--;
}
for (int x = 0; x <= k; x++) {
cnt += (long long)(up[x] - (x ? up[x - 1] : 0)) * (dw[k - x] - (k - x ? dw[k - x - 1] : 0));
}
}
}
return cnt + go(r1, c1, r2, m) + go(r1, m + 1, r2, c2);
}
} int main() {
freopen("E.in", "r", stdin);
freopen("E.out", "w", stdout); scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++)scanf("%s", &s[i][1]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + s[i][j] - '0';
}
}
printf("%I64d", go(1, 1, n, m)); fclose(stdin);
fclose(stdout);
return 0;
}

Codeforces 364的更多相关文章

  1. Codeforces #364 (Div. 2) D. As Fa(数学公式推导 或者二分)

    数学推导的博客 http://codeforces.com/contest/701/problem/D  题目 推导的思路就是 : 让每个人乘车的时间相等 ,让每个人走路的时间相等. 在图上可以这么表 ...

  2. Codeforces #364 DIV2

      ~A题 A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. Codeforces Round #364 (Div. 2)

    这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...

  4. Codeforces Round #364

    http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...

  5. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

  6. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  7. 树形dp Codeforces Round #364 (Div. 1)B

    http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...

  8. Codeforces Round #364 As Fast As Possible

    二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行. 使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力. #include<cstdio> #includ ...

  9. Codeforces Round #364 (Div. 2) B. Cells Not Under Attack

    B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...

随机推荐

  1. Java String.compareTo()方法

    描述:java.lang.String.compareTo() 方法比较两个字符串的字典. 比较是基于字符串中的每个字符的Unicode值.此String对象表示的字符序列的 参数字符串表示的字符序列 ...

  2. AjaxUpLoad.js使用实现文件上传

    AjaxUpLoad.js的使用实现无刷新文件上传,如图. 图1 文件上传前 图2 文件上传后 1.创建页面并编写HTML [html] view plaincopy   上传文档: <div  ...

  3. Hibernate的一个注释 @Transient

    @Transient表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性. 如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,否则,ORM框架默认其注解为@Basi ...

  4. Event-based Asynchronous Pattern Overview基于事件的异步模式概览

    https://msdn.microsoft.com/zh-cn/library/wewwczdw(v=vs.110).aspx Applications that perform many task ...

  5. uva11181Probability|Given

    枚举,条件概率. 2^20次方等于100w,是大约可以没准还能过的. 二进制枚举时,如果买东西的人恰好为r个,设概率为p,就将sum[i]+=p(sum[i]为r个人买东西时第i个人买东西的概率),t ...

  6. Qt之自定义界面(窗体缩放)

    简述 通过前两节内容,我们实现了自定义窗体的移动,以及自定义标题栏-用来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭. 在这之后,我们还缺少窗体的缩放-当鼠标移动到窗体的边框-左.上.右.下 ...

  7. UVa 11181 (条件概率) Probability|Given

    题意: 有n个人买东西,第i个人买东西的概率为Pi.已知最终有r个人买了东西,求每个人买东西的概率. 分析: 设事件E为r个人买了东西,事件Ei为第i个人买了东西.所求为P(Ei|E) = P(EiE ...

  8. UVa 10674 (求两圆公切线) Tangents

    题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...

  9. bzoj1877: [SDOI2009]晨跑

    挺裸的最小费用最大流... #include<cstdio> #include<queue> #include<cstring> #include<iostr ...

  10. Only one instance of a ScriptManager can be added to the page.

    一般出现在一个页面用了多个用户控件,而每个用户控件中都用到了ScriptManager,最好的办法是控件中不要加上         <asp:ScriptManager ID="Scr ...