链接 : https://codeforces.com/contest/1365/problems

problem A

统计可用的行和列的最小值, 模2输出即可

/*
* Author: RoccoShi
* Time: 2020-06-07 22:35:02
*/ #include <bits/stdc++.h>
using namespace std; typedef long long ll; int vix[50];
int viy[50];
int cntx=0, cnty=0; int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
int m, n;
cin >> n >> m;
int x;
for(int i = 0; i < n; ++ i)
for(int j = 0; j < m; ++ j){
cin>>x;
if(x==1){
vix[i] = 1;
viy[j] = 1;
}
}
for(int i = 0; i < n; ++ i)
{
if(vix[i]==0) cntx++;
}
for(int i = 0; i < m; ++ i){
if(viy[i]==0) cnty++;
}
int ans = min(cntx,cnty) % 2;
if(ans==1)cout << "Ashish" <<endl;
else cout << "Vivek" <<endl;
memset(vix,0,sizeof(vix));
memset(viy,0,sizeof(viy));
cntx=0;cnty=0;
} return 0;
}

problem B

可以知道, 只要有0,1那么这个数组想换成啥样就换成啥样

如果全0 or 全1, 数组必须得是非递减

/*
* Author: RoccoShi
* Time: 2020-06-07 22:35:02
*/ #include <bits/stdc++.h>
using namespace std; typedef long long ll; int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
int n,a,b,tmp;
cin>>n;
int flag = 0;
for(int i=0;i<n;++i){
cin >> a;
if(i!=0)
if(a<tmp)
flag = 1;
tmp = a;
}
for(int i=0;i<n;++i){
cin >> b;
if(i!=0)
if(b!=tmp)
flag = 0;
tmp = b;
}
if(flag == 0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0; }

problem C

固定其中一个数组不动, 另一个数组最多右移n-1次

用一个数组vis保存数组a的每个值的位置

vis[i]表示 : i在数组a中的位置为vis[i]

当输入数组b时, 直接用ans = vis[b[i]] - i ( 这个数在a的位置 - 这个数在b的位置 )

如果>=0, 则此数移动ans次可匹配

如果<0, 则此数移动n+ans次可匹配

用一个map装移动x次能匹配的数的个数, 最后遍历取最大值为答案

/*
* Author: RoccoShi
* Time: 2020-06-07 22:35:02
*/ #include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 4e5 + 5;
int a[N], b[N], vis[N];
int ans = 0;
map<int,int> mp; int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; ++i){
cin >> a[i];
vis[a[i]] = i;
}
for(int i = 0; i < n; ++i){
cin >> b[i];
ans = vis[b[i]] - i;
if(ans >= 0)
mp[ans]++;
else
mp[n+ans]++;
}
map<int,int>::iterator it;
ans = -1;
for(it = mp.begin(); it != mp.end(); ++it)
{
ans = max(ans, it->second);
}
cout << ans << endl;
return 0;
}

problem D

统计好人个数, 然后把坏人全封死, 再从终点往回dfs统计好人的个数, 如果好人全找到了, 就YES否则NO

/*
* Author: RoccoShi
* Time: 2020-06-07 22:35:02
*/ #include <bits/stdc++.h>
using namespace std; typedef long long ll;
char a[55][55];
int vis[55][55];
int m, n, ans; int dfs(int x,int y){
if(vis[x][y] || a[x][y]=='#')
return 0;
int ans = 0;
vis[x][y] = 1;
if(a[x][y] == 'G')
{
ans++;
}
ans = ans + dfs(x+1,y);
ans = ans + dfs(x-1,y);
ans = ans + dfs(x,y+1);
ans = ans + dfs(x,y-1);
return ans;
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
cin >> m >> n;
for(int i=0;i<=m+1;++i)
{
a[i][0] = '#';
a[i][n+1] = '#';
}
for(int j=0;j<=n+1;++j)
{
a[0][j] = '#';
a[m+1][j] = '#';
}
int cntG=0;
for(int i = 1; i <= m; ++i){
for(int j = 1; j <= n; ++j)
{
cin>>a[i][j];
if(a[i][j] == 'G') cntG++;
}
}
for(int i = 1; i <= m; ++i){
for(int j = 1; j <= n; ++j)
{
if(a[i][j]=='B'){
a[i][j-1]!='B'?a[i][j-1]='#':1;
a[i][j+1]!='B'?a[i][j+1]='#':1;
a[i+1][j]!='B'?a[i+1][j]='#':1;
a[i-1][j]!='B'?a[i-1][j]='#':1;
}
}
} ans = dfs(m,n);
if(ans == cntG)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
memset(vis,0,sizeof(vis));
}
return 0;
}

这次比赛只写了前2题, 后两题补的

