Codeforces Round #648 (Div. 2)
链接 : 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)的更多相关文章
- Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value(鸽巢原理)
题目链接:https://codeforces.com/problemset/problem/1365/E 题意 有 $n$ 个元素,定义大小为 $k$ 的集合值为 $\sum2^i$,其中,若集合内 ...
- Codeforces Round #648 (Div. 2) D. Solve The Maze
这题犯了一个很严重的错误,bfs 应该在入队操作的同时标记访问,而不是每次只标记取出的队首元素. 题目链接:https://codeforces.com/contest/1365/problem/D ...
- Codeforces Round #648 (Div. 2) C. Rotation Matching
题目链接:https://codeforces.com/contest/1365/problem/C 题意 有两个大小为 $n$ 的排列,可以循环左移或右移任意次,问最多有多少对同一值在同一位置. 题 ...
- Codeforces Round #648 (Div. 2) B. Trouble Sort
一开始读错题了...想当然地认为只能相邻元素交换...(然后换了两种写法WA了4发,5分钟切A的优势荡然无存) 题目链接:https://codeforces.com/contest/1365/pro ...
- Codeforces Round #648 (Div. 2) A. Matrix Game
题目链接:https://codeforces.com/contest/1365/problem/A 题意 给出一个 $n \times m$ 的网格,两人轮流选择一个所在行列没有 $1$ 的方块置为 ...
- Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value 贪心
题意:E.Maximum Subsequence Value 题意: 给你n 个元素,你挑选k个元素,那么这个 k 集合的值为 ∑2i,其中,若集合内至少有 max(1,k−2)个数二进制下第 i 位 ...
- Codeforces Round #648 (Div. 2) F. Swaps Again
题目链接:F.Swaps Again 题意: 有两个长度为n的数组a和数组b,可以选择k(1<=k<=n/2)交换某一个数组的前缀k和后缀k,可以交换任意次数,看最后是否能使两个数组相等 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- dij+DP
众所周知,蒜蒜是一名热爱工作的好员工,他觉得时间就是金钱,做事情总是争分夺秒. 这天晚上,蒜蒜一个人去吃晚饭.不巧的是,吃完饭以后就开始下雨了,蒜蒜并没有带雨伞出来.但是蒜蒜热爱工作,工作使他快乐,他 ...
- 填坑!线上Presto查询Hudi表异常排查
1. 引入 线上用户反馈使用Presto查询Hudi表出现错误,而将Hudi表的文件单独创建parquet类型表时查询无任何问题,关键报错信息如下 40931f6e-3422-4ffd-a692-6c ...
- Redis学习笔记(十五)Sentinel(哨兵)(中)
上一篇 我们模拟了单机器下哨兵模式的搭建,那么接下来我们看下哨兵模式的实现与工作. 为什么又分成两篇呢?因为篇幅太长(偷懒),再一个这篇主要说的是Sentinel的初始化以及信息交换,下一篇着重说下状 ...
- Eclipse中java文件选中变量名,相同变量都变色显示 .
第一步设置高亮显示的颜色: Window-->preferences-->General-->Editors-->Text Editors-->Annotations-- ...
- [Android应用开发] 02.界面展现和文件权限
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- php mysqli使用
连接到数据库$mysqli = new mysqli(主机,用户,密码,数据库); 选择数据库$mysqli->select_db(数据库);设置编码$mysqli->set_charse ...
- Parrot os笔记本推荐
parrot os基于debian开发的,因此同样适用于其他linux:笔记本集显最好,linux直接适用于intel,不用手动切换显卡,大多数linux玩家及pentester不需要高性能显卡,当然 ...
- OAuth + Security -1 - 认证服务器配置
配置 基础包依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...
- 【Socket通信】关于Socket通信原理解析及python实现
Socket(套接字)通信{网络通信其实就是Socket间的通信},首先了解下概念:[来源于百度百科] "两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.& ...
- ASP.NET通过EntityFramework CodeFirst创建数据库
Number1 新建一个项目 给新项目添加一个实体数据模型 选择第三个 这里我创建两个有关系的类,也就是有外键关系的数据库表 using System; using System.Collection ...