[Codeforces Educational Round 71]Div. 2
总结
手速场...像我这种没手速的就直接炸了...
辣鸡 E 题交互,少打了个 ?
调了半个小时...
到最后没时间 G 题题都没看就结束了...结果早上起来被告知是阿狸的打字机...看了看题一毛一样...
提供翻译造福人类...
A. There Are Two Types Of Burgers
Description
你有 \(b\) 片面包,\(p\) 块牛肉,\(f\) 块鸡肉。两片面包和一块肉可以组成一个汉堡,两种汉堡的价钱分别是 \(h,c\)。求最大收益。\(t\) 组询问。
\(1\leq t,b,p,f,h,c\leq 100\)
Solution
不用贪心,直接枚举多少个鸡肉汉堡多少个牛肉汉堡,判断面包是否够用即可。
Code
#include <bits/stdc++.h>
using namespace std;
int t, b, p, f, h, c, ans;
int main() {
scanf("%d", &t);
while (t--) {
ans = 0;
scanf("%d%d%d%d%d", &b, &p, &f, &h, &c);
for (int i = 0; i <= p; i++)
for (int j = 0; j <= f; j++)
if (i+j <= b/2)
ans = max(ans, i*h+c*j);
printf("%d\n", ans);
}
return 0;
}
B. Square Filling
Description
给你一个 \(n\times m\) 的空白棋盘,每次你可以选择一个 \(2\times 2\) 的矩阵染色。问你是否能染成目标状态,输出方案(不用求最优解)。
\(1\leq n,m\leq 50\)
Solution
对于目标棋盘中的某一块黑色,一定只能由四种方法使他变黑。
那么对于每个黑块,直接枚举染它的矩阵的左上角,看这四种方案中是否有可行的。即这个 \(2\times 2\) 的矩阵在目标棋盘中都为黑色,若可行,标记输出;若都不可行,显然无解。
Code
#include <bits/stdc++.h>
using namespace std;
int n, m, a[55][55], tmp;
int ans[55][55], tot;
void noans() {
puts("-1"); exit(0);
}
bool color(int x, int y) {
if (x == n || y == m || x == 0 || y == 0) return false;
if (!a[x][y] || !a[x+1][y] || !a[x][y+1] || !a[x+1][y+1]) return false;
ans[x][y] = 1;
return true;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j])
if (color(i-1, j-1) || color(i, j-1) || color(i-1, j) || color(i, j));
else noans();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
tot += ans[i][j];
printf("%d\n", tot);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (ans[i][j])
printf("%d %d\n", i, j);
return 0;
}
C. Gas Pipeline
Description
一条长度为 \(n\) 的路,让你在路上架管道,管道高度 \(>\) 马路高度,马路高度只为 \(0\) 或 \(1\),管道高度只能为 \(1\) 或 \(2\)。并且管道开始和结束高度为 \(1\)。
如果在 \(x\) 处要修改管道高度,那么花费管道长度为 \(2\),否则为 \(1\)。同时管道需要柱子支撑,长度为 \(n\) 的管道需要 \(n+1\) 根柱子,柱子长度取决于相邻的部分的最大高度。
单位长度管道花费 \(a\),单位长度柱子花费为 \(b\)。求最小花费。
\(2\leq n\leq 2\cdot 10^5,1\leq a,b\leq 10^8\)
Solution
令 \(f_{i,0/1}\) 表示修管道 \(1\sim i\),且 \(i\) 处管道高度为 \(1/2\) 的最小花费。
转移只需考虑第 \(i-1\) 个位置管道高度即可。注意,如果 \(i\) 处马路高度为 \(1\),那么直接将 \(f_{i,0}\) 赋值为 \(\infty\)。
答案为 \(f_{n,0}\)。
Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+5;
const ll inf = 2e15;
int t, n, a, b;
char ch[N];
ll f[N][2];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d", &n, &a, &b);
scanf("%s", ch+1);
f[1][0] = a+2ll*b;
f[1][1] = 2ll*a+2ll*b;
for (int i = 2; i <= n; i++) {
f[i][0] = min(f[i-1][0]+a+b, f[i-1][1]+2ll*a+2ll*b);
f[i][1] = min(f[i-1][1]+a+2ll*b, f[i-1][0]+2ll*a+2ll*b);
if (ch[i] == '1') f[i][0] = inf;
}
printf("%I64d\n", f[n][0]);
}
return 0;
}
D. Number Of Permutations
Description
给你 \(n\) 个有序二元组。定义一个“坏的”二元组序列指,存在一个维度单调不降。
将这 \(n\) 个二元组全排列,问有多少种方法使它变得“不坏”,对 \(998244353\) 取模。
\(1\leq n\leq 3\cdot 10^5\)
Solution
考虑间接法。
对于单一维度,我们将其排序,若连续 \(x\) 个数字相同,那么这 \(x\) 个位置可以任意排,贡献 \(x!\) 的方案数。
两个维度处理完之后,我们来加上多减去的部分。不过前提是原二元组序列能够排成两个维度均单调不降的序列。
那么如果排序后连续 \(x\) 个二元组相同,那么这 \(x\) 个位置可以任意排,贡献 \(x!\) 的方案数。
Code
#include <bits/stdc++.h>
using namespace std;
const int yzh = 998244353, N = 3e5+5;
int n, fac[N], ca[N], cb[N], ans, tmp, cnt = 1;
struct node {
int a, b;
bool operator < (const node &t) const {
return a == t.a ? b < t.b : a < t.a;
}
} x[N];
int main() {
scanf("%d", &n); fac[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i].a, &x[i].b);
fac[i] = 1ll*i*fac[i-1]%yzh;
ca[x[i].a]++, cb[x[i].b]++;
}
ans = fac[n], tmp = 1;
for (int i = 1; i <= n; i++)
tmp = 1ll*tmp*fac[ca[i]]%yzh;
(ans -= tmp) %= yzh;
tmp = 1;
for (int i = 1; i <= n; i++)
tmp = 1ll*tmp*fac[cb[i]]%yzh;
(ans -= tmp) %= yzh;
sort(x+1, x+n+1);
for (int i = 1; i <= n; i++)
if (x[i].b < x[i-1].b) {printf("%d\n", (ans+yzh)%yzh); return 0; }
tmp = 1;
for (int i = 1; i <= n+1; i++)
if (x[i].a == x[i-1].a && x[i].b == x[i-1].b) ++tmp;
else {
cnt = 1ll*cnt*fac[tmp]%yzh;
tmp = 1;
}
(ans += cnt) %= yzh;
printf("%d\n", (ans+yzh)%yzh);
return 0;
}
E. XOR Guessing
Description
这是一道交互题。
交互库先生成一个数 \(x\),你需要猜出 \(x\) 是多少。
你可以询问两次,你每次给出 \(100\) 个整数,这些整数范围和 \(x\) 相同,交互库会随机选出 \(100\) 个数中的一个,与 \(x\) 异或后返回。注意,所有询问的数(共 \(200\) 个)不能重复。询问两次后输出结果。
\(x\in[0,2^{14}-1]\)
Solution
可知 \(x\) 是位数为 \(14\) 的二进制数字(高位 \(0\) 补齐)。那么两次询问分别确定低的 \(7\) 位和高 \(7\) 位即可。
确定低的 \(7\) 位时,只需让给出的 \(100\) 个数低的 \(7\) 位均为 \(0\) 即可,因为 \(2^7=128>100\),一定能选出 \(100\) 个数。只需取返回值的低的 \(7\) 位,这和真实值的低的 \(7\) 位时相等的。
高位同理。
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = (1<<7)-1, tmp, ans = 0;
int b = (1<<14)-1-a;
printf("? ");
for (int i = 1; i <= 100; i++)
printf("%d%c", (i<<7), " \n"[i == 100]);
fflush(stdout);
scanf("%d", &tmp);
ans += (tmp&a);
printf("? ");
for (int i = 1; i <= 100; i++)
printf("%d%c", i, " \n"[i == 100]);
fflush(stdout);
scanf("%d", &tmp);
ans += (tmp&b);
printf("! %d\n", ans);
fflush(stdout);
return 0;
}
F. Remainder Problem
Description
让你维护长度为 \(500000\) 的序列,支持 \(q\) 次操作:
- 单点加;
- 询问:\(500000\) 个位置模 \(x\) 余 \(y\) 的位置的值的和。
\(1\leq q\leq 500000\)
Solution
发现 \(500000^{1.5}\) 大概等于三亿多...发现时限 \(4s\),就喜闻乐见的分块了。
维护数组 \(cal[x][y]\),表示模 \(x\) 余 \(y\) 的位置的值的和。只需开到 \(\sqrt{500000}\) 的大小就行了。
较大的值直接在原数组上枚举。
修改和询问复杂度是 \(O(\sqrt{500000})\) 的,查表的话是 \(O(1)\) 的。
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 500000+5;
int cal[710][710], a[N], q, t, x, y;
int main() {
scanf("%d", &q);
while (q--) {
scanf("%d%d%d", &t, &x, &y);
if (t == 1) {
a[x] += y;
for (int i = 1; i <= 709; i++)
cal[i][x%i] += y;
} else {
if (x <= 709) printf("%d\n", cal[x][y]);
else {
int ans = 0;
for (int i = 0; i*x+y <= 500000; i++)
ans += a[i*x+y];
printf("%d\n", ans);
}
}
}
return 0;
}
G. Indie Album
生成 \(n\) 个字符串。生成方式为
- 新取一个字符;
- 将前面某个字符串复制后,在末尾新添一个字符。
字符集为小写字母。\(q\) 组询问,问串 \(t\) 在某个串中出现了多少次。
\(1\leq n,q,\sum|t|\leq 4\cdot 10^5\)
Solution
Code
我太懒了...
[Codeforces Educational Round 71]Div. 2的更多相关文章
- Codeforces Beta Round #65 (Div. 2)
Codeforces Beta Round #65 (Div. 2) http://codeforces.com/contest/71 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
随机推荐
- Python之颜色的表示
字背景颜色范围:40----49 40:黑 41:深红 42:绿 43:黄色 44:蓝色 45:紫色 46:深绿 47:白色 字颜色:30-----------39 30:黑 31:红 32:绿 33 ...
- LeetCode 5274. Number of Ways to Stay in the Same Place After Some Steps - Java - DP
题目链接:5274. 停在原地的方案数 You have a pointer at index 0 in an array of size arrLen. At each step, you can ...
- Docker之dockerfile制作jdk镜像
目的: Dockerfile简介 Dockerfile制作jdk镜像 Dockerfile简介 了解dockerfile之前要先了解Docker基本概念和使用可参考:https://www.cnblo ...
- 配置多用户SMB挂载
在 system1 通过 SMB 共享目录 /devops ,并满足下列要求: 1.共享名为 devops 2.共享目录 devops 只能 group8.example.com 域中的客户端使用 3 ...
- Locust性能测试-no-web模式和csv报告保存 转自:悠悠
前言 前面是在web页面操作,需要手动的点start启动,结束的时候也需要手工去点stop,没法自定义运行时间,这就不太方便. locust提供了命令行运行的方法,不启动web页面也能运行,这就是no ...
- Tomcat组件梳理--Server
Tomcat组件梳理--Server 1.Server组件的定义和功能概述 定义: Server组件用于描述一个启动的Tomcat实例,一个Tocmat被启动,在操作系统中占用一个进程号,提供web服 ...
- 2019 2345网址导航java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.2345网址导航等公司offer,岗位是Java后端开发,因为发展原因最终选择去了2345网址导航,入职一年时 ...
- Django:表多对多查询、聚合分组、FQ查询、事务
1表多对多的关系查询 准备工作创建表结构 from django.db import models # Create your models here. class Publisher(models. ...
- 谷歌hack语法
搜索标题 intitle:"登入" //加引号是精确搜索 搜索正文 intext:"登入" 在URL中搜索 inurl:"/phpmyadmin&qu ...
- iOS OpenCV资料收集
OpenCV iOS Title: OpenCV iOS Hello Compatibility: > OpenCV 2.4.3 Author: Charu Hans You will lear ...