A - Rotate

先输出第二和第三个字符,然后再输出第一个字符即可

B - Visibility

以 \((x,y)\) 作为起点向4个方向探索不是 # 的点,注意一下会在\((x,y)\)重复计算 \(3\) 次,所以要 cnt - 3

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int H, W, X, Y;
cin >> H >> W >> X >> Y;
X -= 1, Y -= 1;
vector<string> s(H);
for (int i = 0; i < H; ++i) cin >> s[i];
int cnt = 0;
// 向 4 个方向探索
for (int i = X; i < H and s[i][Y] != '#'; ++i) cnt++;
for (int i = X; i >= 0 and s[i][Y] != '#'; --i) cnt++;
for (int i = Y; i < W and s[X][i] != '#'; ++i) cnt++;
for (int i = Y; i >= 0 and s[X][i] != '#'; --i) cnt++;
cout << cnt - 3 << "\n";
return 0;
}

C - ORXOR Editorial

Good,位运算典型题

int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int& x : a) cin >> x;
int ans = INT_MAX;
for (int i = 0; i < (1 << (n - 1)); ++i) {
int xored = 0, ored = 0;
for (int j = 0; j <= n; ++j) {
if (j < n) ored |= a[j];
if (j == n || (i >> j & 1)) xored ^= ored, ored = 0;
}
ans = min(ans, xored);
}
cout << ans << "\n";
return 0;
}

D - Opposite

// C++似乎内置了 PI 也可以不定义 M_PI
#define M_PI 3.14159265358979323846
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int N;
double xx, yy, x, y;
cin >> N >> xx >> yy >> x >> y;
double a = (xx + x) / 2, b = (yy + y) / 2;
xx -= a, yy -= b;
double m = xx * cos(2 * M_PI / N) - yy * sin(2 * M_PI / N);
double n = xx * sin(2 * M_PI / N) + yy * cos(2 * M_PI / N);
cout << fixed << setprecision(12) << m + a << "\n" << n + b;
return 0;
}

E - Traveler

很好的处理方法

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 7;
vector<int> v[N];
ll l[N], r[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for (int i = 0, x, c; i < n; ++i) {
cin >> x >> c;
v[c].push_back(x);
}
v[0].push_back(0);
v[n + 1].push_back(0); // int ans = 0;
for (int i = 1, j = 0; i <= n + 1; ++i) {
if (v[i].empty()) continue;
sort(v[i].begin(), v[i].end());
int lx = v[i].front(), rx = v[i].back();
int ly = v[j].front(), ry = v[j].back();
// cout << lx << " " << rx << "\n";
l[i] = min(abs(rx - ly) + l[j], abs(rx - ry) + r[j]) + rx - lx;
r[i] = min(abs(lx - ly) + l[j], abs(lx - ry) + r[j]) + rx - lx;
// ans = min(l[i], r[i]);
j = i;
} cout << min(l[n + 1], r[n + 1]) << "\n";
return 0;
}

F - Construct a Palindrome

#include <bits/stdc++.h>
using namespace std;
const int N = 1002;
int n, m;
char s[2];
struct node {
int s, t, sp;
} r;
queue<node> q;
vector<int> a[N][26];
int ans = 1e9, vis[N][N];
//把边看成点
//对于两对边(a,b) (c,d)
//如果(a,c) 和 (b,c)之间存在边 而且边上的字母相同的话
//那么这两个边变成的点就可以联通
int bfs() {
while (!q.empty()) {
r = q.front();
q.pop();
if (r.sp == ans) return ans << 1;
for (int i = 0; i < 26; ++i)
for (int j = 0; j < a[r.s][i].size(); ++j)
for (int k = 0; k < a[r.t][i].size(); ++k) {
int ns = a[r.s][i][j];
int nt = a[r.t][i][k];
if (ns == r.t || nt == r.s) return r.sp << 1 | 1;
if (ns == nt) ans = r.sp + 1;
if (vis[ns][nt]) continue;
vis[ns][nt] = 1;
q.push((node){ns, nt, r.sp + 1});
}
}
return -1;
}
int main() {
scanf("%d%d", &n, &m);
for (int x, y; m; --m) {
scanf("%d%d%s", &x, &y, s);
a[x][*s - 'a'].push_back(y);
a[y][*s - 'a'].push_back(x);
}
vis[1][n] = 1;
q.push((node){1, n, 0});
printf("%d", bfs());
}

