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)的更多相关文章

  1. AtCoder Beginner Contest 254(D-E)

    Tasks - AtCoder Beginner Contest 254 D - Together Square 题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一 ...

  2. AtCoder Beginner Contest 086 (ABCD)

    A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...

  3. AtCoder Beginner Contest 085(ABCD)

    A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...

  4. AtCoder Beginner Contest 084(AB)

    A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit  ...

  5. AtCoder Beginner Contest 083 (AB)

    A - Libra 题目链接:https://abc083.contest.atcoder.jp/tasks/abc083_a Time limit : 2sec / Memory limit : 2 ...

  6. AtCoder Beginner Contest 264(D-E)

    D - "redocta".swap(i,i+1) 题意: 给一个字符串,每次交换相邻两个字符,问最少多少次变成"atcoder" 题解: 从左到右依次模拟 # ...

  7. Atcoder Beginner Contest 155E(DP)

    #definde HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; int main(){ ios: ...

  8. Atcoder Beginner Contest 121D(异或公式)

    #include<bits/stdc++.h>using namespace std;int main(){    long long a,b;    cin>>a>&g ...

  9. Atcoder Beginner Contest 156E(隔板法,组合数学)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ; long long fac[N] ...

  10. Atcoder Beginner Contest 155D(二分,尺取法,细节模拟)

    二分,尺取法,细节模拟,尤其是要注意a[i]被计算到和a[i]成对的a[j]里时 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...

随机推荐

  1. npm WARN config global `--global`, `--local` are deprecated. Use `--location 的解决方法

    1.背景 2.解决步骤 2.1.找到nodejs的安装路径 2.2.修改配置文件 将文件里的 prefix-g 改为 prefix --location=global 修改前: 修改后: 点击保存就解 ...

  2. SonarQube集成Xunit单元测试

    安装SonarQube 利用docker 安装SonarQube docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE ...

  3. SMU Summer 2023 Contest Round 2

    SMU Summer 2023 Contest Round 2 A. Treasure Hunt 当\(x1 - x2\)的差值与\(y1-y2\)的差值都能被\(x,y\)整除时,且商之和为2的倍数 ...

  4. 优秀架构设计与web文档

    架构风格与基于网络的软件架构设计 https://docs.huihoo.com/rest/REST_cn.pdf rfc https://tools.ietf.org/html/rfc2616

  5. Github 通义千问模型测试

    通义千问 大模型安装 相关地址 https://github.com/QwenLM/Qwen2-Audio/blob/main/README_CN.md PS C:\Users\supermao> ...

  6. 玄机蓝队靶场_应急响应_01:linux日志分析

    个人感觉这个靶场主要考验对linux的命令的基础掌握,对日志路径的基本了解. 一:解题 (1)ssh连接靶场,先用命令lsb_release -a看看是什么系统.然后发现是Debian GNU/Lin ...

  7. 巴特沃斯LPF设计(硬件电路实现)

    高阶 (2n) VSVC单位增益巴特沃斯低通滤波器设计,可分解为 n 个二阶低通,通过对这多个二阶低通的组合优化,可提高滤波器的低通特性和稳定性. 串联的传递函数是各个二阶滤波器传递函数的乘积:\({ ...

  8. P2P 下载入门

    基本概念 直链下载: https://file-examples.com/wp-content/storage/2017/04/file_example_MP4_480_1_5MG.mp4 直链就是一 ...

  9. exceptionless 在 windows 上 手动部署,非docker 详细步骤

    关于exceptionless 是什么我就不多说了,能看到这篇文章的都知道了.网上几乎都是docker部署的,docker部署的确十分方便,但是有的人没有条件用docker,像我就不想花这个钱去多服务 ...

  10. 基于 GoFrame 框架的 Go 项目打包成镜像,并上传至 Harbor 镜像库

    〇.前言 在云服务时代最流行的部署方式就是容器部署,这也是最推荐的部署方式. 对于 GoFrame 框架就不多介绍了,直接来初始化一个 demo,备用. // 初始化一个项目:gf-demo gf i ...