比赛链接Dashboard - Codeforces Round 908 (Div. 2) - Codeforces
A
题目大意
玩家A和B参与比赛,比赛由几轮组成,每轮都有几场比赛 。
在每场比赛中,A或B中只有一名选手获胜。当其中一名选手在该轮比赛中达到x胜时,该轮结束。这名选手被宣布为这轮比赛的获胜者。选手们打几轮,直到其中一人达到胜利y轮为止。之后,游戏结束,该玩家被宣布为整个游戏的获胜者 。
你刚刚看了n场比赛,并知道哪个玩家赢下了哪场,但是你不知道x和y的值,现在需要你判断比赛最终是A还是B获胜,或者无法确定是谁获胜。
现在给出长度为n的字符串 ,第i个字符表示该玩家赢下第i场比赛。
思路
本题有一个取巧的做法,当分出胜负的时候,最后一轮的最后一把一定是最终获胜者获取的
ACcode
#include<iostream>
#include<string>
using namespace std;
void solve() {
int n; cin >> n;
string str;
cin >> str;
cout << str[str.size() - 1] << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
B
题目大意
给出一个数列a[N],你需要构造一个元素只含有1,2,3的数列b[N],使恰好满足下面三个条件中的两个:
存在1<=i,j<=n,使得a[i]=a[j],b[i]=1,b[j]=2
存在1<=i,j<=n,使得a[i]=a[j],b[i]=1,b[j]=3;
存在1<=i,j<=n,使得a[i]=a[j],b[i]=2,b[j]=3;
如果存在多种满足题意的答案,输出任意即可,如果不存在,输出-1
思路
我们只需要关心数列a中出现次数>=2的种类数t
t=0,显然不存在数列b,输出-1;
t=1,易知只会满足0种或1种或3种(用上面三个条件推一下即可)
t>=2,存在满足2种条件
ACcode
#include<iostream>
#include<vector>
using namespace std;
void solve() {
int n; cin >> n;
vector<int>a(n), b(n, 1);//记录数组,打印数组
int cnt[105];
vector<int>pos;
for (int i = 0; i < 105; i++)cnt[i] = 0;
for (int i = 0; i < n; i++)a[i] = 0;
int pre = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
if (cnt[a[i]] >= 2 && (pre == -1 || pre != a[i])){
pre=a[i];
pos.push_back(i);
}
}
if (pos.size() <= 1)cout << -1;
else {
b[pos[0]] = 2;
b[pos[1]] = 3;
for (int i = 0; i < n; i++)cout << b[i] << ' ';
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
C
题目大意
给定一个数组b,一个匿名线人告诉你数组b是这样得到的:最初有一个同样长的数组 a,然后进行如下操作k次
选择数组a中的的一个定点x, 把整个数组向左移动x次
判断是否真的存在某个数组a,使之经过k次以上操作之后变成 b。
成为备选定点的条件:在数列a中且a[i]=i。
数列a向左移动两个单位,a1,a2...an——a3,a4....an,a1,a2;
思路
观察样例和读题可知,每次移动后,都是把选择的那个点x移动到数列a的后面
所以可以利用逆向思维,每次让最后一位归位,然后找上一位,继续归位,当找到某一个最后一位大于n的时候输出不存在,如果找了一圈循环了,则存在
ACcode
#include<iostream>
#include<vector>
using namespace std;
int n, k;
void solve() {
cin >> n >> k;
vector<int>b(n + 1,0);
vector<bool>st(n + 1,0);
for (int i = 1; i <= n; i++)cin >> b[i];
bool flag = 1;
int last = n;
for (int i = 1; i <= k;i++) {
if (b[last] > n) { flag = 0; break; }
if (st[last]) { break; }//已经循环过一遍了
st[last] = 1;
last = (last - b[last] + n) % n;
if (!last)last = n;
}
if (flag)cout << "Yes" << '\n';
else cout << "No" << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}