补题:Codeforces Round #590 (Div. 3)

比赛入口

C Pipes

做法:当时一直在想有哪些特殊情况才会输出NO,其实只需要跟着水模拟着走下去就好了…哭唧唧…

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
string s[2];
int main() {
  fio
  int t; cin >> t;
  int n, k, i;
  while(t--) {
    cin >> n >> s[0] >> s[1];
    k = i = 0;
    for( ; i < n; ++i) {
      if(s[k][i] > '2') {
        k ^= 1;
        if(s[k][i] < '3') break;
      }
    }
    if(i == n && k == 1) puts("YES");
    else puts("NO");
  }
  return 0;
}

E Special Permutations

做法:看做法像是差分+前缀和??嗯…(雾)…处理结果数组,看最后的值影响到哪几个答案,依次把答案更新…妙啊妙啊

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int N = 2e5+5;
LL a[N], f[N];
int main() {
  int n, m;
  read(n); read(m);
  for(int i = 1; i <= m; ++i) read(a[i]);
  for(int i = 1; i < m; ++i) {
    if(a[i] == a[i+1]) continue;
    int x = a[i], y = a[i+1], di = fabs(x-y);
    if(x > y) swap(x, y);
    f[1] += di; f[x] -= di;
    f[x] += y - 1; f[x+1] -= y - 1;
    f[x+1] += di - 1; f[y] -= di - 1;
    f[y] += x; f[y+1] -= x;
    f[y+1] += di;
  }
  for(int i = 1; i <= n; ++i) {
    f[i] += f[i-1];
    cout << f[i] << " ";
  }
  cout << endl;
  return 0;
}


发布了28 篇原创文章 · 获赞 14 · 访问量 2953

猜你喜欢

转载自blog.csdn.net/qq_43408978/article/details/104083157