标签:The %s amp 通过 ring 区间 前缀和 ace math
#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\n");
continue;
}
if(n%2)
printf("%d\n", n/2);
else
printf("%d\n", n/2 - 1);
}
return 0;
}
#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("\n");
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] = ‘\0‘;
printf("%s\n", ar + 1);
}
return 0;
}
题意: 给我们一个有个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\n", ans);
init(mx);
}
return 0;
}
#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;
}
题意:给我一个长度为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\n", 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\n", l, r, mx); */
ans = max(ans, (j + 1) * 2 + mx);
}
/* printf("\n"); */
}
printf("%d\n", ans);
}
return 0;
}
Codeforces Round #634 (Div. 3)
标签:The %s amp 通过 ring 区间 前缀和 ace math
原文地址:https://www.cnblogs.com/lql-nyist/p/12775817.html