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 ...
随机推荐
- 07.django日志配置
https://docs.djangoproject.com/en/3.0/topics/logging/ https://yiyibooks.cn/xx/python_352/library/log ...
- 【Java】手把手模拟CAS,瞬间理解CAS的机制
话不多少,先看个案例,[模拟100个用户,每个用户访问10次网站]”: public class ThreadDemo1 { //总访问量 ; //模拟访问的方法 public static void ...
- 【Oracle】CentOS7/CentOS8命令行安装Oracle 11G R2
写在前面 很长一段时间内,国内互联网公司都在提倡"去IOE",但是很多企业还是愿意为昂贵的Oracle数据库买单,不少读者所在的公司也在用Oracle,很多读者自行安装Oracle ...
- Java——关键字instanceof
instanceof 判断一个对象是否为一个类的实例,是为true ,否为false class Animal{} class Cat extends Animal{} /**instanceof 判 ...
- ExtJS定时和JS定时
ExtJS定时 //定时刷新待办事宜状态 var task={ run:function(){ //执行的方法或方法体 }, interval:5*60*1000 //5分钟 } //定时启动 Ext ...
- Unity实现写入json文件
using System.Collections; using System.Collections.Generic; using UnityEngine; using LitJson; using ...
- web自动化的一些基础知识
selenium 原理 就是通过webdriver 给浏览器的驱动发送命令,打开浏览器,建立http通信请求 然后通过发送各种命令让浏览器进而执行各种操作 xpath 语法 #xpath定位总结:'' ...
- 网络编程杂谈之TCP协议
TCP协议属于网络分层中的传输层,传输层作用的就是建立端口与端口的通信,而其下一层网络层的主要作用是建立"主机到主机"的通信,所以在我们日常进行网络编程时只要确定主机和端口,就能实 ...
- CORS漏洞利用检测和利用方式
CORS全称Cross-Origin Resource Sharing, 跨域资源共享,是HTML5的一个新特性,已被所有浏览器支持,不同于古老的jsonp只能get请求. 检测方式: 1.curl访 ...
- burpsuite 2.0beta体验
这里有破解版:http://ximcx.cn/post-110.html 一直再用1.7x版本,2.0的还没怎么用过 移除了 Scanner 和spider 选项卡,全部整理到Dashboard里 代 ...