A. Red Versus Blue

每一次循环都计算R和B的比例,然后输出t个R,一个B,每次输出都判断是否结束

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>#define endl '\n'using namespace std;const int N = 1e5 + 10;void mian()
{int n, a, b;cin >> n >> a >> b;while (n){int t = 1.0 * a / (b + 1) + 0.99;for (int i = 1; i <= t; i++){cout << "R";n--;if (n == 0)break;a--;}if (n == 0)break;cout << "B";n--;b--;}cout << endl;
}int main()
{int T;cin >> T;while (T--){mian();}return 0;
}

B. Bit Flipping

题目要求是可以将一位不变,可以转换一下这种情况为使一位发生变化。但是次数要求是偶数次,所以如果k为奇数,就将全部位转换一下。

然后可以发现有k次机会使一位发生变化,最后剩余的次数全部给最低位即可。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>#define endl '\n'using namespace std;const int N = 1e5 + 10;void mian()
{int n, k;string s;cin >> n >> k;cin >> s;if (k == 0){cout << s << endl;for (int i = 1; i <= n; i++){cout << "0" << ' ';}cout << endl;}else{if (k % 2){for (int i = 0; i < s.size(); i++){s[i] ^= 1;}}vector<int> ans(n);for (int i = 0; i < s.size() - 1; i++){if (k == 0)break;if (s[i] == '0'){s[i] = '1';k--;ans[i] = 1;}elseans[i] = 0;}if (k % 2){s[s.size() - 1] ^= 1;}ans[n - 1] = k;cout << s << endl;for (auto i : ans){cout << i << ' ';}cout << endl;}
}int main()
{int T;cin >> T;while (T--){mian();}return 0;
}

C. Line Empire

题意:X轴上有n个城市,自己主城在0处,可以花费b乘上主城与另一个城市之间的距离来攻占掉,也可以花费a乘两地距离来迁都。迁都只能迁到已经攻占的地方,攻占不能跳过其他城市攻占,求花费最小多少。

如果不迁都,那么以后每次攻占都要计算上这一段距离,那么可以算一下还有几个城要攻占乘上权值b,与权值a进行比较,如果比a大那么就要迁都。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>#define endl '\n'using namespace std;typedef long long ll;const int N = 1e5 + 10;ll x[N];void mian()
{ll n, a, b, pos = 0;ll res = 0;cin >> n >> a >> b;for (int i = 1; i <= n; i++){cin >> x[i];}res += x[1] * b;for (int i = 2; i <= n; i++){if ((n - i + 1) * b > a){res += a * (x[i - 1] - pos);pos = x[i - 1];}res += b * (x[i] - pos);}cout << res << endl;
}int main()
{int T;cin >> T;while (T--){mian();}
}

D. Reverse Sort Sum

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>#define endl '\n'using namespace std;const int N = 1e5+10;void mian()
{int n;cin >> n;vector<int> a(n, 1);vector<int> c(n);for (int i = 0; i < n; i++){cin >> c[i];}for (int i = 0; i < n; i++){if (c[i] == 0){a[i] = 0;}else if (c[i] < n){a[c[i]] = 0;c[c[i]] += c[i];}}for (int i = 0; i < n; i++){cout << a[i] << ' ';}cout << endl;
}int main()
{int T;cin>>T;while(T--){mian();}return 0;
}

Codeforces Round #782 (Div. 2) A-D题解相关推荐

  1. Codeforces Round #782 (Div. 2) A~D

    Codeforces Round #782 (Div. 2) A. Red Versus Blue 题意:红队和蓝队进行了 n n n次比赛.用一个长度为 n n n的字符串表示每场的胜负情况.R代表 ...

  2. Codeforces Round #782 (Div. 2)

    咕咕咕咕咕 前段时间去打华为软挑了,所以停了一段时间的训练,嘤嘤嘤 这场本来要打,然后十分钟写A写bug了,于是玩游戏去了-- 早上vp了一下,下课了就溜回去睡觉了,下午把c做了,d还没看,回头看一下 ...

  3. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  4. Codeforces Round #774 (Div. 2)E题题解

    Codeforces Round #774 (Div. 2) E. Power Board 题目陈述 有一个n×m(1≤n,m≤106)n\times m(1\le n,m\le10^6)n×m(1≤ ...

  5. Codeforces Round #640 (Div. 4)(ABCDEG题解)

    文章目录 A. Sum of Round Numbers B - Same Parity Summands C - K-th Not Divisible by n D - Alice, Bob and ...

  6. Codeforces Round #782 (Div. 2)-D. Reverse Sort Sum(树状数组)

    题目链接:Problem - D - Codeforces 题意:给定一个 01 序列 ,对  区间分别进行递增排序,得到  个序列,现给定  序列, ,即所有序列第  位的和.求给定 序列所对应的原 ...

  7. Codeforces Round #635 (Div. 2)(A~D)题解

    Codeforces #635 A~D A.Ichihime and Triangle B.Kana and Dragon Quest game C.Linova and Kingdom D.Xeni ...

  8. 【记录CF】Codeforces Round #777 (Div. 2) A~C 题解

    目录 杂谈 A. Madoka and Math Dad B. Madoka and the Elegant Gift C. Madoka and Childish Pranks 杂谈 又是一场离谱掉 ...

  9. [cf]Codeforces Round #782 (Div. 2)

    目录 前言 A.Red Versus Blue code B. Bit Flipping code C Line Empire code D.(完全不会,蹲大佬的题解) 前言 传送门 : (那天人们又 ...

最新文章

  1. python beautifulsoup模拟点击_Python爬虫丨BeautifulSoup实践
  2. Microsoft Speech SDK 编程入门
  3. 剑指Offer(Java实现)重建二叉树
  4. stm32 独立看门狗和窗口看门狗区别
  5. 路由器OSPF协议配置命令一
  6. 法在计算机课程中的应用,尝试教学法在中职《计算机应用基础》课程中的应用(原稿)...
  7. c语言未声明的标识符什么意思_C语言中%d和%f是什么意思啊?
  8. 【laravel VS lumen】
  9. (转)DB2 db2diag.log 日志分析
  10. Linux安装yum教程
  11. 如何用ESP32+LVGL实现给路由器加装屏幕
  12. Shell脚本学习指南读书笔记(一)
  13. 小程序容器化:基于uni-app的Android小程序开发
  14. 公众号运营实用小工具推荐
  15. TTML(IMSC)字幕
  16. 平衡搜索树中的左单旋右单旋双旋
  17. laragon用php连接数据库,Laragon - PHP 集成环境 - 技术资源库 - by 安拓网络技术资源库 - by 安拓网络...
  18. C++ 基础知识throw的用法
  19. JS计算日期天数之差
  20. 如何通过sstap实现本地静态ip

热门文章

  1. WLAN无线局域网IEEE802.11协议二
  2. 【UR #2】 猪猪侠再战括号序列
  3. 软考中级 真题 2014年下半年 系统集成项目管理工程师 应用技术 下午试卷
  4. Java程序员日常积累-向大神学习(三)
  5. Linux 压缩管理、进程管理、网络管理命令总结
  6. MySQL8 创建主键ID
  7. 小程序快速入门到项目开发 2(小程序appID获取和目录结构)
  8. app内实现搜索wifi和连接wifi
  9. 【FFmpeg 之MP4】mp4视频切割
  10. Java 2 实用教程(第五版)课后习题-【编程题答案】