如果说学到了什么, 那就是找通解不要瞎jier特判, 判到最后一堆bug还把人给判晕了

Codeforces Round #648 (Div. 2)的更多相关文章

  1. Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value(鸽巢原理)

    题目链接:https://codeforces.com/problemset/problem/1365/E 题意 有 $n$ 个元素,定义大小为 $k$ 的集合值为 $\sum2^i$,其中,若集合内 ...

  2. Codeforces Round #648 (Div. 2) D. Solve The Maze

    这题犯了一个很严重的错误,bfs 应该在入队操作的同时标记访问,而不是每次只标记取出的队首元素. 题目链接:https://codeforces.com/contest/1365/problem/D ...

  3. Codeforces Round #648 (Div. 2) C. Rotation Matching

    题目链接:https://codeforces.com/contest/1365/problem/C 题意 有两个大小为 $n$ 的排列,可以循环左移或右移任意次,问最多有多少对同一值在同一位置. 题 ...

  4. Codeforces Round #648 (Div. 2) B. Trouble Sort

    一开始读错题了...想当然地认为只能相邻元素交换...(然后换了两种写法WA了4发,5分钟切A的优势荡然无存) 题目链接:https://codeforces.com/contest/1365/pro ...

  5. Codeforces Round #648 (Div. 2) A. Matrix Game

    题目链接:https://codeforces.com/contest/1365/problem/A 题意 给出一个 $n \times m$ 的网格,两人轮流选择一个所在行列没有 $1$ 的方块置为 ...

  6. Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value 贪心

    题意:E.Maximum Subsequence Value 题意: 给你n 个元素,你挑选k个元素,那么这个 k 集合的值为 ∑2i,其中,若集合内至少有 max(1,k−2)个数二进制下第 i 位 ...

  7. Codeforces Round #648 (Div. 2) F. Swaps Again

    题目链接:F.Swaps Again 题意: 有两个长度为n的数组a和数组b,可以选择k(1<=k<=n/2)交换某一个数组的前缀k和后缀k,可以交换任意次数,看最后是否能使两个数组相等 ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. web自动化之执行js脚本

    from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from seleni ...

  2. Android_四大组件之BroadcastReceiver

    一.概述 BroadcastReceiver是广播接收器,接收来自 系统或应用发出的广播信息 并进行相应的逻辑处理. 自定义BroadcastReceiver只需继承android.content.B ...

  3. 编译sifive的freedom-u-sdk

    在其它电脑搭建编译该sdk工程的环境,由于所在电脑的linux系统为新装系统(版本:Ubuntu 20.04 LTS),下面记录了编译过程中遇到的问题,以及解决过程供以后参考 问题1:error &q ...

  4. MySql Oracle SqlServer 数据库的数据类型列表

    Oracle数据类型 一.概述  在ORACLE8中定义了:标量(SCALAR).复合(COMPOSITE).引用(REFERENCE)和LOB四种数据类型,下面详细介绍它们的特性. 二.标量(SCA ...

  5. uwsgi+nginx 502 bad get away 错误

    用uwsgi和nginx部署网站时有时候访问网站会出现502错误 配置,启动文件等完全没有问题. 目前解决方法是重启uwsgi就可以了(虽然说502错误应该有很多产生原因啦) 所用命令: $ ps - ...

  6. Rocket - debug - TLDebugModuleInner - ABSTRACTCS

    https://mp.weixin.qq.com/s/dF_0sE5ZakyY569wlppVHA 简单介绍TLDebugModuleInner中ABSTRACTCS寄存器的实现. 1. ABSTRA ...

  7. Splay代码简化版

    皆さん.こんにちは.上一篇文章,我们讲了Splay如何实现.这一篇我们来让我们的伸展树短一点. 上一篇Splay讲解的链接:リンク. 首先还是变量的定义,在这里呢,我把一些小函数也用Define来实现 ...

  8. 本地计算机上的MySQL80服务启动后停止,某些服务在未由其他服务或者程序使用时将自动停止

    是由于mysql server XX 路径下的my.ini文件发生错误. 高版本的mysql server的my.ini文件不在mysql server XX路径下,在programdata文件夹(查 ...

  9. Java实现 LeetCode 581 最短无序连续子数组(从两遍搜索找两个指针)

    581. 最短无序连续子数组 给定一个整数数组,你需要寻找一个连续的子数组,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序. 你找到的子数组应是最短的,请输出它的长度. 示例 1: 输入: ...

  10. Java实现 LeetCode 432 全 O(1) 的数据结构

    432. 全 O(1) 的数据结构 实现一个数据结构支持以下操作: Inc(key) - 插入一个新的值为 1 的 key.或者使一个存在的 key 增加一,保证 key 不为空字符串. Dec(ke ...