【2022neuoj刷题打卡】2591~2600

2591

点击查看代码
//Author:Fczhao
//Language:cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
vector<int> e[maxn];
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> dis(3 * n + 3);
  bitset<3 * maxn> vis;
  vis.reset(); 
  for(int i = 3; i < dis.size(); i++) dis[i] = inf;
  for(int i = 0; i < m; i++) {
    int u, v; cin >> u >> v;
    e[u].push_back(v);
  }
  int s, t; cin >> s >> t;
  dis[3 * s] = 0;
  vis[3 * s] = true;
  queue<int> Q;
  Q.push(3 * s);
  while(!Q.empty()) {
    int it = Q.front(); Q.pop();
    int now = it / 3, step = it - now * 3;
    for(int i = 0; i < e[now].size(); i++) {
      int to = e[now][i] * 3 + (step + 1) % 3;
      if(!vis[to]) {
        vis[to] = true;
        if(step == 2) dis[to] = dis[it] + 1;
        else dis[to] = dis[it];
        Q.push(to);
      }
    }
  }
  if(dis[3 * t] != inf) cout << dis[3 * t] << endl;
  else cout << -1 << endl;
  return 0;
}

2592

点击查看代码
//Author:Fczhao
//Language:cpp
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> x(n), y(n), h(n);
  int m = 0;
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]) m = i;
  }
  for(int i = 0; i <= 100; i++) 
    for(int j = 0; j <= 100; j++) {
      int ch = abs(i - x[m]) + abs(j - y[m]) + h[m];
      bool f = true;
      for(int a = 0; a < n; a++) {
        int th = max(0, ch - abs(i - x[a]) - abs(j - y[a]));
        if(th != h[a]) f = false;
      }
      if(f) {
        cout << i << " " << j << " " << ch << endl;
        return 0;
      }
    }
  return 0;
}

2593

不会 (这题难度定成3真的大丈夫?)

2594

点击查看代码
//Author:Fczhao
//Language:cpp
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int a[3];
  for(int i = 0; i < 3; i++) cin >> a[i];
  sort(a, a + 3);
  cout << a[2] - a[0] << endl;
  return 0;
}

2595

点击查看代码
//Author:Fczhao
//Language:cpp
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int n, m, ans = 0;
  cin >> n >> m;
  for(int i = 1; i * i <= m; i++) {
    if(m % i == 0) {
      int cnt = m / i;
      if(cnt >= n) ans = max(ans, i);
      if(i >= n) ans = max(ans, m / i);
    }
  }
  cout << ans << endl;
  return 0;
}

2596

点击查看代码
//Author:Fczhao
//Language:cpp
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  bool f = false;
  for(int i = 0; i < s.length(); i++) {
    if(t == (s.substr(i) + s.substr(0, i))) f = true;
  }
  cout << (f ? "Yes" : "No") << endl;
  return 0;
}

2597

点击查看代码
//Author:Fczhao
//Language:cpp
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int sum = 0;
  for(int i = 0; i < n; i++) sum += a[i];
  cout << sum - n << endl;
  return 0;
}

2598

点击查看代码
/*
 * @Author: Fczhao
 * @Language: cpp
 * @Date: 2022-02-25 16:03:34
 */
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  int ans = a * b;
  cout << (ans % 2 ? "Yes" : "No") << endl;
  return 0;
}

2599

点击查看代码
/*
 * @Author: Fczhao
 * @Language: cpp
 * @Date: 2022-02-25 16:06:16
 */
#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
};
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<node> a(m);
  for(int i = 0; i < m; i++) 
    cin >> a[i].l >> a[i].r;
  sort(a.begin(), a.end(), [](node &a, node &b) {
    if(a.r != b.r) return a.r < b.r;
    return a.l < b.l;
  });
  int last = 0, cnt = 0;
  for(int i = 0; i < m; i++) {
    if(last <= a[i].l) last = a[i].r, ++cnt;
//    cout << a[i].r << endl;
  }
  cout << cnt << endl;
  return 0;
}

2600

点击查看代码
/*
 * @Author: Fczhao
 * @Language: cpp
 * @Date: 2022-02-25 16:21:28
 */
#include <bits/stdc++.h>
using namespace std;
signed main(){
  #ifdef FCZHAO
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  int x; cin >> x;
  bool f = false;
  if(x == 7 || x == 5 || x == 3) f = true;
  cout << (f ? "YES" : "NO") << endl;
  return 0;
}

posted @ 2022-02-25 16:24  fczhao  阅读(81)  评论(0)    收藏  举报