AtCoder Beginner Contest 371(ABCDE)
A
个人直接硬解,讨论情况也并不复杂
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
void solve() {
char a, b, c;
cin >> a >> b >> c;
if (a == '<') {
if (c == '<') {
cout << "B" << endl;
return;
} else {
if (b == '<') {
cout << "C" << endl;
return;
} else {
cout << "A" << endl;
return;
}
}
} else {
if (c == '>') {
cout << "B" << endl;
return;
} else {
if (b == '<') {
cout << "A" << endl;
return;
} else {
cout << "C" << endl;
return;
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}
B
只要一旦找到每个家庭的太郎,标记一下就行了
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
bool vt[N];
void solve() {
int n, m;
cin >> n >> m;
while (m--) {
int a;
char c;
cin >> a >> c;
if (!vt[a]) {
if (c == 'M') {
cout << "Yes" << endl;
vt[a] = 1;
} else {
cout << "No" << endl;
}
} else cout << "No" << endl;
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}
C
同构见的不是很多,但该题数据很小,点最多才8个,第一眼的思路是对第二个图的点进行全排列,然后再与图一比较,计算删边和加边的总价值,然后对每个全排列的总价值取最小就是最终答案,代码细节比较多。
如果数据范围较大,确实有必要思考一下怎么做。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=10;
int w[N][N];//加边或删边的权值
int a[N];//全排列
bool p1[N][N],p2[N][N];//分别为图一图二的边
bool vis[N][N];//用于标记,避免重复加边或删边
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
p1[u][v] = 1, p1[v][u] = 1;//反向也记录
}
int M;
cin >> M;
for (int i = 1; i <= M; i++) {
int u, v;
cin >> u >> v;
p2[u][v] = 1, p2[v][u] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
cin >> w[i][j];
w[j][i] = w[i][j];
}
}
for (int i = 1; i <= n; i++) {
a[i] = i;
}
int ans1 = 1e16;
do {
memset(vis, 0, sizeof vis);
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if ((!vis[a[i]][a[j]] && !vis[a[j]][a[i]]) &&
((p1[i][j] && !p2[a[i]][a[j]]) || (!p1[i][j] && p2[a[i]][a[j]]))) {
ans += w[a[i]][a[j]];
vis[a[i]][a[j]] = vis[a[j]][a[i]] = 1;//标记该边已经被处理
}
}
}
ans1 = min(ans, ans1);
} while (next_permutation(a + 1, a + n + 1));//全排列函数
cout << ans1 << endl;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}
D
D题相当模板,查询区间的和,直接上线段树,但该题是以坐标的形式,所有首先是要将坐标的范围转变为下标的区间,以便线段树区间查询。对于左端点,二分去找第一个≥该坐标的下标就是区间左端点;
对于右端点二分去找第一个大于该坐标的下标再减一就是区间右端点;
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define lc p<<1
#define rc (p<<1)|1
const int N=2e5+10;
int x[N],b[N];
struct Tree {
int l, r, sum;
}tr[N*4];
void pushup(int p) { //上传
tr[p].sum = tr[lc].sum + tr[rc].sum;
}
void build(int p,int l,int r) { //建树
tr[p] = {l, r, b[l]};
if (l == r) return;
int m = l + r >> 1;
build(lc, l, m);
build(rc, m + 1, r);
pushup(p);
}
int query(int p,int x,int y) { //区间查询
if (x <= tr[p].l && y >= tr[p].r) { //覆盖则返回
return tr[p].sum;
}
int m = tr[p].l + tr[p].r >> 1; //不覆盖裂开
// pushdown(p);
int sum = 0;
if (x <= m) sum += query(lc, x, y);
if (y > m) sum += query(rc, x, y);
return sum;
}
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
for (int i = 1; i <= n; i++) cin >> b[i];
build(1, 1, n);
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
int l1 = lower_bound(x + 1, x + n + 1, l) - x;
int r1 = upper_bound(x + 1, x + n + 1, r) - x - 1;
if (r1 < l1) cout << 0 << endl;
else cout << query(1, l1, r1) << endl;
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}
E
对于每一个值a[i],包含它的区间的个数是(n - j + 1) * j ,也就是它的贡献。但是,有相同的数,所以造成的贡献就不一样,要取相同的俩个值中间的部分作为贡献

