# 2022牛客暑期多校训练营6（ABGIJM）

37 篇文章 1 订阅

### A Array

##### 代码
#include <bits/stdc++.h>

using namespace std;

int ans[1000006];

int main()
{
int n, mxg = 0;
pair<int, int> g[100005];
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", &g[i].first), g[i].second = i, mxg = max(mxg, g[i].first);
sort(g + 1, g + n + 1);
int c = 1;
for (int i = 1; i <= n; i++)
{
int j=c;
while(ans[j])j++,c++;
for (; j <= 2*mxg; j += g[i].first)
{
while(ans[j])j--;
ans[j] = g[i].second;
}
if(j-2*mxg<c)
{
while(j>2*mxg||ans[j])j--;
ans[j] = g[i].second;
}
c++;
}
printf("%d\n", 2*mxg);
for (int i = 1; i <= 2*mxg; i++)
printf("%d ", (ans[i])?ans[i]:1);
return 0;
}


### B Eezie and Pie

##### 代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> rod[2000006];
ll ans[2000006], d[2000006];
vector<pair<int, int>> tmp;//这里的.first实际上无意义

void dfs(int x, int f)
{
tmp.push_back({x, 1});
if ((int)tmp.size() - 1 - d[x] - 1 >= 0)
tmp[(int)tmp.size() - 1 - d[x] - 1].second--;

for (auto u : rod[x])
{
if (u == f)
continue;
dfs(u, x);
}

ans[x] = tmp[tmp.size() - 1].second;
if (tmp.size() > 1)
{
tmp[tmp.size() - 2].second += tmp[tmp.size() - 1].second;
}
tmp.pop_back();
}
int main()
{
int n, u, v;
cin >> n;
for (int i = 1; i < n; i++)
{
scanf("%d%d", &u, &v);
rod[u].push_back(v);
rod[v].push_back(u);
}
for (int i = 1; i <= n; i++)
{
scanf("%lld", &d[i]);
}
// tmp.push_back({0,0});
dfs(1, 0);
for (int i = 1; i <= n; i++)
{
printf("%lld ", ans[i]);
}
return 0;
}



### G Icon Design

##### 代码

#include <iostream>
#include <set>
using namespace std;

int main() {
int n;
cin >> n;

set<pair<int, int>> s;

// N

int L = n + 1, U = n;

for (int i = 1; i <= 2 * n + 3; i++) {
s.insert({L + i, U + i});
s.insert({L + 1, U + i});
s.insert({L + 2 * n + 3, U + i});
}

// F

L += 2 * n + 3 + n + 1;

for (int i = 1; i <= 2 * n + 3; i++) {
s.insert({L + 1, U + i});
s.insert({L + i, U + 1});
s.insert({L + i, U + n + 2});
}

// L

L += 2 * n + 3 + n + 1;

for (int i = 1; i <= 2 * n + 3; i++) {
s.insert({L + 1, U + i});
s.insert({L + i, U + 2 * n + 3});
}

// S
L += 2 * n + 3 + n + 1;

for (int i = 1; i <= 2 * n + 3; i++) {
s.insert({L + i, U + 1});
s.insert({L + i, U + n + 2});
s.insert({L + i, U + 2 * n + 3});
if (i <= n + 2) {
s.insert({L + 1, U + i});
}
if (i >= n + 2) {
s.insert({L + 2 * n + 3, U + i});
}
}

for (int i = 0; i < 4 * n + 5; i++) {
for (int j = 0; j < 13 * n + 19; j++) {
if (i == 0 || j == 0 || i == 4 * n + 5 - 1 ||
j == 13 * n + 19 - 1) {
cout << '*';
} else if (s.find({j, i}) != s.end()) {
cout << "@";
} else {
cout << ".";
}
}
cout << '\n';
}

return 0;
}


### I Line

##### 代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<ll, ll> vv[10];
vector<pair<pair<ll, ll>, int>> pp;
vector<pair<ll, ll>> p;
bool operator==(pair<pair<ll, ll>, int> a, pair<pair<ll, ll>, int> b)
{
return a.first.first == b.first.first && a.first.second == b.first.second;
}
int main()
{
int n, u, v, d;
cin >> n >> d;
for (int i = 0; i < n; i++)
{
scanf("%lld%lld", &vv[i].first, &vv[i].second);
if (vv[i].first * vv[i].second)
{
int g = __gcd(abs(vv[i].first), abs(vv[i].second));
vv[i].first /= g;
vv[i].second /= g;
}
else
{
if (vv[i].first + vv[i].second)
{
if (vv[i].second)
vv[i] = {0, 1};
else if (vv[i].first)
vv[i] = {1, 0};
}
}
}
sort(vv, vv + n);
n = unique(vv, vv + n) - vv;
pp.push_back({{0, 0}, -1});
ll bas = 1;
for (int i = 0; i < n; i++, bas *= 37)
{
for (int k = 0; k < pp.size(); k++)
{
if (pp[k].second == i)
break;
auto tt = pp[k].first;
for (int j = 2; j <= d; j++)
{
pp.push_back(
{{tt.first + vv[i].first * bas * j, tt.second + vv[i].second * bas * j}, i});
}
}
}

printf("%d\n", pp.size());
for (auto i : pp)
printf("%lld %lld\n", (i.first), (i.second));
return 0;
}


