Atcoder ABC 070

Atcoder ABC 070

ABC

Under pressure not OK, RBI simulation game to adjust status under

A

Determining whether a string is a palindrome.

#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

Given two sections, determine the size of the common section, the left end of the common interval equal to the maximum value of the left end of the two sections, the right end of the right section equal to the minimum two points.
Interval is empty output should be 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

Some numbers equal to the least common multiple common demand the least common multiple of each array:

// #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

The meaning of problems: Given a tree, and a specified node k, and b for a node, there is a query q, a query from reaching the minimum distance b.
Resolution: The weights are non-negative, shortest path problem, to do with kas a starting point dijsktra. dist[a]+dist[j]Is the answer.

Note: as far as possible to open the larger array, no points is 2 times the number of edges of the graph, thus \ (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;
}

Guess you like

Origin www.cnblogs.com/adameta/p/12315617.html