#include<bits/stdc++.h>
#define ll long long
#define pd() printf("\n")
#define pr(x) printf("%d", x)
#define x first
#define y second
using namespace std;
const int N = 4000;
int main() {
int T;
scanf("%d", &T);
while(T --){
int n, r, b;
scanf("%d%d%d",&n,&r,&b);
int k = r / (b + 1);
int z = r % (b + 1);
int cnt = 0, sum = 0;
string ans = "";
for(int i = 0; ans.length() < n; i ++){
if(cnt < k) ans += "R", cnt ++;
else{
cnt = 0;
if(z > 0)z--, ans+="R";
if(sum < b)sum ++,ans+="B";
else ans+="R";
}
}
cout << ans << endl;
pd();
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define pr(x) printf("%d",x)
#define pd() printf("\n")
#define ll long long
const int N = 2e5 + 100;
ll a[N], cnt[N];
char chage_ch(char ch){
ch = ch == '1' ? '0' : '1';
return ch;
}
void solve(){
int n, k, z = 0;
string s;
cin >> n >> k >> s;
for(int i = 0; i < n; i ++) cnt[i] = 0;
for(int i = 0; i < n; i ++){
if(!k || i == n - 1) {
for(int j = i; j < n; j ++){
if(z & 1)s[i] = chage_ch(s[i]);
}
break;
}
if(z & 1){
s[i] = chage_ch(s[i]);
}
if(s[i] == '1' && (k & 1)) cnt[i] ++ , k --, z ++;
else if(s[i] == '0' && (k % 2 == 0)) cnt[i] ++ , k --, z ++;
s[i] = '1';
}
cnt[n - 1] = k;
if(z & 1){
s[n - 1] = chage_ch(s[n - 1]);
}
cout << s[n - 1] << endl;
for(int i = 0; i < n; i ++){
cout << cnt[i] << " ";
}
cout << endl;
}
int main(){
int T;
cin >> T;
while(T --)
{
solve();
}
}
题意: 你的首都在数轴0这个位置,给出n个敌国位置(x1,x2…xn),你可以进进行两个操作: 1.占领一个帝国花费为b*|xi - xj|. 2.移动首都的位置花费为a*|x2 - xj|. 求最小花费:
#include<bits/stdc++.h>
using namespace std;
#define pr(x) printf("%d",x)
#define pd() printf("\n")
#define ll long long
const int N = 2e5 + 100;
ll x[N], sum[N];
void solve(){
ll a, b, n;
cin >> n >> a >> b;
for(int i = 1; i <= n ; i ++)
{
cin >> x[i];
sum[i] = sum[i-1] + x[i];
}
ll ans = b * sum[n];
for(int i = 1; i <= n; i ++){
ll res = (1ll * a + 1ll * b) * x[i];
res += 1ll * b * (sum[n] - sum[i] - (n - i) * x[i]);
ans = min(ans, res);
}
cout << ans << endl;
}
int main(){
int T;
cin >> T;
while(T --)
{
solve();
}
}
#include<bits/stdc++.h>
using namespace std;
#define pr(x) printf("%d",x)
#define pd() printf("\n")
#define ll long long
const int N = 2e5 + 100;
int a[N], cnt[N];
void solve(){
int n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
cnt[i] = 1;
}
for(int i = 1; i <= n; i ++){
if(a[i] == 0) cnt[i] = 0;
else{
if(cnt[i] == 0) a[i] += (i - 1);
cnt[a[i] + 1] = 0;
}
}
for(int i = 1; i <= n ; i ++){
cout << cnt[i] << " ";
}
cout << endl;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T;
cin >> T;
while(T --)
{
solve();
}
}
|