Codeforces Round #656 (Div. 3)部分题解
Codeforces Round #656 (Div. 3)题解
A.Three Pairwise Maximums
解题思路:
依照题意和样例,三个整数x,y,z必须有两个相同且都比第三个数大。
如果x==y则说明a为最大值,此时需要满足a>=z,如果不满足该条件,则无解,因为z=max(b,c),我们不能确定b,c谁比较大,所以我们就假设两个数一样的即可。而当y == z和x == z同理。
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t; cin >> t; while (t--) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[1] != a[2]) {
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
cout << a[0] << " " << a[0] << " " << a[2] << endl;
}
}
B.Restore the Permutation by Merger
题目说是相对顺序插入的,所以我们可以直接遍历来做。
#include<bits/stdc++.h>
using namespace std;
int t, n, a;
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> t; while (t--) {
cin >> n; int b[55] = { 0 };
for (int i = 0; i < 2 * n; ++i) {
cin >> a;
if (!b[a])
cout << a << " ";
b[a]++;
}
cout << endl;
}
}
C.Make It Good
解题思路:
满足中间大两边小。
要找最长“好序列”,从后往前找,找到第一个不满足从后往前递增条件的元素,然后从这个元素往前找,找到开始升的那个元素就停止。最后答案就是n减去最长“好序列”长度。
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int R = n;
while (a[R - 1] >= a[R] && R >= 1) R--;
while (a[R - 1] <= a[R] && R >= 1) R--;
int ans = R - 1;
if (ans == -1) ans = 0;
cout << ans << endl;
}
return 0;
}
D. a-Good String
解题思路:
暴力枚举,取最小值
#include<bits/stdc++.h>
using namespace std;
char a[131073];
int t, n;
int solve(int l,int r,char m) {
if (l == r) {
if (a[l] == m)return 0;
else return 1;
}
int mid = (l + r) >> 1, left = 0, right = 0,len = r - l + 1;
for (int i = l; i <= mid; ++i) if (a[i] == m)left++;
for (int i = mid + 1; i <= r; ++i) if (a[i] == m)right++;
int ans = min(len / 2 - left + solve(mid + 1, r, m + 1), len / 2 - right + solve(l, mid, m + 1));
return ans;
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> t; while (t--) {
char m = 'a';
cin >> n;for(int i = 1;i <= n;++i){
cin >> a[i];
}
cout << solve(1, n, m) << endl;
}
}
E. Directing Edges
解题思路:
首先可以看出这是一道拓扑的题。但由于不太好维护得建图。建反方向的边,最后再拓扑排。但由于我太菜了,就没做出来。代码就放dalao们做的了。
#include<bits/stdc++.h>
using namespace std;
vector<int>e[200005];
int u[200005],v[200005];
int T,n,m;
int in[200005],tp[200005];
queue<int>q;
bool topsort(){
int ct=0,tmp=0;
for(int i=1;i<=n;i++) if(!in[i]) q.push(i),ct++,tp[i]=++tmp;
while(!q.empty()){
int U=q.front();q.pop();
for(int V:e[U]){
in[V]--;
if(!in[V]) q.push(V),ct++,tp[V]=++tmp;
}
}
return ct<n;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);memset(in,0,sizeof(in));
for(int i=1;i<=n;i++) e[i].clear();
for(int o,i=1;i<=m;i++){
scanf("%d%d%d",&o,&u[i],&v[i]);
if(o) in[v[i]]++,e[u[i]].emplace_back(v[i]);
}if(topsort()) puts("NO");
else{
puts("YES");
for(int i=1;i<=m;i++)
if(tp[u[i]]<tp[v[i]]) printf("%d %d\n",u[i],v[i]);
else printf("%d %d\n",v[i],u[i]);
}
}return 0;
}
Codeforces Round #656 (Div. 3)部分题解的更多相关文章
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #821(Div.2) (A-C) 题解
Codeforces Round #821(Div.2) (A-C) A.Consecutive Sum 大致题意 给定一组共 n 个数据 ,如果俩个数的下标在 mod k 意义下同余,则可以交换a[ ...
随机推荐
- 如何通过C++ 给PDF文档添加文字水印
因PDF文档具有较好的稳定性和兼容性,现在越来越多的合同.研究论文.报告等都采用PDF格式.为了进一步保护这些重要文档内容免受未经授权的复制或使用,我们可以添加水印以表明其状态.所有权或用途.针对工作 ...
- Mysql报:error while loading shared libraries libtinfo.so.5的解决办法
版权声明:原创作品,谢绝转载!否则将追究法律责任. ----- 作者:kirin #.今天闲来无事,想在Anolis8的系统上装一个MySQL8.0玩.前期在安装和配置的过程中没有什么问题,但是在我想 ...
- LeetCode15:三数之和(双指针)
解题思路:常规解法很容易想到O(n^3)的解法,但是,n最大为1000,很显然会超时. 如何优化到O(n^2),a+b+c =0,我们只需要判断 a+b的相反数是否在数组中出现,而且元素的取值范围在 ...
- 【C++】【图像处理】灰度直方图实现算法解析(以.raw格式的图像为基础进行图像处理、gray levels:256)
前情提要:本记录需要一定的C++和图像处理基础进行阅读. 图像处理算法学习记录: Code: 1 void histCompute(BYTE*image, int width, int height) ...
- Android SDK Manager 报错“加载 SDK 组件信息失败”。(Android SDK Manager complains with "Loading SDK component information failed."
[解决方案]: 将存储库设置更改为 Google .因此,在 android SDK 管理器上点击齿轮图标(设置),然后点击 Repository -> Google.
- #11独立开发周总结|核心OKR1000元/月已达标
核心OKR:1000元/月达成情况 算上微信上收费了200多元,核心OKR已达标 12.25-12.29本周完成事项 产品方面 本周产品上主要是在进行重构的测试,顺利上线,线上问题也比较少 运营方面 ...
- JavaFx之Ikonli图标库大全(十五)
JavaFx之Ikonli图标库大全(十五) Ikonli给java提供了大量的图标库, 官网:https://kordamp.org/ikonli/ Ikonli 提供了可以在 Java 应用程序中 ...
- CSS3学习笔记-字体属性
在CSS3中,可以使用字体属性来控制网页中文本的样式和排版.以下是常用的字体属性: font-family 该属性用于指定网页中的文本所使用的字体.我们可以通过使用通用的字体名称,或者直接使用字体名称 ...
- Visual Studio 2022 Preview设置简体中文
前言: 作为尝鲜小分队队长,对于vs的升级版Visual Studio 2022 Preview肯定也开始用上了,不过之前一直以为还没有出中文的语言包所以一直用的是英文版的,搞得英文本来不好的我很是不 ...
- 五菱宝骏车机升级教程【嘟嘟桌面或ES文件管理器】
文章来源:https://www.djww.net/607.html 简介 越来越多的汽车厂商自研车机系统,其实就是在原来安卓的基础上加入自己的元素,然后禁用某些功能从而实现禁止用户安装第三方app. ...