A. Pupils Redistribution
https://codeforces.com/contest/779/problem/A
题意就是把数字1到5平均分到两个班内,题水但是判定容易出BUG
#include<bits/stdc++.h>
using namespace std;
constexpr int maxl = 6;
int numa[maxl], numb[maxl];
int main()
{
int n;
cin >> n;
for(int i = 0;i < n; i++)
{
int a;
cin >> a;
numa[a]++;
}
for(int i = 0; i < n; i++)
{
int b;
cin >> b;
numb[b]++;
}
int sum = 0;
int flag = 0;
for(int i = 1; i <= 5; i++)
{
sum += abs(numa[i] - numb[i]);
if(abs(numa[i] - numb[i]) % 2 == 1) flag = 1;
}
if(sum % 4 != 0 || flag)
cout << -1 << endl;
else
cout << sum / 4 << endl;
return 0;
}
B. Weird Rounding
https://codeforces.com/contest/779/problem/B
这个就是从后往前找第k个0,水题
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 30;
char str[maxn];
int main()
{
int k;
scanf("%s %d", str, &k);
int n = strlen(str);
int num = 0, vim = 0, flag = 0;
for(int i = n - 1; i >= 0; i--)
{
if(str[i] == '0')
vim++;
num++;
if(vim == k && num != n)
{
flag = 1;
break;
}
}
if(flag)
cout << num - vim << endl;
else
{
cout << n - 1 << endl;
}
return 0;
}
C. Dishonest Sellers
https://codeforces.com/contest/779/problem/C
一道阅读理解模拟水题
#include<algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SZ(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define devil ios::sync_with_stdio(false)
#define cim constexpr int maxn =
#define PAUSE system("pause")
const int inf = 0x3f3f3f3f;
using namespace std;
//head
constexpr int maxn = 2e5 + 5;
struct Node {
int a, b, vim;
}node[maxn];
bool cmp(Node x, Node y)
{
return x.vim < y.vim;
}
int main()
{
int sum = 0;
int num = 0;
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
{
scanf("%d", &node[i].a);
}
for (int i = 1; i <= n; i++)
{
scanf("%d", &node[i].b);
node[i].vim = node[i].a - node[i].b;
}
for (int i = 1; i <= n; i++)
{
if (node[i].vim < 0)
{
num++;
sum += node[i].a;
node[i].vim = inf;
}
}
sort(node + 1, node + 1 + n, cmp);
n -= num;
k -= num;
num = 1;
while (k > 0)
{
//cout << -111 << endl;
sum += node[num++].a;
//cout << node[num - 1].a;
k--;
n--;
}
while(n > 0)
{
//cout << -222 << endl;
sum += node[num++].b;
//cout << node[num - 1].b;
n--;
}
cout << sum << endl;
return 0;
}
D. String Game
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word p can be obtained by removing the letters from word t.
Input
The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.
Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, all ai are distinct).
Output
Print a single integer number, the maximum number of letters that Nastya can remove.
Examples
input
Copy
ababcba abb 5 3 4 1 7 6 2
output
Copy
3
input
Copy
bbbabb bb 1 6 3 4 2 5
output
Copy
4
https://codeforces.com/contest/779/problem/D
这题我没想出来,看了网上的题解后发现这个就是二分中的暴力题
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 2e5 + 6;
string str1, str2, str;
int n;
int a[maxn];
bool ok()
{
int n = str2.length();
int num = 0;
int L = str.length();
for(int i = 0; i < L; i++)
{
if(str2[num] == str[i])
num++;
}
if(num == n)
return true;
return false;
}
int main()
{
cin >> str1 >> str2;
n = str1.length();
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
int l = 0, r = n - 1;
while(l <= r)
{
int m = (l + r) >> 1;
str = str1;
for(int i = 0; i <= m; i++)
{
str[a[i] - 1] = '*';
}
if(ok())
{
l = m + 1;
}
else
r = m - 1;
}
cout << l << endl;
return 0;
}