Codeforces Round #684 (Div. 2)
A
讨论三种情况,不换/全换成0/全换成1 ,取一个花费最小值
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 20;
int n, c0, c1, h;
char str[N];
int main()
{
int T;
scanf("%d", &T);
while(T -- )
{
scanf("%d%d%d%d%s", &n, &c0, &c1, &h, str);
int a = 0, b = 0;
for(int i = 0; i < n; ++ i)
if(str[i] == '0') a ++;
else b ++;
int res = 1e9;
res = min(res, n * c0 + h * b);
res = min(res, n * c1 + h * a);
res = min(res, c0 * a + c1 * b);
printf("%d\n", res);
}
return 0;
}
B
排序之后,从\(n \times k - \dfrac{n}{2}\)开始取,每隔\(\dfrac{n}{2}\)取一个,取\(k\)个即可
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000 + 20;
int n, k, a[N * N];
int main()
{
int T;
scanf("%d", &T);
while(T -- )
{
scanf("%d%d", &n, &k);
for(int i = 1; i <= n * k; ++ i) scanf("%d", &a[i]);
sort(a + 1, a + n * k + 1);
LL res = 0;
for(int i = n * k - n / 2, j = 1; j <= k; i -= n / 2 + 1, ++ j)
res += a[i];
printf("%lld\n", res);
}
return 0;
}
C1/C2
按行处理,处理前\(n - 2\)行,最后\(2\)行按列处理,处理到\(m - 2\)列,最后\(4\)个格子讨论即可.
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n, m;
int a[N][N];
struct zt
{
int a, b, c, d, e, f;
};
vector<zt> vec;
int main()
{
int T;
scanf("%d",&T);
while(T --)
{
vec.clear();
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= m; ++ j)
scanf("%1d", &a[i][j]);
for(int i = 1; i <= n - 2; ++ i)
for(int j = 1; j <= m; ++ j)
if(a[i][j])
{
vec.push_back((zt){i, j, i + 1, j, i + 1, j < m ? j + 1 : j - 1});
a[i][j] ^= 1; a[i + 1][j] ^= 1; a[i + 1][j < m ? j + 1 : j - 1] ^= 1;
}
for(int j = 1; j <= m - 2; ++ j)
for(int i = n - 1; i <= n; ++ i)
if(a[i][j])
{
vec.push_back((zt){i, j, i, j + 1, i < n ? i + 1 : i - 1, j + 1});
a[i][j] ^= 1; a[i][j + 1] ^= 1; a[i < n ? i + 1 : i - 1][j + 1] ^= 1;
}
int num = a[n - 1][m - 1] + a[n - 1][m] + a[n][m - 1] + a[n][m];
if(num == 1)
{
if(a[n][m])
{
vec.push_back((zt){n, m, n, m - 1, n - 1, m - 1});
vec.push_back((zt){n, m, n, m - 1, n - 1, m});
vec.push_back((zt){n, m, n - 1, m, n - 1, m - 1});
}
if(a[n - 1][m])
{
vec.push_back((zt){n - 1, m, n - 1, m - 1, n, m - 1});
vec.push_back((zt){n - 1, m, n - 1, m - 1, n, m});
vec.push_back((zt){n - 1, m, n, m, n, m - 1});
}
if(a[n][m - 1])
{
vec.push_back((zt){n, m - 1, n - 1, m - 1, n - 1, m});
vec.push_back((zt){n, m - 1, n - 1, m - 1, n, m});
vec.push_back((zt){n, m - 1, n, m, n - 1, m});
}
if(a[n - 1][m - 1])
{
vec.push_back((zt){n - 1, m - 1, n, m - 1, n, m});
vec.push_back((zt){n - 1, m - 1, n, m - 1, n - 1, m});
vec.push_back((zt){n - 1, m - 1, n - 1, m, n, m});
}
}
if(num == 2)
{
if(a[n - 1][m - 1] && a[n - 1][m])
{
vec.push_back((zt){n - 1, m - 1, n, m - 1, n, m});
vec.push_back((zt){n, m - 1, n, m, n - 1, m});
}
if(a[n][m - 1] && a[n][m])
{
vec.push_back((zt){n, m - 1, n - 1, m - 1, n - 1, m});
vec.push_back((zt){n, m, n - 1, m, n - 1, m - 1});
}
if(a[n - 1][m - 1] && a[n][m - 1])
{
vec.push_back((zt){n - 1, m - 1, n - 1, m, n, m});
vec.push_back((zt){n, m - 1, n - 1, m, n, m});
}
if(a[n - 1][m] && a[n][m])
{
vec.push_back((zt){n - 1, m, n - 1, m - 1, n, m - 1});
vec.push_back((zt){n, m, n, m - 1, n - 1, m - 1});
}
if(a[n - 1][m - 1] && a[n][m])
{
vec.push_back((zt){n - 1, m - 1, n - 1, m, n, m - 1});
vec.push_back((zt){n, m, n - 1, m, n, m - 1});
}
if(a[n][m - 1] && a[n - 1][m])
{
vec.push_back((zt){n - 1, m, n - 1, m - 1, n, m});
vec.push_back((zt){n, m - 1, n - 1, m - 1, n, m});
}
}
if(num == 3)
{
vector<int> tmp;
if(a[n][m]) tmp.push_back(n), tmp.push_back(m);
if(a[n - 1][m - 1]) tmp.push_back(n - 1), tmp.push_back(m - 1);
if(a[n - 1][m]) tmp.push_back(n - 1), tmp.push_back(m);
if(a[n][m - 1]) tmp.push_back(n), tmp.push_back(m - 1);
vec.push_back((zt){tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]});
}
if(num == 4)
{
vec.push_back((zt){n - 1, m - 1, n - 1, m, n, m - 1});
vec.push_back((zt){n, m, n, m - 1, n - 1, m - 1});
vec.push_back((zt){n, m, n, m - 1, n - 1, m});
vec.push_back((zt){n, m, n - 1, m, n - 1, m - 1});
}
printf("%d\n", vec.size());
for(int i = 0; i < vec.size(); ++ i)
printf("%d %d %d %d %d %d\n", vec[i].a, vec[i].b, vec[i].c, vec[i].d, vec[i].e, vec[i].f);
}
return 0;
}
E
线段树,维护一个min和max和区间和,利用单调不增的性质进行修改和查询
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, m, w[N];
struct Node
{
int l, r;
LL maxv, minv, sum, lazy;
}tr[N * 4];
void pushup(int u)
{
tr[u].maxv = max(tr[u << 1].maxv, tr[u << 1 | 1].maxv);
tr[u].minv = min(tr[u << 1].minv, tr[u << 1 | 1].minv);
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
}
void pushdown(int u)
{
Node &root = tr[u], &left = tr[u << 1], &right = tr[u << 1 | 1];
if(root.lazy)
{
left.maxv = right.maxv = root.lazy;
left.minv = right.minv = root.lazy;
left.sum = (left.r - left.l + 1) * root.lazy;
right.sum = (right.r - right.l + 1) * root.lazy;
left.lazy = right.lazy = root.lazy;
root.lazy = 0;
}
}
void build(int u, int l, int r)
{
if(l == r) tr[u] = {l, r, w[r], w[r], w[r], 0};
else
{
tr[u] = {l, r, 0, 0, 0, 0};
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
void modify(int u, int l, int r, int v)
{
if(tr[u].minv >= v) return;
if(tr[u].l >= l && tr[u].r <= r && tr[u].maxv < v)
{
tr[u].lazy = v;
tr[u].minv = tr[u].maxv = v;
tr[u].sum = (LL)(tr[u].r - tr[u].l + 1) * v;
}
else
{
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) modify(u << 1, l, r, v);
if(r > mid) modify(u << 1 | 1, l, r, v);
pushup(u);
}
}
int query(int u, int l, int r, int &v)
{
if(tr[u].minv > v) return 0;
if(tr[u].l >= l && tr[u].r <= r && tr[u].sum <= v)
{
v -= tr[u].sum;
return tr[u].r - tr[u].l + 1;
}
else
{
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
int res = 0;
if(l <= mid) res = query(u << 1, l, r, v);
if(r > mid) res += query(u << 1 | 1, l, r, v);
return res;
}
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++ i) scanf("%d", &w[i]);
build(1, 1, n);
while(m -- )
{
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if(op == 1) modify(1, 1, x, y);
else printf("%d\n", query(1, x, n, y));
}
return 0;
}
2020.11.19
Codeforces Round #684 (Div. 2)的更多相关文章
- Codeforces Round #684 (Div. 2)【ABC1C2】
比赛链接:https://codeforces.com/contest/1440 A. Buy the String 题解 枚举字符串中 \(0\) 或 \(1\) 的个数即可. 代码 #includ ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- Dapr微服务应用开发系列3:服务调用构件块
题记:这篇开始逐一深入介绍各个构件块,从服务调用开始 原理 所谓服务调用,就是通过这个构件块让你方便的通过HTTP或者gRPC协议同步调用其他服务的方法,这些方法也是通过HTTP或者gRPC来暴露的. ...
- 使用 Typecho 搭建博客
nginx 配置文件 [root@dbtest ~]# cat /etc/nginx/conf.d/www.typecho.com.conf server { listen 80; server_na ...
- spring再学习之简单测试
一.spring是怎么工作的那,通过一个类装载进容器进行描述: 首先创建一个类user: package cn.itcast.bean; public class User { public User ...
- 问题记录 java.lang.NoClassDefFoundError: org/dom4j/DocumentException
客户端调webservice服务产生以下错误 AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.genera ...
- 一分钟搞懂JavaScript中的JSON对象
JSON(JavaScript Object Notation)是表示值和对象的通用格式. JavaScript 提供了如下方法: JSON.stringify 将对象转换为 JSON. JSON.p ...
- 【Alpaca】.Net版开源配置中心 - 技术选型 Vue 3.0
是否可以用 Vue 3.0 现有的Vue 2.* 不推荐,坐等Vue 3.0出迁移工具吧,手动改的话工作量还是不小的 新项目 考虑下团队内对Vue + TS + VS Code的熟练程度.过程中你会遇 ...
- git hooks All In One
git hooks All In One $ xgqfrms git:(main) cd .git/ $ .git git:(main) ls COMMIT_EDITMSG HEAD branches ...
- TypeScript 4.1 Quick Start Tutorials
TypeScript 4.1 Quick Start Tutorials TypeScript 4.1 快速上手教程 https://typescript-41-quick-start-tutoria ...
- JWT & JSON Web Tokens
JSON Web Tokens https://jwt.io json web token example https://jwt.io/introduction/ https://medium.co ...
- vue3 deep dive
vue3 deep dive vue core vnode vue core render / mount / patch refs https://www.vuemastery.com/course ...