打的很快乐的一次比赛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. 在每一行中, 出现次数为奇数的字符数 \(<=1\)
    2. 对应两行每种字符的个数相同

然后枚举列,把每一行看成一个字符, 进行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 解题报告的更多相关文章

  1. codeforces 714C解题报告

    http://codeforces.com/contest/714/problem/C #include <bits/stdc++.h>//非递归形式建立字典树 using namespa ...

  2. codeforces#254DIV2解题报告

    今天简直大爆发啊... 吃了顿烧烤竟然这么管事. . . .. 本弱渣竟然做出来了3道,并且B题是我第一次在CF中用到算法..(曾经最多也就是贪心. . . ). 题目地址:codeforces#22 ...

  3. Codeforces 652F 解题报告

    题意 有n只蚂蚁在长度为m个格子的环上,环上的格子以逆时针编号,每只蚂蚁每秒往它面向的方向移动一格.如果有两只蚂蚁相撞则相互调换方向,问t秒后每只蚂蚁的位置. 题解 首先通过观察可以发现 蚂蚁相撞产生 ...

  4. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  5. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  6. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  7. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  8. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  9. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

随机推荐

  1. C 语言 计算

    note1: 不要把表达式写的太复杂,不容易阅读和理解,容易造成读程序的误解,所以要避免写出复杂的表达式. note2:程序是按步执行的,程序表达的是顺序执行的动作,而不是关系.

  2. json jmespath的使用

    在接口测试的过程中,我们经常会接触到json格式respones,我们会经常去做取JSON中某个值的操作,可以用jmespath分析.转换和选择性的提取JSON数据进行操作,功能非常强大,易读. 一. ...

  3. 全面超越Appium,使用Airtest超快速开发App爬虫

    想开发网页爬虫,发现被反爬了?想对 App 抓包,发现数据被加密了?不要担心,使用 Airtest 开发 App 爬虫,只要人眼能看到,你就能抓到,最快只需要2分钟,兼容 Unity3D.Cocos2 ...

  4. spring boot 整合quartz ,job不能注入的问题

    在使用spring boot 整合quartz的时候,新建定时任务类,实现job接口,在使用@AutoWire或者@Resource时,运行时出现nullpointException的问题.显然是相关 ...

  5. 啊哈算法第四章第三节 层层递进-广度优先搜索 java实现

    package corejava; public class FourThree { static int [][]a=new int[50][50]; static int [][]b=new in ...

  6. springIoC的理解01

    IOC将模块(对象)之间的依赖关系交由IOC容器管理,让应用开发对接口编程,而不是对类编程.依赖反转:每个对象都需要与其合作的对象(也就是依赖的对象)的引用.未使用依赖反转的特性之前,是需要先创建一个 ...

  7. jsonp现实跨域Ajax CORS

    浏览器有一个很重要的概念——同源策略(Same-Origin Policy).所谓同源是指,域名,协议,端口相同.不同源的客户端脚本(javascript.ActionScript)在没明确授权的情况 ...

  8. 使用IDEA的项目上传到GitHub

    使用IDEA的项目上传到GitHub 前提条件: 1.配置好Git(https://jingyan.baidu.com/article/8275fc867b652046a03cf613.html) 2 ...

  9. o2o、c2c、b2c、b2b、b2b2c都是什么?

    o2o:线上线下,如线上消费,线下享受服务,o2o是不需要物流的,是线上购买的东西,自己去线下获得.c2c:个人对个人,消费者与消费者之间的小成本交易,买卖双方都不是公司,如你在咸鱼上卖自己的东西.b ...

  10. python学习Day9 内存管理

    复习 :文件处理 1. 操作文件的三步骤:-- 打开文件:此时该文件在硬盘的空间被操作系统持有 |  文件对象被应用程序持用 -- 操作文件:读写操作 -- 释放文件:释放操作系统对文件在硬盘间的持有 ...