牛客周赛 Round 67
比赛链接
牛客周赛 Round 67
A题
代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 3e5 + 5, M = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n;
string s;
void solve()
{
cin >> n >> s;
string str = "";
for (char c : s)
{
if (c >= 'a' && c <= 'z')
str.push_back(c);
}
for (char c : s)
{
if (c >= '0' && c <= '9')
str.push_back(c);
}
for (char c : s)
{
if (c >= 'A' && c <= 'Z')
str.push_back(c);
}
cout << str << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int test = 1;
// cin >> test;
for (int i = 1; i <= test; i++)
{
solve();
}
return 0;
}
B题
思路
非常明显的二分,注意此题会爆longlong,所以我这里使用了python。
代码
n = int(input())
for i in range(n):
a,b,c,d = map(int,input().split(' '))
low = 0
high = int(1e18)
while low < high:
mid = (low + high + 1) // 2;
if mid * d < b * c:
low = mid
else:
high = mid - 1
print(a - low,end=' ')
print()
C题
思路
暴力枚举 A A A和 B B B的值即可。
代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 3e5 + 5, M = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n, c, num, len;
string s1, s2, str;
string func(int x)
{
if (x == 0) return "0";
str = "";
while (x)
{
char c = (x % 10) + '0';
x /= 10;
str.push_back(c);
}
reverse(str.begin(), str.end());
return str;
}
bool check(int x)
{
int y = c - x;
s1 = func(x), s2 = func(y);
return (int)(s1.size() + s2.size() + len + 2) == n;
}
void solve()
{
cin >> n >> c;
num = c;
while (num)
{
len++;
num /= 10;
}
int ans = 0;
for (int i = 0; i <= c; i++)
{
if (check(i))
{
ans++;
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int test = 1;
// cin >> test;
for (int i = 1; i <= test; i++)
{
solve();
}
return 0;
}
D题
思路
从 0 0 0到 n + 1 − k n+1-k n+1−k不断循环填充即可。
代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 3e5 + 5, M = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n, k;
void solve()
{
cin >> n >> k;
if (k > n)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
int op = n + 1 - k;
for (int i = 1; i <= n; i++)
{
cout << (i % op) << " ";
}
cout << endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int test = 1;
// cin >> test;
for (int i = 1; i <= test; i++)
{
solve();
}
return 0;
}
E题
思路
令 l o w = l 1 + l 2 low = l1+l2 low=l1+l2,令 h i g h = r 1 + r 2 high = r1+r2 high=r1+r2,答案就是 [ l o w , h i g h ] [low,high] [low,high]里数位和的最大值。假设当前 h i g h high high数位上的值 o p 1 op1 op1比 l o w low low上的 o p 2 op2 op2大时,我们可以取 o p 1 − 1 op1-1 op1−1,后面全部取 9 9 9。我们通过不断枚举 h i g h high high的最高几位,不断贪心即可。
代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 3e5 + 5, M = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int l, r, L, R;
void solve()
{
cin >> l >> r >> L >> R;
int low = l + L, high = r + R;
vector<int>a, b;
while (low || high)
{
a.push_back(low % 10);
b.push_back(high % 10);
low /= 10, high /= 10;
}
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int n = a.size();
bool ok = false;
int ans = 0, res = 0;
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
{
ans = max({ans, res + b[i] - 1 + (n - i - 1) * 9, res + b[i]});
}
else
{
ans = max(ans, res + b[i]);
}
res += b[i];
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int test = 1;
cin >> test;
for (int i = 1; i <= test; i++)
{
solve();
}
return 0;
}
F题
思路
赛时没做出来,过两天补上…