### J Number Game

##### 思路

( − 1 ) k + 1 k + 1 2 A + ( − 1 ) k k B + ( − 1 ) k C ( − 1 ) k k 2 A + ( − 1 ) k + 1 k B + ( − 1 ) k C (-1)^{k+1}\frac {k+1}2A+(-1)^kkB+(-1)^kC\\ (-1)^{k}\frac {k}2A+(-1)^{k+1}kB+(-1)^kC

##### 代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e4;
const ll M = 1e9 + 7;
typedef struct
{
int x, y, z;
} ppp;
int main()
{
ll t, a, b, c, x;
cin >> t;
while (t--)
{
cin >> a >> b >> c >> x;
if (c == x)
{
printf("Yes\n");
continue;
}
if (2 * b - a)
{
if ((x + c + b - a) % (a - 2 * b) == 0 && (x + c + b - a) / (a - 2 * b) >= 0)
{
printf("Yes\n");
continue;
}
if ((x + c - b) % (2 * b - a) == 0 && (x + c - b) / (2 * b - a) >= 0)
{
printf("Yes\n");
continue;
}
if ((x - c) % (2 * b - a) == 0 && (x - c) / (2 * b - a) >= 0)
{
printf("Yes\n");
continue;
}
if ((x - c) % (a - 2 * b) == 0 && (x - c) / (a - 2 * b) >= 0)
{
printf("Yes\n");
continue;
}
printf("No\n");
continue;
}
else if (a - b - c == x || b - c == x)
{
printf("Yes\n");
continue;
}
else
{
printf("No\n");
continue;
}
}
}



### M Game on grid

DP

##### 思路

d p [ i ] [ j ] = { c h e c k ( m p [ i ] [ j ] )   m p [ i ] [ j ] ! = . max ⁡ ( d p [ i + 1 ] [ j ] , d p [ i ] [ j + 1 ] )   ( i + j ) % 2 = = 0 min ⁡ ( d p [ i + 1 ] [ j ] , d p [ i ] [ j + 1 ] )   ( i + j ) % 2 = = 1 dp[i][j]=\begin{cases} check(mp[i][j])\ mp[i][j]!=.\\ \max(dp[i+1][j],dp[i][j+1])\ (i+j)\%2==0\\ \min(dp[i+1][j],dp[i][j+1])\ (i+j)\%2==1\\ \end{cases}

##### 代码

#include <bits/stdc++.h>
using namespace std;
const int N = 502;

int dp[N][N], n, m;
char s[N][N];

void solve()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s", s[i]);

auto dpf = [&](auto ck, int final = 1)
{
for (int i = n - 1; i >= 0; i--)
{
for (int j = m - 1; j >= 0; j--)
{
dp[i][j] = ck(i, j);
if (dp[i][j] != 0)
continue;
if (i == n - 1 && j == m - 1)
continue;
vector<int> nxt;
if (i < n - 1)
nxt.push_back(dp[i + 1][j]);
if (j < m - 1)
nxt.push_back(dp[i][j + 1]);
if ((i + j) % 2 == 0)
{
dp[i][j] = *max_element(nxt.begin(), nxt.end());
}
else
{
dp[i][j] = *min_element(nxt.begin(), nxt.end());
}
}
}
return dp[0][0] == final;
};

if (dpf(
[](int i, int j) -> int
{
if (s[i][j] == 'B')
return -1;
return s[i][j] == 'A';
}))
printf("yes ");
else
printf("no ");

if (dpf([](int i, int j) -> int { return s[i][j] == '.' ? 0 : -1; }, 0))
printf("yes ");
else
printf("no ");

if (dpf(
[](int i, int j) -> int
{
if (s[i][j] == 'A')
return -1;
return s[i][j] == 'B';
}))
puts("yes");
else
puts("no");
}

int main()
{
int T;
scanf("%d", &T);
while (T--)
{
solve();
}
}

• 3
点赞
• 0
收藏
觉得还不错? 一键收藏
• 3
评论
09-21 502
08-08 381
08-04 379
08-06 955

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。