链接 : 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. 四、$jQuery

    1.你觉得jQuery或zepto源码有哪些写的好的地方 jquery源码封装在一个匿名函数的自执行环境中,有助于防止变量的全局污染,然后通过传入window对象参数,可以使window对象作为局部变 ...

  2. Python中ThreadLocal的理解与使用

    一.对 ThreadLocal 的理解 ThreadLocal,有的人叫它线程本地变量,也有的人叫它线程本地存储,其实意思一样. ThreadLocal 在每一个变量中都会创建一个副本,每个线程都可以 ...

  3. 接口参数校验(不使用hibernate-validator,规避大量if else)

    引言 编写接口时,常用的参数校验使用hibernate-validator注解+@@Validated注解进行参数校验.当遇到一些特殊场景或需求,需要自己对参数进行手动校验时,会出现以下问题: 不可避 ...

  4. 非常实用的织梦dede所有标签调用方法大全

    关键描述调用标签: <meta name="keywords" content="{dede:field name='keywords'/}">&l ...

  5. DEDE自增序号 自动增加数字序号 autoindex属性

    在DEDE的模板制作过程中经常会需要用到1,2,3,4....这样的排序方式,这个时候就需要用到DEDE自带的自增序号产生函数 1.按顺序从1开始 需要使用到 [field:global runphp ...

  6. MySQL性能分析(Explain)

    更多知识,请移步我的小破站:http://hellofriend.top 1. 概述 使用EXPLAIN关键字可以模拟优化器执行SQL查询语句,从而知道MySQL是如何处理你的SQL语句的.分析你的查 ...

  7. NOIP 2017 P3959 宝藏 (状态压缩DP板子)

    洛谷题目传送门!! 题目的N这么小,当然是选择用状压DP啦!  等等,我好像不会状缩.... 首先,我们当然是要写状态转移方程了!! 那么,如果我们设  f[s]  状态s下,所要的最小花费,那么很显 ...

  8. [工具-003]如何从ipa中提取info.plist并提取相应信息

    最近公司的产品要进行一次批量的升级,产品中的一些配置存放在info.plist,为了保证产品的信息无误,我们必须要对产品的发布信息进行验证.例如:广告ID,umeng,talkingdata等等.那么 ...

  9. 【补充说明】Gauge框架在JS中的简单应用

    这里做一个总结 由于公司架构要用node来替代Java的部分服务,所以就研究了这个自动化测试框架:它可以很方便的测试我们的接口,而且还能使用断言[assert]来判断是否是我们预期的结果. 但是呢,由 ...

  10. Java实现 LeetCode 622 设计循环队列(暴力大法)

    622. 设计循环队列 设计你的循环队列实现. 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环.它也被称为"环形缓冲器" ...