AtCoder Beginner Contest 197(Sponsored by Panasonic) Person Editorial的更多相关文章

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

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

  2. Atcoder Beginner Contest 147D(按位处理)

    把每个数字每一位上二进制数字取出,求答案时直接用N个数里这一位是0的个数乘上这一位是1的个数然后乘上二的这一位次方,注意所有可能溢出的地方都要对mod取模. #define HAVE_STRUCT_T ...

  3. Atcoder Beginner Contest 140E(多重集,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;multiset<long long&g ...

  4. Atcoder Beginner Contest 139E(模拟,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int n;int a[1007][1007] ...

  5. 数学--数论-- AtCoder Beginner Contest 151(组合数+数学推导)好题(๑•̀ㅂ•́)و✧

    思路统计最大值出现的次数,和最小值出现的次数.虽然是每次都是MAX-MIN,我们先求MAX的和,然后再求MIN的和,做差. 这次代码写的真的很漂亮 题目地址: #include <bits/st ...

  6. AtCoder Beginner Contest 254(D-E)

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

  7. AtCoder Beginner Contest 086 (ABCD)

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

  8. AtCoder Beginner Contest 085(ABCD)

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

  9. AtCoder Beginner Contest 084(AB)

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

  10. AtCoder Beginner Contest 083 (AB)

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

随机推荐

  1. 关于如何来测一款app的思考

    最近工作当中需要整体测一遍app,需要全方面思考并且尽可能覆盖所有待测点,因为整理总结了这篇关于app测试的总体大纲 一.功能测试 1.1界面测试 1.1.1导航测试 ---是否易于导航.导航是否直观 ...

  2. New Type Functions/Utilities for Dealing with Ranges in C++20

    Generic Types of Ranges   类型萃取从字面意思上来说其实就是帮助我们挑选某个对象的类型,筛选特定的对象来做特定的事.可以先来回顾一下以前的写法. #include <ve ...

  3. dubbo优化

    dubbo 的优化配置 在spring整合的配置文件中配置1. 超时配置在消费方调用服务方接口服务时,会发生如下超时错误,Dubbo消费方在调用服务时,超时时间默认是1000毫秒,这个时间可能比较短, ...

  4. [ABC317G] Rearranging

    Problem Statement There is a grid with $N$ rows and $M$ columns. The square at the $i$-th row from t ...

  5. Chrome扩展的核心:manifest 文件(上)

    大家好,我是dom哥.我正在写关于 Chrome 扩展开发的系列文章,感兴趣的可以点个小星星. Chrome 在全球浏览器市场份额独占 6 成,无论是对普通用户还是开发者,都是电脑里的必备利器.Chr ...

  6. 使用代码生成工具快速开发应用-结合后端Web API提供接口和前端页面快速生成,实现通用的业务编码规则管理

    在前面随笔<在Winform应用中增加通用的业务编码规则生成>,我介绍了基于Winform和WPF的一个通用的业务编码规则的管理功能,本篇随笔介绍基于后端Web API接口,实现快速的Vu ...

  7. python操作redis集群、redis主从+哨兵

    主从+哨兵 from redis.sentinel import Sentinel if __name__ == '__main__': # 哨兵监听的别名,这个就是你redis配置中的名字 serv ...

  8. 记录一次K8s pod被杀的排查过程

    问题描述 今天下午运维反馈说我们这一个pod一天重启了8次,需要排查下原因.一看Kiban日志,jvm没有抛出过任何错误,服务就直接重启了.显然是进程被直接杀了,初步判断是pod达到内存上限被K8s ...

  9. ActiveMQ RCE CVE-2023-46604分析

    一.漏洞触发点 org.apache.activemq.openwire.v12包下BaseDataStreamMarshaller类的createThrowable方法. package org.a ...

  10. django 定时任务 apscheduler 踩坑

    本想每天定点的去查询一些数据然后用钉钉机器人发出来,前两三天还好好的,后面就执行 ERROR了 看了下错误问题,就跟连不上数据库一样,参考别人的解决方法 scheduler.add_job(every ...