Dashboard - Pinely Round 2 (Div. 1 + Div. 2) - Codeforces
A. Channel
题意:当前有a人在线,之后有人上下线都可知,问n人一定会上线,还是不可能,还是可能会。
思路:顺序统计上线人数,若出现下线人就减去,取最大值,若该最大值人数为大于等于n则一定会;然后用已上线人数加上所有上线的人数,假设都为新线用户,若够n则可能会,否则不可能。
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f;
int T, n, m, q, a;
int b[N];
int gcd(int a, int b)
{
if(b) while((a %= b) && (b %= a));
return a + b;
}
int main()
{
fast();
cin >> T;
while(T --)
{
cin >> n >> a >> q;
string s; cin >> s;
int x = 0, y = 0, cnt = 0;
int sz = s.size();
for(int i = 0; i < sz; i ++)
{
if(s[i] == '+') x ++, y ++;
else x --;
cnt = max(x + a, cnt);//当前一定上线的人数
}
if(n == a || cnt >= n)
cout << "YES" << endl;
else if(a + y >= n)
cout << "MAYBE" << endl;
else
cout << "NO" << endl;
}
return 0;
}
B. Split Sort
题意:给出一个从1到n的序列(不一定为顺序),可以进行一种操作,选择x,将小于x的数按原顺序提出,剩下的按原顺序放到之后形成新序列,问最小多少操作可以使序列递增
思路:若x+1在x的左边,即x+1优先于x出现,则至少需要一步操作来更改二者的顺序,统计这样的逆序对
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f;
int T, n, m, tt;
int q[N], b[N], tmp[N];
int gcd(int a, int b)
{
if(b) while((a %= b) && (b %= a));
return a + b;
}
int main()
{
fast();
cin >> T;
while(T --)
{
int cnt = 0, ans = 0;
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> q[i];
if(q[i] != i) cnt ++;
}
if(!cnt)
cout << ans << endl;
else
{
map<int, int> mp;
for(int i = 1; i <= n; i ++)
{
mp[q[i]] ++;//若相邻位为逆序,至少需要操作一次
if(mp[q[i] + 1]) ans ++;
}
cout << ans << endl;
}
}
return 0;
}
C. MEX Repetition
题意:给定长度为n的序列a,由0到n一共(n +1)的中的数构成,一轮操作为,将当前位置数由不出现在当前集合中的最小非负整数替代,一共进行k轮,打印最终操作数组
思路:
找规律,每(n + 1)轮操作一轮回,若k % (n + 1) == 0则直接打印原数组,否则找出排序后第一个不顺序出现的元素tt,找出的位置即为k%(n+ 1)轮后改元素的位置cnt,先输出原数组[n-cnt+1,n),tt,[0,n-cnt);
0 1 3
2 0 1//第一轮操作
3 2 0
1 3 2
0 1 3//第四轮操作,返回原数组
#include<bits/stdc++.h>
#define endl '\n'
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f;
int T, n, m, k;
int a[N], b[N];
int gcd(int a, int b)
{
if(b) while((a %= b) && (b %= a));
return a + b;
}
int main()
{
fast();
cin >> T;
while(T --)
{
cin >> n >> k;
for(int i = 0; i < n; i ++)
{
cin >> a[i];
b[i] = a[i];
}
if(k % (n + 1) == 0)
{
for(int i = 0; i < n; i ++)
cout << a[i] << " ";
}
else
{
int cnt = k % (n + 1);
sort(b, b + n);
int tt = 0;
for(int i = 0; i < n; i ++)
if(b[i] != tt) break;
else tt ++;
for(int i = n - cnt + 1; i < n; i ++)
cout << a[i] << " ";
cout << tt << " ";
for(int i = 0; i < n - cnt; i ++)
cout << a[i] << " ";
}
cout << endl;
}
return 0;
}
D. Two-Colored Dominoes
题意:太长了,麻了
思路:影响行的只有垂直块,影响列的只有水平块,若个影响行列的块数不为偶数,则一定不可能形成完美,可以分别以行和列的角度对影响其的块进行成对的交叉赋值
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f;
int T, n, m;
int a[N], b[N];
char c[M][M], p[M][M], s[M][M];
int gcd(int a, int b)
{
if(b) while((a %= b) && (b %= a));
return a + b;
}
int main()
{
fast();
cin >> T;
while(T --)
{
bool flag = true;
cin >> n >> m;
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
s[i][j] = '.';//存取答案图
for(int i = 0; i < n; i ++)
cin >> p[i];//操作图
int cnt = 0;
for(int i = 0; i < n; i ++)//对行中的垂直块操作,保证垂直块为偶数,相交赋值
{
int tt = 1;
for(int j = 0; j < m; j ++)
{
if(p[i][j] == 'U')
{
cnt ++;
if(tt == 1) s[i][j] = 'W', s[i + 1][j] = 'B', tt = 2;
else if (tt == 2) s[i][j] = 'B', s[i + 1][j] = 'W', tt = 1;
}
}
if (cnt % 2) flag = false;
cnt = 0;
}
for(int j = 0; j < m; j ++)//对列中的水平块操作,保证水平块为偶数,相交操作
{
int tt = 1;
for(int i = 0; i < n; i ++)
{
if (p[i][j] == 'L')
{
cnt ++;
if(tt == 1) s[i][j] = 'W', s[i][j + 1] = 'B', tt = 2;
else if(tt == 2) s[i][j] = 'B', s[i][j + 1] = 'W', tt = 1;
}
}
if(cnt % 2) flag = false;
cnt = 0;
}
if(flag)
{
for(int i = 0; i < n; i ++)
{
for(int j = 0; j < m; j ++)
cout << s[i][j];
cout << endl;
}
}
else cout << -1 << endl;
}
return 0;
}
/*
_ooOoo_
o8888888o
88" . "88
(| ^_^ |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑AC,永无bug缠身
*/