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. 57. Insert Interval

    题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if nec ...

  2. API设计

    ---恢复内容开始--- 参考:http://www.cnblogs.com/youxin/p/3967274.html http://scotch.io/tutorials/simple-larav ...

  3. 盘点PHP编程常见失误

    概述:本文盘点PHP开发者在编码时,容易忽略或不注意引起的小失误与错误. 变量声明 如果在一条语句中声明一个变量,如下所示:$var='value';编译器首先会求出语句右半部分的值,恰恰正是语句的这 ...

  4. java--面向抽象编程

    所谓面向抽象编程是指当设计某种重要的类时,不让该类面向具体的类,而是面向抽象类,及所设计类中的重要数据是抽象类声明的对象,而不是具体类声明的对象.就是利用abstract来设计实现用户需求. 比如:我 ...

  5. Android权限安全(5)组件的android:exported属性

    Android四大组件都有 android:exported 属性 android:exported="true" 时 表示该组件是公开的,其它组件可以访问这个组件 android ...

  6. C# 写入XML文档三种方法详细介绍

      三个类将同样的xml内容写入文档,介绍了如何使用XmlDocument类对XML进行操作,以及如何使用LINQ to XML对XML进行操作. 它们分别使用了XmlDocument类和XDocum ...

  7. Jquery的.post说解

    Jquery的.post说解(一) 准备工作 ·Customer类   public class Customer {     public int Unid { get; set; }     pu ...

  8. Setup Oracle 11gR2 for Redhat Linux AS 4 Update 7 x64

    Setup Oracle 11gR2 for Redhat Linux AS 4 Update 7 x64 1. checking linux version. [root@localhost ~]# ...

  9. trackr: An AngularJS app with a Java 8 backend – Part I

    该系列文章来自techdev 我想分享在techdev公司开发的项目-trackr-的一些最新的见解.trackr是一个用来跟踪我们的工作时间,创建报告和管理请假的web应用程序.做这个程序的目的有两 ...

  10. 函数lock_rec_get_first

    /*********************************************************************//** Gets the first explicit l ...