CF1659 Codeforces Round #782 (Div. 2) 题解
作者:互联网
好痛苦……我好垃圾……先把代码码一下,等到考完试再写解析吧。好久没有写题写的那么窒息了,罚时也相当爆炸。
呜呜呜呜我好垃圾……E题看了一眼不写了,后面补上(?)。
A Red Versus Blue
int n, r, b;
void solve(){
scanf("%d%d%d", &n, &r, &b);
int mx = n / (b + 1);
while (r > b && r >= mx && b > 0){
for (int i=0;i<mx;++i) printf("R");
printf("B");
r -= mx, b--;
}
while (b > 0 && r > 0){
printf("RB");
r--, b--;
}
for (int i=0;i<b;++i){
printf("B");
}
for (int i=0;i<r;++i){
printf("R");
}
puts("");
// printf("!! %d %d\n", r, b);
}
B Bit Flipping
int n, m;
const int N = 2e5 + 5;
string s, ans;
int r[N];
void init(){
ans.clear();
for (int i=0;i<n;++i){
r[i] = 0;
}
}
void solve(){
cin >> n >> m;
cin >> s;
init();
int tmp = m;
for (int i=0;i<n;++i){
if (i == n - 1) r[i] = tmp;
else if (tmp){
if ((s[i] - '0') ^ (m & 1) == 0)
r[i] = 1, --tmp;
}
if ((s[i] - '0') ^ ((m - r[i]) & 1)){
ans += "1";
}
else ans += "0";
}
cout << ans << endl;
for (int i=0;i<n;++i){
cout << r[i] << " \n"[i==n-1];
}
}
C Line Empire
ll n, a, b;
const int N = 2e5 + 5;
int x[N];
ll p[N];
void solve(){
scanf("%lld%lld%lld", &n, &a, &b);
for (int i=1;i<=n;++i){
scanf("%d", &x[i]);
}
for (int i=1;i<=n;++i){
p[i] = p[i - 1] + x[i];
}
ll mn = 3e18, cur;
for (int i=0;i<=n;++i){
cur = (a + b) * x[i] + b * ((p[n] - p[i]) - (n - i) * x[i]);
mn = min(mn, cur);
}
printf("%lld\n", mn);
}
D Reverse Sort Sum
int n;
const int N = 2e5 + 5;
int c[N], a[N];
void solve(){
scanf("%d", &n);
int st = 0;
for (int i=1;i<=n;++i){
scanf("%d", &c[i]);
a[i] = 1;
}
for (int i=1;i<=n;++i){
int x = n - c[i];
if (st == i - 1 && c[i] == 0){
a[i] = 0, ++st;
continue;
}
if (!a[i]) x -= i - 1;
st = n + 1 - x;
a[st] = 0;
}
// printf("!!! ");
for (int i=1;i<=n;++i){
printf(i==n?"%d\n":"%d ", a[i]);
}
}
标签:const,CF1659,782,int,题解,void,2e5,&&,scanf 来源: https://www.cnblogs.com/vivaldi370/p/solution_cf1659_a2e.html