2019 ICPC Asia-East Continent Final(A,M)题解

简介: 2019 ICPC Asia-East Continent Final(A,M)题解

A.

题意就是输入n,m,代表行含n格,列含m格,让我们在这个网格里面找线段,要求线段中点是交叉点;求有几个线段。


题解;


我们可以分析知道,把每一行每一列的含有合法的线段找出来,然后找出类似2*2,4*4的正方形的所有个数*2;


全部加起来就是答案。

#include <bits/stdc++.h>
using namespace std;
long long sum = 0, sum1 = 0, sum2 = 0;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 2; i <= n; i += 2) {
    sum += n + 1 - i;
  }
  for (int i = 2; i <= m; i += 2) {
    sum1 += m + 1 - i;
  }
  sum2 += sum * (m + 1) + sum1 * (n + 1);
  for (int i = 1; i <= n; i++) {
    sum2 += sum1 * (i / 2) * 2;
  }
  cout << sum2 << endl;
}


M.


题意就是给出a排列,b排列,我们的结果序列可以加ai,但是如果i>2,j>2;i^k=j,我们的结果就要减bj,求结果最大化。


我们可以用2,3,5……的的K次方来搞在每一个里面找到最大的数,然后加起来。


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 7;
long long a[maxn], b[maxn], vis[maxn] = {0}, c[maxn], d[maxn];
int pd(int x, int  y) {
  for (ll i = x; i <= y; i *= x) {
    if (i == y) {
      return 1;
    }
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  long long sum1 = 0;
  ll maxn;
  sum1 = a[1];
  for (int i = 2; i <= n; i++) {
    long long add = 0;
    maxn = 0;
    if (!vis[i]) {
      for (ll j = i; j <= n; j *= i) {
        c[add++] = j;
        vis[j] = 1;
      }
      for (int g = 0; g < (1 << add); g++) {
        ll add1 = 0;
        long long sum = 0;
        for (int h = 0; h < add; h++) {
          if (g & (1 << h)) {
            sum += a[c[h]];
            d[add1++] = c[h];
          }
        }
        for (int i = 0; i < add1; i++) {
          for (int j = 0; j < add1; j++) {
            if (d[i] < d[j] && pd(d[i], d[j])) {
              sum -= b[d[j]];
            }
          }
        }
        maxn = max(maxn, sum);
      }
    }
    sum1 += maxn;
  }
  cout << sum1 << endl;
}


相关文章
|
7月前
ZZULIOJ----2618: ACM-ICPC亚洲区域赛ZZUL
ZZULIOJ----2618: ACM-ICPC亚洲区域赛ZZUL
|
人工智能 C++
【PAT甲级 - C++题解】1136 A Delayed Palin
【PAT甲级 - C++题解】1136 A Delayed Palin
83 0
luogu CF776D The Door Problem(2-sat问题)
luogu CF776D The Door Problem(2-sat问题)
65 0
|
机器学习/深度学习 人工智能
The Preliminary Contest for ICPC China Nanchang National Invitational I题 Max answer
The Preliminary Contest for ICPC China Nanchang National Invitational I题 Max answer
94 0
The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence
The Preliminary Contest for ICPC China Nanchang National Invitational M题 Subsequence
78 0
(数学)(必要解题步骤)2021icpc上海D. Strange Fractions
(数学)(必要解题步骤)2021icpc上海D. Strange Fractions
81 0
|
机器学习/深度学习 BI
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
134 0
2020-2021 ACM-ICPC, Asia Seoul Regional Contest L. Two Buildings (决策单调性 分治)
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
91 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
2020 ICPC Asia Taipei-Hsinchu Site Programming Contest H. Optimization for UltraNet (二分+最小生成树+算贡献)
2020 ICPC Asia Taipei-Hsinchu Site Programming Contest H. Optimization for UltraNet (二分+最小生成树+算贡献)
126 0