Skip to content

Commit

Permalink
add ACM
Browse files Browse the repository at this point in the history
  • Loading branch information
devilran6 committed Oct 3, 2023
1 parent 99c0e00 commit faf73ff
Show file tree
Hide file tree
Showing 11 changed files with 2,082 additions and 6 deletions.
1,059 changes: 1,059 additions & 0 deletions docs/ACM/CF/div2_892.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docs/ACM/CF/div2_893.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: CFdiv2_893
description: (ABCDEF)
categories:
- CF
highlight_shrink: false
abbrlink: 7fd84b65
date: 2023-08-18 00:00:00
mathjax: true
copyright_author: devilran
copyright_author_href:
copyright_url:
copyright_info:
---
314 changes: 314 additions & 0 deletions docs/ACM/CF/div2_899.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
---
title: CFdiv2_899
description: (ABCDEF)
categories:
- CF
highlight_shrink: false
abbrlink: 9f0da27b
date: 2023-09-25 00:00:00
mathjax: true
copyright_author: devilran
copyright_author_href:
copyright_url:
copyright_info:
---





赛时写了ABCD,但C题卡了太久,b题其实完全暴力就可以,但是想歪了,最后也没时间重新写了,过了ACD



## A



### 题目



You are given a sequence $a_{1}, a_{2}, \ldots, a_{n}$. A sequence $b_{1}, b_{2}, \ldots, b_{n}$ is called good, if it satisfies all of the following conditions:

- $b_{i}$ is a positive integer for $i = 1, 2, \ldots, n$;
- $b_{i} \neq a_{i}$ for $i = 1, 2, \ldots, n$;
- $b_{1} \lt\; b_{2} \lt\; \ldots \lt\; b_{n}$.

Find the minimum value of $b_{n}$ among all good sequences $b_{1}, b_{2}, \ldots, b_{n}$.



给定a序列,求满足条件的最小$b_n$



### 思路



n很小,直接从t=1开始对应到b就行,如果 $b_i$==$a_i$ , t ++;



### code



```cpp
#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define x first
#define y second
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 0x3f3f3f3f;

void solve()
{
int n;
cin >> n;

vector<LL> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}

LL ans = 0, now = 1;
for (int i = 1; i <= n; i++)
{
if (now == a[i])
now++;
ans += now;
now++;
}

now--;
cout << now << endl;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

int t = 1;
cin >> t;

while (t--)
{
solve();
}

return 0;
}
```



## B

这道题n很小,其实直接暴力就可以,根本不需要思考方

### 题目

给定n个集合$S_i$, 记所有集合的并集为$S_{all}$, 求从中选取一些集合,这些集合的并集的元素数量需要严格小于$S_{all}$,求选取出来的集合的并集的元素数量的最大值



### 思路

挨个枚举全集中的每个元素,当这个元素不存在的时候,我可以把哪些集合进行合并。之后合并完最大值就行



### code

```cpp
#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define x first
#define y second
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 0x3f3f3f3f;
const int N = 55;

set<int> mp[N], all;

void solve()
{
int n;
cin >> n;

all.clear();
for (int i = 1; i <= n; i++)
{
mp[i].clear();
int m;
cin >> m;

for (int j = 1; j <= m; j++)
{
int t;
cin >> t;
mp[i].insert(t);
all.insert(t);
}
}

int ans = 0;
for (auto t : all)
{
set<int> res;
for (int i = 1; i <= n; i++)
{
if (mp[i].find(t) != mp[i].end())
{
continue;
}

for (auto tt : mp[i])
{
res.insert(tt);
}
}

ans = max(ans, (int)res.size());
}

cout << ans << endl;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

int t;
cin >> t;

while (t--)
{
solve();
}

return 0;
}
```



## C



### 题目

有n张牌堆成一堆,每张牌上写了一个价值,有以下两个操作,求操作完可以获得的最大价值。任意时候都可以停止操作。(价值中存在负数,否则就全取完就好了)

操作 --- 从上向下数第几张

- 拿走第奇数张,之后获得这张牌上的价值
- 拿走第偶数张,之后直接将这张牌扔掉,并不获得这张牌的价值

注意,每次拿走一站牌后,所有牌的顺序会重新计算,奇偶性可能发生改变



### 思路



如果一定选取第i个元素

对于i后面的奇数位置的元素,可以倒着直接取完

对于i后面偶数位置的元素,可以取完i,之后后这些要取的元素,就变成奇数了

后缀和优化



所以枚举第一个要选取的元素即可

### code

```cpp
#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define x first
#define y second
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 0x3f3f3f3f;

void solve()
{
int n;
cin >> n;

vector<LL> a(n + 1), suf(n + 2);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}

suf[n + 1] = 0;
for (int i = n; i >= 1; i--)
{
suf[i] = suf[i + 1] + max(a[i], 0ll);
}

LL ans = 0;
for (int i = 1; i <= n; i++)
{
ans = max(ans, (i % 2 == 1) * a[i] + suf[i + 1]);
}

cout << ans << endl;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

int t;
cin >> t;

while (t--)
{
solve();
}

return 0;
}
```





Loading

0 comments on commit faf73ff

Please sign in to comment.