Codeforces Round 910 (Div. 2)
A. Milica and String
wa麻了,,,不知道自己在干什么
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve(){
int k,n;
string s;
cin>>n>>k>>s;
int cnt=0;
s = " " + s + " ";
for(int i=n+1;i;i--) if(s[i]=='B') cnt++;
if(cnt==k) cout<<0<<endl;
else if(cnt>k){
int cnt1=0;
cout<<1<<endl;
for(int i=n+1;i>0;i--){
if(s[i]=='B') cnt1++;
if(cnt1==k){
cout<<i-1<<" A"<<endl;
return;
}
}
}else{
int cnt1=0;
cout<<1<<endl;
for(int i=1;i<=n;i++){
if(s[i]=='A') cnt1++;
if(cnt1==k-cnt){
cout<<i<<" B"<<endl;
return;
}
}
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
B. Milena and Admirer
今天不宜写题
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10;
int a[N];
int n;
void solve(){
cin>>n;
int ans=0;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=n-1;i>0;i--){
if(a[i]<=a[i+1]) continue;
int x=(a[i] + a[i+1] - 1)/a[i+1];
a[i]/=x;
ans+=x-1;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
C. Colorful Grid
写着有点恶心,,,自己的码太丑了贴个佬的码
只要在起点处加个环,终点加个U型就行了
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
int main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n, m, k;
cin >> n >> m >> k;
if (k < n + m - 2){
cout << "NO" << '\n';
continue;
}
if (k % 2 != (n + m - 2) % 2){
cout << "NO" << '\n';
continue;
}
vector<vector<int> > a1(n, vector<int>(m - 1)), a2(n - 1, vector<int>(m));
for(int i = 0; i < n - 1; i++){
if (i % 2 == 0){
a2[i][0] = 1;
}
}
for(int i = 0; i < m - 1; i++){
if ((n + i - 1) % 2 == 0){
a1[n - 1][i] = 1;
}
}
if (k % 4 != (n + m - 2) % 4){
a1[0][0] = a1[1][0] = 1;
}
a2[n - 2][m - 1] = a1[n - 1][m - 2] ^ 1;
a1[n - 2][m - 2] = a1[n - 1][m - 2];
a2[n - 2][m - 2] = a2[n - 2][m - 1];
cout << "YES" << '\n';
for(int i = 0; i < a1.size(); i++){
for(auto x : a1[i]){
cout << (x ? "R" : "B") << ' ';
}
cout << '\n';
}
for(int i = 0; i < a2.size(); i++){
for(auto x : a2[i]){
cout << (x ? "R" : "B") << ' ';
}
cout << '\n';
}
}
}
D
将每个集合当作一个线段。如果两个线段相交,对他们进行交换结果不变。如果两个线段不相交,假设[l1,r1],[l2,r2],l1<r1<l2<r2,对他们交换结果增大2*(l2-r1),因为只交换一次,所以我们要找到最大的那个左端点和最小的那个右端点。
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10;
int n;
int a[N];
int b[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
int sum=0;
int maxl=0;
int minr=1e9;
for(int i=1;i<=n;i++){
sum+=abs(a[i]-b[i]);
maxl=max(maxl,min(a[i],b[i]));
minr=min(minr,max(a[i],b[i]));
}
if(maxl>=minr)sum+=2*(maxl-minr);
cout<<sum<<endl;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
标签:int,Codeforces,long,a1,--,Div,include,910,define
From: https://www.cnblogs.com/zfxyyy/p/17875708.html