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. openCv 图像顺时针、逆时针旋转

    通过下面这个函数调用 Rotate90(workImg,270); //顺时针旋转 Rotate90(workImg,90); //逆时针旋转 实现,其实用该函数旋转任意度数对正方形图都ok,只是长方 ...

  2. org.json.JSONObject与com.google.gson.Gson

    org.json库为JSON创始人编写的解析JSON的java库,Gson为Google为我们提供的解析JSON格式数据的库. Gson里最重要的对象有2个Gson 和GsonBuilder. Gso ...

  3. int string相互转换

    一.itoa()和atoi() 注意:这两个函数并不是标准的C函数,而是windows环境下特有的函数. 1.itoa #include<iostream> #include<str ...

  4. 面试题_17_to_30_数据类型和 Java 基础面试问题

    17)Java 中应该使用什么数据类型来代表价格?(答案)如果不是特别关心内存和性能的话,使用BigDecimal,否则使用预定义精度的 double 类型. 18)怎么将 byte 转换为 Stri ...

  5. UVa 10253 (组合数 递推) Series-Parallel Networks

    <训练之南>上的例题难度真心不小,勉强能看懂解析,其思路实在是意想不到. 题目虽然说得千奇百怪,但最终还是要转化成我们熟悉的东西. 经过书上的神分析,最终将所求变为: 共n个叶子,每个非叶 ...

  6. 基于RTP的H264视频数据打包解包类

    from:http://blog.csdn.net/dengzikun/article/details/5807694 最近考虑使用RTP替换原有的高清视频传输协议,遂上网查找有关H264视频RTP打 ...

  7. crtmpserver流媒体服务器的介绍与搭建

    crtmpserver流媒体服务器的介绍与搭建 (2012-02-29 11:28) 标签:  crtmpserver  C++ RTMP Server  rtmp  Adobe FMS(Flash ...

  8. 利用c#反射实现实体类生成以及数据获取与赋值

    转:http://hi.baidu.com/xyd21c/item/391da2fc8fb351c10dd1c8b8 原有的实体类成员逐个赋值与获取的方法弊端: 1.每次对实体类属性进行赋值时,都要检 ...

  9. MySQL 5.6 复制:GTID 的优点和限制(第一部分)

    全局事务标示符(Global Transactions Identifier)是MySQL 5.6复制的一个新特性.它为维护特定的复制拓扑结构下服务器的DBA们大幅度改善他们的工作状况提供了多种可能性 ...

  10. win7和centos双系统安装

    几年之前为了安装xp和linux的双系统曾折腾了好多天,今天为了安装这个win7和centos双系统,也折腾了两天多,哦,我的天,安装个双系统,怎么这么麻烦呢? 没有来得及整理,先铺上草稿,供同志们参 ...