ABC 070 Atcoder
圧力の下でOK、RBIシミュレーションゲームは、下のステータスを調整しません
A
文字列が回文であるかどうかを決定します。
#define judge
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef judge
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
string s;
cin >> s;
int tag = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] != s[s.size() - i - 1]) {
tag = 1;
break;
}
}
if (tag) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
return 0;
}
B
与えられた二つの部分は、共通部分のサイズを決定し、共通区間の左端は、2つのセクションの左端の最大値に等しく、右部の右端が最小の二点に等しいです。
間隔は、空の出力が0であるべきです。
#define judge
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef judge
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << max(0, min(b, d) - max(a, c)) << endl;
return 0;
}
C
p和q最大公约数
* p和q的最小公倍数
= P * Q
いくつかの数字は、最小公倍数共通需要各アレイの最小公倍数に等しいです。
// #define judge
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 10;
int n;
ll gcd(ll a, ll b) {
if (b > a) swap(a, b);
while (b != 0) {
ll r = b;
b = a % b;
a = r;
}
return a;
}
ll low(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
#ifndef judge
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin >> n;
ll x = 1, y;
for (int i = 0; i < n; i++) {
cin >> y;
x = low(x, y);
}
cout << x << endl;
return 0;
}
D
問題の意味:ノードのツリーが与えられると、指定されたノードk、bは、クエリq、最小距離Bに到達からの問合せがあります。
解像度:重みはで行うには非負、最短経路問題、あるk
始点dijsktraとして。dist[a]+dist[j]
答えがあります。
注:可能な限りのように、より大きなアレイを開くために、何点は、このように、グラフの辺の2倍の数ではない\(2 * MAXN \) 。
#define judge
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
static int faster_iostream = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
return 0;
}();
ll q, a, b, c, x, y, k;
const int maxn = 5e5 + 10;
int n, m;
ll h[maxn], w[maxn * 2], e[maxn], ne[maxn * 2], idx;
ll dist[maxn];
bool used[maxn];
void init() {
memset(h, -1, sizeof h);
idx = 0;
}
void add(int a, int b, int c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dij(int k) {
memset(dist, 0x3f, sizeof dist);
dist[k] = 0;
priority_queue<PII, vector<PII>, greater<PII>> heap;
heap.push(make_pair(0, k));
while (heap.size()) {
PII t = heap.top();
heap.pop();
ll ver = t.second, distance = t.first;
if (used[ver]) continue;
used[ver] = true;
for (int i = h[ver]; i != -1; i = ne[i]) {
ll j = e[i];
if (dist[j] > distance + w[i]) {
dist[j] = distance + w[i];
heap.push(make_pair(dist[j], j));
}
}
}
}
int main() {
#ifndef judge
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin >> n;
init();
for (int i = 0; i < n - 1; i++) {
cin >> a >> b >> c;
add(a, b, c);
add(b, a, c);
}
cin >> q >> k;
dij(k);
while (q--) {
cin >> x >> y;
cout << dist[x] + dist[y] << endl;
}
return 0;
}