像这样每个元素对应的贡献是这样的俩段区间长度的乘积,图中的贡献就是 i*(n - i + 1) + (j - i) * (n - j + 1) + (k - j) * (n - k + 1)
所以将每种值的元素的所有下标放到一个数组中,然后加上每种值的元素的贡献就能得出答案
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
vector<int> p[N];//p[i]存放值为i所有的元素所在的下标
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[a[i]].push_back(i);
}
int ans = 0;
for (int i = 1; i <= n; i++) {//每种不同值的元素
int cnt = 0;
for (auto j: p[i]) {//所在下标
ans += (n - j + 1) * (j - cnt);
cnt = j;
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}
总结:
C>D, E题很巧妙,用不上数据结构
AtCoder Beginner Contest 371(ABCDE)的更多相关文章
- AtCoder Beginner Contest 254(D-E)
Tasks - AtCoder Beginner Contest 254 D - Together Square 题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一 ...
- AtCoder Beginner Contest 086 (ABCD)
A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...
- AtCoder Beginner Contest 085(ABCD)
A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...
- AtCoder Beginner Contest 084(AB)
A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit ...
- AtCoder Beginner Contest 083 (AB)
A - Libra 题目链接:https://abc083.contest.atcoder.jp/tasks/abc083_a Time limit : 2sec / Memory limit : 2 ...
- AtCoder Beginner Contest 264(D-E)
D - "redocta".swap(i,i+1) 题意: 给一个字符串,每次交换相邻两个字符,问最少多少次变成"atcoder" 题解: 从左到右依次模拟 # ...
- Atcoder Beginner Contest 155E(DP)
#definde HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; int main(){ ios: ...
- Atcoder Beginner Contest 121D(异或公式)
#include<bits/stdc++.h>using namespace std;int main(){ long long a,b; cin>>a>&g ...
- Atcoder Beginner Contest 156E(隔板法,组合数学)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ; long long fac[N] ...
- Atcoder Beginner Contest 155D(二分,尺取法,细节模拟)
二分,尺取法,细节模拟,尤其是要注意a[i]被计算到和a[i]成对的a[j]里时 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
随机推荐
- 从.net开发做到云原生运维(三)——.net core的学习路线
1. 前言 前面几篇文章主要讲了.net技术相关的基本概念和一些涉及的项目什么,本身也没讲太多底层的技术,这篇文章依旧不讲具体的技术,主要介绍.net技术的学习路线.学习路线也是我18年毕业的时候看到 ...
- 【转载】 NCCL(Nvidia Collective multi-GPU Communication Library) Nvidia英伟达的Multi-GPU多卡通信框架NCCL 学习;PCIe 速率调研
原文地址: https://www.cnblogs.com/xuyaowen/p/nccl-learning.html ---------------------------------------- ...
- 传奇人物:“Linux之父”林纳斯·托瓦兹(Linus Torvalds)
偶然看到一个视频: https://www.youtube.com/watch?v=H32IXRkPjHA 林纳斯·托瓦兹(Linus Torvalds)是当之无愧的技术领袖.尤其是那句Just fo ...
- 【转载】 MPP大规模并行处理架构详解
本文来自博客园,作者:五分钟学大数据 原文链接:https://www.cnblogs.com/itlz/p/14998858.html =============================== ...
- springboot中统一日志输出logback
1.背景 为了便于分析和记录系统的运行,一个系统输出其运行的关键日志是非常必要的 比如输出:请求参数.请求url.请求方式.执行的sql.重要操作的日志.响应结果等 而这些日志中,大部分不需要我们手动 ...
- 【VMware ESXi】把硬盘当内存用?VMware 内存分层(Memory Tiering),你值得拥有!
VMware vSphere 8.0 U3 发布了一个非常有意义的功能叫内存分层(Memory Tiering),以利用基于 PCIe 的 NVMe 设备充当第二层(辅助)内存,从而使 ESXi 主机 ...
- 关于mysql配置文件中jdbc url 的记录
版本不同 url不同 大同小异 基本就是不同参数配置的区别 maven 仓库地址 https://mvnrepository.com/artifact/mysql/mysql-connector-ja ...
- Linux C基础——” Makefile “ 文件管理大师你拜访过嘛?
Make简介: 工程管理器,顾名思义,是指管理较多的文件 Make工程管理器也就是个"自动编译管理器",这里的"自动"是指它能够根据文件时间戳自动发现更新过的文 ...
- RabbitMQ接口封装
1.引用 <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client< ...
- c# 复制文件夹内所有文件到另外一个文件夹
/// <summary> /// 开始转移 /// </summary> /// <param name="sender"></para ...