Codeforces Round #634 (Div. 3)
Posted lql-nyist
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #634 (Div. 3)相关的知识,希望对你有一定的参考价值。
A. Candies and Two Sisters(水题)
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
using namespace std;
void fre() { freopen("A.txt","r",stdin); freopen("Ans.txt","w",stdout); }
#define ll long long
#define INF 0x3f3f3f3f
const int mxn = 105;
int main()
{
/* fre(); */
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n);
if(n == 1)
{
printf("0
");
continue;
}
if(n%2)
printf("%d
", n/2);
else
printf("%d
", n/2 - 1);
}
return 0;
}
B. Construct the String(简单构造)
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
using namespace std;
void fre() { freopen("A.txt","r",stdin); freopen("Ans.txt","w",stdout); }
#define ll long long
#define INF 0x3f3f3f3f
const int mxn = 20005;
char ar[mxn];
int main()
{
/* fre(); */
int t;
scanf("%d", &t);
while(t --)
{
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
if(b == 1)
{
for(int i = 1; i <= n; i ++)
printf("a");
printf("
");
continue;
}
for(int i = 1; i <= b; i ++)
ar[i] = ‘a‘ + i - 1;
for(int i = b + 1; i <= a; i ++)
ar[i] = ‘a‘ - 1 + b;
int p = 1;
for(int i = a + 1; i <= n; i ++)
{
ar[i] = ar[p ++];
}
ar[n + 1] = ‘ ‘;
printf("%s
", ar + 1);
}
return 0;
}
C. Two Teams Composing(简单构造)
题意
-
题意: 给我们一个有个n数的序列我们要从这个序列中找出一些元素,然后把这些元素分成元素数量相同的两组(设为数量为k),位于第一组中的元素要各不相同,位于第二组中的元素要完全相同,在满足要求的情况下 k 最大为多少?
-
思路:首先我们统计每个值出现的次数,那么我们找到出现次数最多那个数,我们可以判读位于第二组的数,一定都是出现次数最多的那个,那么我们只需要同二分枚举这个数的位于第二组的数量,然后用judge函数判断第一组元素是否都能凑出来就行了
思路
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
using namespace std;
void fre() { freopen("A.txt","r",stdin); freopen("Ans.txt","w",stdout); }
#define ll long long
#define INF 0x3f3f3f3f
const int mxn = 1e6;
int ar[mxn];
int bar[mxn];
bool judge(int num)
{
int cnt = 0;
int i;
for(i = 1; bar[i]; i ++)
{
//
}
cnt = i - 1;
if(num != bar[0])
cnt ++;
return cnt >= num;
}
void init(int n)
{
for(int i = 0; i <= n; i ++)
bar[i] = 0;
}
int main()
{
/* fre(); */
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n);
int mx = -1;
for(int i = 1; i <= n; i ++)
{
scanf("%d", &ar[i]);
mx = max(mx, ar[i]);
bar[ar[i]] ++;
}
sort(bar, bar + mx + 1, greater<int>());
int l = 1, r = bar[0];
int ans = 0;
while(l <= r)
{
int mid = (l + r) >> 1;
if(judge(mid))
{
l = mid + 1;
ans = mid;
}
else
r = mid - 1;
}
printf("%d
", ans);
init(mx);
}
return 0;
}
D. Anti-Sudoku(水题)
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
for (int i = 0; i < 9; ++i) {
string s;
cin >> s;
for (auto &c : s) if (c == ‘1‘) c = ‘2‘;
cout << s << endl;
}
}
return 0;
}
E2. Three Blocks Palindrome (hard version)(暴力枚举)
思路
-
题意:给我一个长度为n的序列,让我们从中找一个子序列这个子序列的元素形式为「a a a b b b a a a」或着「a」或者「a a a」,问我们能找到行如上式的序列最长的是多少?
-
思路:暴力枚举,首先预处理储存每一个数的位置,然后在用前缀和预处理某个区间段内的某个数的数量,我们枚举左边a的数量,那么右边a的数量也就确定下来了,在通过之前的预处理确定中间段的界限出现最多的那个数字数量,最后一点点枚举就行了
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<queue>
using namespace std;
void fre() { freopen("A.txt","r",stdin); freopen("Ans.txt","w",stdout); }
#define ll long long
#define INF 0x3f3f3f3f
const int mxn = 2e5 + 10;
int ar[mxn];
int br[mxn][205];
vector<int> pos[205];
void init(int n)
{
for(int i = 0; i <= 205; i ++)
pos[i].clear();
for(int i = 0; i <= n; i ++)
memset(br[i], 0, sizeof(br[i]));
}
int main()
{
/* fre(); */
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n);
init(n);
for(int i = 1; i <= n; i ++)
{
scanf("%d", &ar[i]);
for(int j = 0; j <= 200; j ++)
br[i][j] = br[i - 1][j];
br[i][ar[i]] ++;
pos[ar[i]].push_back(i);
}
int ans = 1;
for(int i = 1; i <= 200; i ++)
{
if(pos[i].size() <= 1) continue;
/* printf("%d
", i); */
for(int j = 0; j < pos[i].size()/2; j ++)
{
int l = pos[i][j], r = pos[i][pos[i].size() - j - 1];
int mx = 0;
for(int k = 0; k <= 200; k ++)
mx = max(mx, br[r-1][k] - br[l][k]);
/* printf("%d %d mx = %d
", l, r, mx); */
ans = max(ans, (j + 1) * 2 + mx);
}
/* printf("
"); */
}
printf("%d
", ans);
}
return 0;
}
以上是关于Codeforces Round #634 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #634 (Div. 3)
Codeforces Round #634 (Div. 3)
Codeforces Round #634 D. Anti-Sudoku(构造/水)
Codeforces Round #436 E. Fire(背包dp+输出路径)