Codeforces 524 解题报告
打的很快乐的一次比赛hiahiahia, 才A掉4题rating就涨了100+
距离比赛\(3\)天了, 由于博主实在太颓, 又补掉了\(E\)题, 到现在才发解题报告
A.
语法题, 读入输出就行了
#include<cstdio>
#include<algorithm>
#include<iostream>
#define rd read()
#define ll long long
using namespace std;
int read() {
int X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c <= '9' && c >= '0'; c = getchar())
X = X * 10 + c - '0';
return X * p;
}
int main()
{
int n = rd, k = rd;
ll a = 2 * n, b = 5 * n, c = 8 * n, ans = 0;
ans = (a + k - 1) / k + (b + k - 1) / k + (c + k - 1) / k;
cout << ans << endl;
}
B.
把相邻两项放在一起, 多出的\(1\)项另外加上去
#include<cstdio>
#include<algorithm>
#define rd read()
using namespace std;
int read() {
int X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c <= '9' && c >= '0'; c = getchar())
X = X * 10 + c - '0';
return X * p;
}
int main()
{
int n = rd;
for (; n; --n) {
int l = rd, r = rd, ans = 0;
if ((r - l + 1) % 2 == 0) printf("%d\n", (l & 1 ? 1 : -1) * (r - l + 1) / 2);
else {
ans = (l & 1 ? 1 : -1) * (r - l) / 2;
ans += (r & 1 ? -1 : 1) * r;
printf("%d\n", ans);
}
}
}
C.
简单的容斥
白色和黑色是交替出现的
一个\(w \times h\) 的矩阵, 如果 \(w \times h\) 为奇数, 则左下角的颜色会比另外一种颜色多出\(1\)个
接下来是计算方法, 算出的 黑色 或 白色 的个数表示 泼墨水之前的矩阵
泼白墨水时, 算出 \((x1, y1), (x2, y2)\) 这个矩阵内有多少个黑色方块, 并更新入答案
泼黑墨水时, 算出 \((x3, y3), (x4, y4)\) 这个矩阵内有多少个白色方块, 并更新入答案
这时我们发现两次泼墨水的范围会有交集, 这个相交的矩阵为 \((x5, y5), (x6, y6)\)
这个相交的矩阵内 第二次泼墨只记入了 白色方块的贡献, 而没有记入黑色方块的贡献(黑色方块在第一次泼墨时被染成了白色)
所以只需要把 这个矩阵内的 黑色方块的个数 加入黑色方块的总数即可
枚举横纵坐标就可以找到相交矩阵
下代码计算矩阵内某种颜色的方块数用一个函数可以解决, 我打麻烦了QAQ
#include<cstdio>
#include<algorithm>
#include<iostream>
#define rd read()
#define ll long long
using namespace std;
typedef pair<ll, ll> P;
ll n, m, numw, numb;
ll lsx[10], lsy[10], cntx, cnty;
const ll inf = 1e9 + 7;
ll read() {
ll X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c <= '9' && c >= '0'; c = getchar())
X = X * 10 + c - '0';
return X * p;
}
#define X first
#define Y second
void in(P &tmp) {
tmp.X = rd; tmp.Y = rd;
lsx[++cntx] = tmp.X;
lsy[++cnty] = tmp.Y;
}
int jud(ll x, ll y, P tmp1, P tmp2, P tmp3, P tmp4) {
if (x < tmp1.X || x > tmp2.X) return 0;
if (x < tmp3.X || x > tmp4.X) return 0;
if (y < tmp1.Y || y > tmp2.Y) return 0;
if (y < tmp3.Y || y > tmp4.Y) return 0;
return 1;
}
void up(P &a, P b) {
if (a < b) a = b;
}
void down(P &a, P b) {
if (a > b) a = b;
}
void cal() {
P tmp1, tmp2, tmp3, tmp4;
in(tmp1); in(tmp2); in(tmp3); in(tmp4);
ll dx = tmp2.X - tmp1.X + 1, dy = tmp2.Y - tmp1.Y + 1;
if ((dx * dy) % 2 && (tmp1.X + tmp1.Y) % 2) {
numb -= dx * dy - dx * dy / 2;
numw += dx * dy - dx * dy / 2;
} else numb -= dx * dy / 2,
numw += dx * dy / 2;
dx = tmp4.X - tmp3.X + 1, dy = tmp4.Y - tmp3.Y + 1;
if ((dx * dy) % 2 && (tmp3.X + tmp3.Y) % 2 == 0) {
numw -= dx * dy - dx * dy / 2;
numb += dx * dy - dx * dy / 2;
} else numw -= dx * dy / 2,
numb += dx * dy / 2;
P tmp5 = P(inf, inf), tmp6 = P(0, 0);
for (int i = 1; i <= 4; ++i)
for (int j = 1; j <= 4; ++j) if (jud(lsx[i], lsy[j], tmp1, tmp2, tmp3, tmp4)) {
down(tmp5, P(lsx[i], lsy[j])),
up(tmp6, P(lsx[i], lsy[j]));
}
if (tmp6.X == 0) return;
dx = tmp6.X - tmp5.X + 1, dy = tmp6.Y - tmp5.Y + 1;
if ((dx * dy) % 2 && (tmp5.X + tmp5.Y) % 2) {
numw -= dx * dy - dx * dy / 2;
numb += dx * dy - dx * dy / 2;
} else numw -= dx * dy / 2,
numb += dx * dy / 2;
}
#undef x
#undef y
int main()
{
int T = rd;
for (; T; T--) {
cntx = cnty = 0;
n = rd; m = rd;// y <= n && x <= m (x, y)
numb = n * m / 2;
numw = n * m - numb;
cal();
cout << numw << " " << numb <<endl;
}
}
D.
枚举+数列计算?
\(a_n=(4^n-1) \div 3\) 表示边长为 \(2^n\) 的矩阵分裂成 \(1 \times 1\) 的矩阵需要的操作数。 高中的数列知识应该算的很快
然后枚举 路径上的矩阵的边长为 \(2^{n-a} \ (a=1...n)\) , 至少要 \(2^a - 1\) 次操作才能造出存在这样的路径,
则左边界\(L=2^a-1\), 然后我们需要算出右边界\(R\),并判断\(k\) 是否在 \([L, R]\) 内。
把除掉这条路径上的 所有矩阵都分裂成 \(1 \times 1\) 的矩阵 就能算出 \(R\)
另外 \(R\) 的值会爆\(LL\), 所以我用了 \(long \ double\) QuQ
#include<cstdio>
#include<algorithm>
#include<iostream>
#define ll long long
#define rd read()
#define lb long double
using namespace std;
const ll inf = 1e9 + 7;
ll n, k;
ll read() {
ll X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c >= '0' && c <= '9'; c = getchar())
X = X * 10 + c - '0';
return X * p;
}
lb fpow(lb a, ll b) {
lb res = 1;
for (; b; b >>= 1, a = a * a)
if (b & 1) res = res * a;
return res;
}
int cal() {
lb tmp1 = 0, tmp2 = 0, fac = 2;
for (int i = 1; i <= n && i <= 50; ++i) {
tmp1 += fac - 1;
tmp2 += (2 * (fac - 1) - 1) * (fpow(4, n - i) - 1) / 3;
if (tmp1 <= k && k <= tmp1 + tmp2) return n - i;
if (tmp1 > k) return inf;
fac *= 2;
}
return inf;
}
int main()
{
int T = rd;
for (; T; T--) {
n = rd; k = rd;
int res = cal();
if (res == inf) puts("NO");
else printf("YES %d\n", res);
}
}
E.
manacher算法
一个矩阵满足条件, 必须使
- 在每一行中, 出现次数为奇数的字符数 \(<=1\)
- 对应两行每种字符的个数相同
然后枚举列,把每一行看成一个字符, 进行manacher算出回文串的个数即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#define ll long long
using namespace std;
typedef bitset<28> BT;
const int N = 260;
int n, m, cnt[N * 2][N][27], len[N << 1], odd[N << 1];
BT num[N << 1][N];
char s[N][N];
int cmp(int L, int R, int x, int y) {
if (odd[x] > 1 || odd[y] > 1) return 0;
for (int k = 1; k <= 26; ++k)
if (cnt[x][R][k] - cnt[x][L - 1][k] != cnt[y][R][k] - cnt[y][L - 1][k]) return 0;
return 1;
}
int cal(int l, int r) {
len[1] = 1; int pos = 1, R = 1;
int res = 0;
for (int i = 2; i <= 2 * n + 1; ++i) {
if (i <= R) {
if (len[2 * pos - i] < R - i + 1) len[i] = len[2 * pos - i];
else {
len[i] = R - i + 1;
while (i + len[i] <= 2 * n + 1 && i - len[i] && cmp(l, r, i + len[i], i - len[i]))
R++, len[i]++, pos = i;
}
} else {
len[i] = 1;
while (i + len[i] <= 2 * n + 1 && i - len[i] && cmp(l, r, i + len[i], i - len[i]))
R++, len[i]++, pos = i;
}
if (odd[i] <= 1) res += len[i] / 2;
}
// printf("%d\n", res);
return res;
}
int main()
{
scanf("%d%d", &n, &m);
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) {
for (int k = 1; k <= 26; ++k)
cnt[i << 1][j][k] = cnt[i << 1][j - 1][k];
cnt[i << 1][j][s[i][j] - 'a' + 1]++;
BT tmp; tmp.set(s[i][j] - 'a' + 1);
num[i << 1][j] = num[i << 1][j - 1] ^ tmp;
}
int ans = 0;
for (int i = 1; i <= m; ++i)
for (int j = 1; j <= i; ++j) {
BT tmp;
for (int k = 1; k <= n; ++k) {
tmp = num[k << 1][j - 1] ^ num[k << 1][i];
odd[k << 1] = tmp.count();
}
// printf("%d %d :", j, i);
ans += cal(j, i);
}
printf("%d\n", ans);
}
Codeforces 524 解题报告的更多相关文章
- codeforces 714C解题报告
http://codeforces.com/contest/714/problem/C #include <bits/stdc++.h>//非递归形式建立字典树 using namespa ...
- codeforces#254DIV2解题报告
今天简直大爆发啊... 吃了顿烧烤竟然这么管事. . . .. 本弱渣竟然做出来了3道,并且B题是我第一次在CF中用到算法..(曾经最多也就是贪心. . . ). 题目地址:codeforces#22 ...
- Codeforces 652F 解题报告
题意 有n只蚂蚁在长度为m个格子的环上,环上的格子以逆时针编号,每只蚂蚁每秒往它面向的方向移动一格.如果有两只蚂蚁相撞则相互调换方向,问t秒后每只蚂蚁的位置. 题解 首先通过观察可以发现 蚂蚁相撞产生 ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
随机推荐
- uni-app 调用支付宝支付
本文讲解 uni-app如何调用支付宝进行支付,服务端为 .net编写. 客户端:uni-app 编写 1.根据服务端生成的订单信息发起支付. 服务端:.net 编写 1.生成订单信息.2.接收支 ...
- java-其他-索引
数据结构 设计模式 算法题
- 前端人员使用notepad++基本配置
截图说明: 以上截图说的很明确了,基本满足基本的开发. notepad++前端配置版支持Emmet快速完成:支持Explorer目录管理:支持cmd控制台命令:支持MarkDown编辑预览:其他想用的 ...
- SQLALchemy中关于复杂关系表模型的映射处理
映射在第五步,我们还是一步一步来哈 一. 关系介绍 举一个比较经典的关系,部门与员工(以下是我的需求情况,算是把该有的关系都涉及到了) 1.每个部门会有很多成员(这里排除一个成员属于多个部门的情况) ...
- PHP Yii2.0PHPexecl导出。
use phpoffice\phpexcel; public function actionExport(){ $objPHPExcel = new \phpexcel; $objPHPExcel - ...
- Python科学计算结果的存储与读取
Python科学计算结果的存储与读取 总结于2019年3月17日 荆楚理工学院 计算机工程学院 一.前言 显然,作为一名工科僧,执行科学计算,需用Python.PS:快忘记Matlab吧.我用了二十 ...
- leetcode971
class Solution: def flipMatchVoyage(self, root, voyage): res = [] self.i = 0 def dfs(root): if not r ...
- 5Linux流程控制语句-if、for、while、case语句、计划任务
流程控制语句.计划任务服务程序,今天记录的有点乱,在预习的时候就记了挺多了,书都花了,上几张图. for 循环 →指定一定的范围 while 循环 →指定一定的条件 for循环语句允许脚 ...
- MAC环境配置
必须安装的依赖有:Node.Watchman 和 React Native 命令行工具以及 Xcode. 1.安装homebrew(用brew指令安装其他依赖) /usr/bin/ruby -e &q ...
- 44_redux_comment应用_redux版本_同步功能
项目结构: components里面的东西没变,将app.jsx移动至containers中 /* * 包含所有action的type名称常量 * */ //添加评论 export const ADD ...