Dashboard - Educational Codeforces Round 155 (Rated for Div. 2) - Codeforces
A. Rigged!
题意:举重比赛,给出n个人,每个人给出能举的最大重量和单个重量能举起的次数,要让第一个人赢,需要用多大的重量,成绩相同无胜者。
思路:只要存在举起的重量和次数同时>=第一个人的人,就不可能让第一个人获胜
AC code:
#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<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, m;
//int a[N], b[N];
int gcd(int a, int b){
if(b) while((a %= b) && (b %= a));
return a + b;
}
int main(){
fast();
T = 1;
cin >> T;
while(T --){
vector<PII> q;
cin >> n;
for(int i = 0; i < n; i ++){
int x, y; cin >> x >> y;
q.push_back({x, y});
}
int a = q[0].first, b = q[0].second;
int flag = 0;
for(int i = 1; i < n; i ++){
if(q[i].first >= a && q[i].second >= b){
flag = 1;
break;
}
}
if(flag) cout << "-1" << endl;
else cout << a << endl;
}
}
B. Chips on the Board
题意:给出a,b两个大小为n的数组,给出一个n*n的棋盘,向里面填筹码,每行或者每列起码得有一个筹码,填入筹码的成本为棋盘坐标(i, j)—>ai+bj,问最小成本
思路:找出每行的最小值,填满最小行,保证每一列有筹码,得到成本x;
找出每列的最小值,填满最小列,保证每一行有筹码,得到成本y;
取x,y最小值
AC code:
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, m;
//int a[N], b[N];
int gcd(int a, int b){
if(b) while((a %= b) && (b %= a));
return a + b;
}
signed main(){
fast();
T = 1;
cin >> T;
while(T --){
cin >> n;
vector<PII> a, b;
int sum_a = 0, sum_b = 0;
for(int i = 1; i <= n; i ++){
int x; cin >> x;
sum_a += x;
a.push_back({x, i});
}
for(int i = 1; i <= n; i ++){
int x; cin >> x;
sum_b += x;
b.push_back({x, i});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int cnt1 = 0, cnt2 = 0;
cnt1 = sum_a + b[0].first * n;
cnt2 = sum_b + a[0].first * n;
cout << min(cnt1, cnt2) << endl;
}
return 0;
}
C. Make it Alternating
题意:给出01字符串,每次操作可以删除任一字符,求两个数,一个是最少删多少字符能让字符串相邻字符不相同即01010101…,一个是做到这种操作的不同操作数
思路:找出连续相邻子区间,即s[i] == s[i + 1] 的子区间长度t,(t-1)即为该段需要的操作数;
每一段需要删(t-1)个,那么该段可能的操作数即为t中留一个,即t种选择,每段子序列相乘,还需要乘上所有需要操作字符的全排列,即为最终答案;
AC code:
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, m;
//int a[N], b[N];
int gcd(int a, int b){
if(b) while((a %= b) && (b %= a));
return a + b;
}
int sum(int n){
if(n == 1 || n == 0) return 1;
return n * sum(n - 1) % mod;
}
signed main(){
fast();
T = 1;
cin >> T;
while(T --){
string s; cin >> s;
int cnt = 0, res = 1, l = 1;
for(int i = 0; i < s.size(); i ++){
if(s[i] == s[i + 1]){
l ++;
}
else if(l > 1){
cnt += l - 1;
res = (res * l) % mod;
l = 1;
}
}
if(l > 1){
cnt += l - 1;
res = (res * l) % mod;
}
if(cnt == 0) res = 1;
else res = res * sum(cnt) % mod;
cout << cnt << " " << res << endl;
}
return 0;
}
/*
_ooOoo_
o8888888o
88" . "88
(| ^_^ |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑AC,永无bug缠身
*/