Codeforces 364
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的更多相关文章
- Codeforces #364 (Div. 2) D. As Fa(数学公式推导 或者二分)
数学推导的博客 http://codeforces.com/contest/701/problem/D 题目 推导的思路就是 : 让每个人乘车的时间相等 ,让每个人走路的时间相等. 在图上可以这么表 ...
- Codeforces #364 DIV2
~A题 A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #364 (Div. 2)
这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...
- Codeforces Round #364
http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...
- Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- 树形dp Codeforces Round #364 (Div. 1)B
http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...
- Codeforces Round #364 As Fast As Possible
二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行. 使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力. #include<cstdio> #includ ...
- 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 ...
随机推荐
- P25、面试题1:赋值运算符函数
题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString { public: CMyString(char* pData = NULL); CMyStr ...
- 对Memcached使用的总结和使用场景
1.memcached是什么 Memcached 常被用来加速应用程序的处理,在这里,我们将着重于介绍将它部署于应用程序和环境中的最佳实践.这包括应该存储或不应存储哪些.如何处理数据的灵活分布以 及如 ...
- <<c 和指针 >> 部分笔记。
最近竟然对指针有些迷惑了,分不清指针的指向.废话少说,复习.(下面内容来自<<c和指针>>) =指针 ==内存和地址 尽管一个字包含了4个字节,它仍然只有一个地址.至于是最左边 ...
- Java中常见几种数据库连接方法
1:引入java.sql数据包; import java.sql.*; 2:加载JDBC驱动程序 Class.forName(JDBC驱动包的名字).newInstance(); 3:产生Co ...
- 面试题_89_to_92_单元测试 JUnit 面试题
89)如何测试静态方法?(答案)可以使用 PowerMock 库来测试静态方法. 90)怎么利用 JUnit 来测试一个方法的异常?(答案) 91)你使用过哪个单元测试库来测试你的 Java 程序?( ...
- bzoj2395
分组赛时学到的最小乘积生成树模型,感觉这个思路非常神,可以说是数形结合的经典问题 由于生成树有两个权值,我们把每个生成树的权值表示成点坐标(sa,sb) 显然我们知道,乘积最小,那么点必然落在下凸壳上 ...
- MySQL Timeout解析
“And God said, Let there be network: and there was timeout”在使用MySQL的过程中,你是否遇到了众多让人百思不得其解的Timeout?那么这 ...
- UVa 11762 (期望 DP) Race to 1
设f(x)表示x转移到1需要的次数的期望,p(x)为不超过x的素数的个数,其中能整除x的有g(x)个 则有(1-g(x)/p(x))的概率下一步还是转移到x,剩下的情况各有1/p(x)的概率转移到x/ ...
- Codeforces Round #273 (Div. 2)
A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...
- Facebook存储技术方案:找出“暖性BLOB”数据
Facebook公司已经在其近线存储体系当中彻底弃用RAID与复制机制,转而采用分布式擦除编码以隔离其所谓的“暖性BLOB”. 暖性?BLOB?这都是些什么东西?大家别急,马上为您讲解: BLOB—— ...