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

比赛入口


B Equal Rectangles

做法:当时一直在想是不是和lcm有关,然后各种模拟判断(去世…)其实只有头和尾才能凑成一对…头和尾相乘和其他对相等的概率是最大的。

代码

#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;
}
int a[405];
int main() {
  int t; read(t);
  int n;
  while(t--) {
    read(n);
    for(int i = 0; i < 4*n; ++i) read(a[i]);
    sort(a, a+4*n);
    int f = 1, mid = a[0] * a[4*n-1];
    for(int i = 0; i < 4*n; i += 2) {
      if(a[i] * a[4*n-i-1] != mid || a[i] != a[i+1]) {
        f = 0; break;
      }
    }
    if(f) puts("YES");
    else puts("NO");
  }
  return 0;
}


D2 Remove the Substring (hard version)

做法:给出两个字符串,t字符串是s字符串删掉一些子串的结果,要求的是删掉子串中长度最长是多少。只需要记录最前面的位置和最后面的位置,再遍历一遍相减就好了…还是没想到呀…

代码

#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+10;
char s[N], t[N];
int ls, lt, p1[N], p2[N], ans;
int main() {
  scanf("%s%s", s+1, t+1);
  ls = strlen(s+1); lt = strlen(t+1);
  p1[0] = 0; p2[lt+1] = ls+1;
  for(int i = 1, j = 0; i <= ls; ++i) 
    s[i] == t[j+1] ? p1[++j] = i : 0;
  for(int i = ls, j = lt + 1; i; --i)
    s[i] == t[j-1] ? p2[--j] = i : 0;
  for(int i = 0; i <= lt; ++i) 
    ans = max(ans, p2[i+1] - p1[i] - 1);
  printf("%d\n", ans);
  return 0;
}

F2 Complete the Projects (hard version)

做法:最后一题应该是排序+dp了…


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

猜你喜欢

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