A
题意:给你一个字符串类似于a+b的,这里的a,b都是0~9的,算出a+b的结果。
思路:最开始没看范围,写的有点复杂了。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, m, k, _;
void solve()
{
string s;
cin >> s;
string s1 = "", s2 = "";
bool f = 1;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '+')
{
f = 0;
continue;
}
if (!f) s1 += s[i];
else s2 += s[i];
}
int a = s1[0] - '0';
int b = s2[0] - '0';
cout << a + b << endl;
}
signed main()
{
IOS;
cin >> _;
while (_--)
solve();
return 0;
}
B
题意:就是给你一个2*2的矩阵,每个数都互不相同发,是否满足每一行最右边的大于最左边,每一列最下边大于最上边。然后你可以对这个矩阵顺时针旋转90°,操作次数不限制,问最后得到的矩阵是否满足上述条件。
思路:
就是判断最大值在哪个位置,把这个最大值放在右下角,然后分别判断剩下三个数能不能满足大小关系
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, m, k, _;
void solve()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int ma = max({ a, b, c, d });
if (ma == a)
{
if (d < c && d < b) cout << "YES" << endl;
else cout << "NO" << endl;
}
if (ma == b)
{
if (c < a && c < d) cout << "YES" << endl;
else cout << "NO" << endl;
}
if (ma == c)
{
if (b < d && b < a) cout << "YES" << endl;
else cout << "NO" << endl;
}
if (ma == d)
{
if (a < b && a < c) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
signed main()
{
IOS;
cin >> _;
while (_--)
solve();
return 0;
}
C
题意:就是给你一个k,n,问你能不能找到一个长度为k,并且互不相同,最大值不能超过n的递增序列,并且使得这个序列中的 ( a i − a i − 1 ) (a_i-a_{i-1}) (ai−ai−1)值的种类最多。
思路:就是根据这个差值为1,2…去构造,第一个数一定是1, 第二个数该是2,第三个数该是4,第四个数该是7…,这么的话我们还面临着最大值为n的这个限制,所以我们每次取值的时候就要看一下,当前这个值填了过后,我们后面还能填的数的个数,如果不能满足后面的数,那我们再之前的每次加1就是了。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, m, k, _;
void solve()
{
cin >> k >> n;
int g = 1, tmp = 1;
cout << 1 << " ";
for (int i = 2; i <= k; i++)
{
int t = tmp + g;
if (n - t >= k - i)
{
cout << t << " ";
g++;
tmp = t;
}
else
{
cout << ++tmp << " ";
}
}
cout << endl;
}
signed main()
{
IOS;
cin >> _;
while (_--)
solve();
return 0;
}
D
题意:给你一个序列,你是否能找到一个x值,使得 a i = a b s ( a i − x ) a_i = abs(a_i-x) ai=abs(ai−x),每一个值这样操作过后原序列变成一个不递减的序列。
思路:我们假定
x
∈
[
l
,
r
]
x \in [l,r]
x∈[l,r],如果
a
i
<
a
i
+
1
a_i < a_i+1
ai<ai+1,因为我们要使得
a
b
s
(
a
i
−
x
)
<
a
b
s
(
a
i
+
1
−
x
)
abs(a_i-x) < abs(a_{i+1}-x)
abs(ai−x)<abs(ai+1−x),那么我们的
r
≤
m
i
n
(
r
,
(
1
+
a
i
+
a
i
+
1
)
/
2
)
r \le min(r, (1+a_i+a_{i+1})/2)
r≤min(r,(1+ai+ai+1)/2);可以使用反证法证明的。
同理:如果
a
i
>
a
i
+
1
a_i > a_i+1
ai>ai+1,
l
≥
m
a
x
(
l
,
(
a
i
+
a
i
+
1
)
/
2
)
l \ge max(l, (a_i+a_{i+1})/2 \ )
l≥max(l,(ai+ai+1)/2 )
最后我们只需要判断
l
≤
r
l \le r
l≤r即可;
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#define int long long
using namespace std;
const int N = 2e5 + 10, INF = 0x3f3f3f3f3f;
int n, m, k, _;
int arr[N];
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
int l = 0, r = INF;
for (int i = 2; i <= n; i++)
{
int x = 0, y = INF;
if (arr[i] > arr[i - 1]) y = (arr[i] + arr[i - 1]) / 2;
else if (arr[i] < arr[i - 1]) x = (arr[i] + arr[i - 1] + 1) / 2;
l = max(l, x), r = min(r, y);
}
if (l > r) cout << -1 << endl;
else cout << l << endl;
}
signed main()
{
IOS;
cin >> _;
while (_--)
solve();
return 0;
}
E
题意:给你一个序列最开始他们都为红色,现在你们两个人可以做三种操作:
1.可以改变蓝色数子之间的顺序,红色数字不能动
2.将一个红色数字变成蓝色数字
3.跳过不做操作
你们两个人轮流进行,入过这个序列变成升序第一个人赢得比赛,如果是降序第二个人赢得比赛,如果已知僵持不下平局。
思路:首先我们要明白这其实就是一个染色游戏,谁先把自己需要染的颜色先染完就赢了,但是由于如果第二个人把所需要的染完的次数和第一个相同这样的话,就会是平局了,因为一旦第二个人染完,第一个人就可以排序赢得游戏。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#define int long long
using namespace std;
const int N = 5e5 + 10, INF = 0x3f3f3f3f3f;
int n, m, k, _;
int arr[N];
void solve()
{
cin >> n;
for (int i = 1; i <= n; ++i) cin >> arr[i];
int f = 0, s = 0, o = 0;
for (int i = 1; i <= n; ++i)
{
if (arr[i] == i && arr[i] == n - i + 1)
f++, s++;
else if (arr[i] == i) f++;
else if (arr[i] == n - i + 1) s++;
else o++;
}
if (s + o <= f) cout << "First" << endl;
else if (f + o < s) cout << "Second" << endl;
else cout << "Tie" << endl;
}
signed main()
{
IOS;
cin >> _;
while (_--)
solve();
return 0;
}```