开始补cf了,还是记录一下,加深思路,打的应该都是div2。题面不截图了,直接说题意,思路,代码。

A

题意:给一个01矩阵,两个人轮流填格子,仅当第i行,第j列全为0时才能填,不能填的人输,问谁赢?Ashish先手,Vivek后手。

思路:记录全为零的行列即可,看能填的位置有几个,奇数个先手赢。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((-x)&x)
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 258280327;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
int a[55], b[55];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while(T--){
met(a, 0); met(b, 0);
int n, m; cin >> n >> m;
rep(i, 1, n){
rep(j, 1, m){
int x; cin >> x;
if(x) a[i] = b[j] = 1;
}
}
int ans = 0;
rep(i, 1, n){
rep(j, 1, m){
if(a[i] + b[j] == 0){
ans++;
a[i] = b[j] = 1;
break;
}
}
}
if(ans % 2 == 1) cout << "Ashish" << endl;
else cout << "Vivek" << endl;
}
return 0;
}

B

题意:给你长度为n的数组a和b(b数组是01数组),问你能否交换一些数的位置使得a数组最后从小到大排列。当b[i]!=b[j]时可以交换a[i]和a[j]。

思路:发现只要有一堆1里面有个0或者一堆0里面有一个1就能随便交换。如果全是0或者全是1,但是已经是非降序的了也可以。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((-x)&x)
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 258280327;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
int a[550];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while(T--){
int n; cin >> n;
rep(i, 1, n) cin >> a[i];
int num1 = 0, num0 = 0;
rep(i, 1, n){
int x; cin >> x;
if(x) num1 = 1;
else num0 = 1;
}
int flag = 1;
rep(i, 2, n){
if(a[i] < a[i-1]) {
flag = 0;
break;
}
}
if(flag || (!flag && num0 && num1)) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}

C

题意:给你一个1~n的一个排列数组a,一个1~n的一个排列数组b,可以整体随意左右移动(相当于循环的),问最多有几个对应位置相等。1 2 3 和3 2 1,就第二个位置相等,都是2,移动后也是只能有一个。

思路:一看n是2e5,还是C题,肯定是线性复杂度了,然后自己写几个例子,1 3 4 2和2 1 4 3。

最佳匹配意识到一个数字在ab数组中的位置差就是当前要移动的步数,(b数组往右移动1个和往左移动3效果一样,因为是循环的),我们同一让b数组往右移动,用一个数组记录所有每对数字匹配上时b数组需要往右移动多少。这样相当于遍历了所有情况。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((-x)&x)
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 258280327;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-10;
const int maxn = 2e5 + 5;
int a[maxn], b[maxn], cnt[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
rep(i, 1, n){
int x; cin >> x;
a[x] = i;
}
rep(i, 1, n){
int x; cin >> x;
b[x] = i;
}
int ans = 1;
rep(i, 1, n){
ans = max(ans, ++cnt[(n+a[i]-b[i])%n]);
}
cout << ans << endl;
return 0;
}

D

题意:给一个n*m图,B是坏人,G是好人, ‘.’表示空,‘#’表示墙,右下角是出口,每个人只能在图中上下左右移动,问能否使一些'.’变成'#'使得所有好人都能出去,所有坏人都出不去。

思路:首先想到如果好人坏人挨着,那要么都能出去,都不能出去,肯定不行。再想其实就是好人和坏人不能互相访问到,怎么样才行?把坏人用墙围一圈不就行了么?在这个基础上再判断一下好人是否都能出去。

为什么可以?思考一下如果存在一中方法是所有坏人都不能访问到好人,并且好人都能出去,那么在这个基础上再把坏人围一圈仍然成立,如果因为围的墙把好人出去的路挡住了,说明没有这个墙坏人就能访问到好人了,因此成立。

围好之后从n,m点出发bfs看是不是和所有好人都连通了就行。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((-x)&x)
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 258280327;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
char ma[55][55];
bool vis[55][55];
int flag;
struct node{
int x, y;
};
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0}; int bfs(int x, int y){
if(ma[x][y] == '#') return 0;
met(vis,0); int num = 0;
vis[x][y] = 1;
queue<node> q;
q.push((node){x, y});
while(!q.empty()){
node now = q.front();
q.pop();
rep(i, 0, 3){
int nx = now.x + dx[i];
int ny = now.y + dy[i];
if(vis[nx][ny]) continue;
if(ma[nx][ny] == 'G' || ma[nx][ny] == '.'){
if(ma[nx][ny] == 'G') num++;
vis[nx][ny] = 1;
q.push((node){nx, ny});
}
}
}
return num;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while(T--){
met(ma, 0);
int n, m; cin >> n >> m;
rep(i, 1, n) cin >> (ma[i]+1);
flag = 1;
int ans = 0;
rep(i, 1, n){
rep(j, 1, m){
if(ma[i][j] == 'B'){
if(ma[i-1][j] == 'G' || ma[i+1][j] == 'G' || ma[i][j+1] == 'G' || ma[i][j-1] == 'G'){
flag = 0;
}
if(ma[i-1][j] == '.') ma[i-1][j] = '#';
if(ma[i+1][j] == '.') ma[i+1][j] = '#';
if(ma[i][j+1] == '.') ma[i][j+1] = '#';
if(ma[i][j-1] == '.') ma[i][j-1] = '#';
}
if(ma[i][j] == 'G') ans++;
}
}
if(!flag){
cout << "No" << endl;
continue;
}
if(bfs(n, m) == ans) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}

E

题意:给你n个数,任意选几个数组成一个新数组,该元素为k的数组值是:如果第x个二进制有 >=max(1, k-2)个元素该二进制位是1,那个数组的值加上2^x。

思路:说的是用到鹊巢原理,不知道也不影响。一看这个max(1, k-2),发现如果选三个数,那数组的值不就是 (a | b | c)吗?再考虑大于3个的,担心如果abc在某个二进制位下都为0,有没有可能多加入该位都是1的个元素使数组的值变大?不可能,因为至少要有n-2个该位上都为1,abc都3个了,故不可能。如果存在一种方案最优解元素大于3个,其实也能由3个元素表示。因为某个二进制位要贡献答案,最多有2个不为1,所以我们选的3个元素一定可以。这也就是鹊巢原理。

枚举一下abc取个max(a|b|c)就行了。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((-x)&x)
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 258280327;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-10;
const int maxn = 2e5 + 5;
ll a[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll ans = 0, n; cin >> n;
rep(i, 1, n) cin >> a[i];
rep(i, 1, n){
rep(j, i+1, n){
rep(k, j+1, n){
ans = max(ans, a[i] | a[j] | a[k]);
}
}
}
cout << ans << endl;
return 0;
}

F

题意:给你一个长度为n的a数组,每次可以选择一个k<=n/2,把前k个和后k个交换,问能否变成b数组。比如 1 2 3 4,k = 2,让前两个和后两个换一下:3 4 1 2。

思路:还是画一画,因为这个题是对称交换,很难不去找对称的有什么性质,发现a[i]和a[n-i+1]这对就像cp,是成对的。并且可以以任意前后顺序出现在数组中。就是比如a[1]=1, a[4]=1,也可以交换成a[1]=4,a[4]=1。这个14就是对cp,也能变到中间,a[2]=1,a[3]=4或者a[2]=4,a[3]=1。剩下的就好办了,记录两个数组所有的cp随便找个顺序排一下,比较一下是否cp相等。

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((-x)&x)
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define bep(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define debug cout << "KKK" << endl
#define ls num*2
#define rs num*2+1
#define re return
using namespace std;
const ll mod = 258280327;
const double PI = acos(-1);
const ll INF = 2e18+1;
const int inf = 1e9+5;
const double eps = 1e-10;
const int maxn = 500 + 5;
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int rd(){
int x = 0; char ch = gc(); bool positive = 1;
for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0;
for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0';
return positive ? x : -x;
} struct node{
int x, y;
bool operator <(const node & a)const{
if(x != a.x) return x < a.x;
return y < a.y;
}
}p1[maxn], p2[maxn]; int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = rd();
while(T--){
int n = rd();
vector<int> v1, v2;
v1.pb(-1), v2.pb(-1);
rep(i, 1, n) v1.pb(rd());
rep(i, 1, n) v2.pb(rd());
rep(i, 1, n/2){
if(v1[i] > v1[n-i+1]) swap(v1[i], v1[n-i+1]);
p1[i] = (node){v1[i], v1[n-i+1]};
if(v2[i] > v2[n-i+1]) swap(v2[i], v2[n-i+1]);
p2[i] = (node){v2[i], v2[n-i+1]};
}
sort(p1+1, p1+1+n/2);
sort(p2+1, p2+1+n/2);
int flag = 1;
rep(i, 1, n/2){
if(p1[i].x != p2[i].x || p1[i].y != p2[i].y) flag = 0;
}
if(n % 2 == 1 && v1[n/2+1] != v2[n/2+1]) flag = 0;
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}

Codeforces Round #648 (Div. 2) A~F题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  4. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

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

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

  6. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  7. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  8. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  9. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

  10. Codeforces Round #615 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1294 A. 给出a.b.c三个数,从n中分配给a.b.c,问能否使得a = b = c.计算a,b,c三个数的差值 ...

随机推荐

  1. java 泛型使用

    泛型类 // 简单泛型 class Point<T>{ // 此处可以随便写标识符号,T是type的简称 private T var ; public T getVar(){ return ...

  2. js生成快速生成0~n的数组

    Object.keys(Array.from(Array(100)))

  3. 【Java】生成随机字符串

    package com.runsky.utils; import java.util.Random; public class GetRandom { private static final Str ...

  4. select from 多表和inner join的区别

    其实两者是一样的,inner join 只是为了区分left join和right join整出来的,本质还是逐行比较

  5. iOS包大小计算

    一.LinkMap文件分析 说明:LinkMap数据是根据文章<LinkMap文件分析>中方法实验实测数据. 如何获得LinkMap文件 1.在XCode中开启编译选项Write Link ...

  6. FATAL Exited too quickly (process log may have details)的解决方案

    作为一个混混的开发,不会啥容器操作.所以一般都是用supervisor来管理一些运行的进程 用了一段时间还是比较好用的,这个软件也是用的Python开发. 但在使用的过程中,status时会出现 FA ...

  7. 项目实训 DAY14

    今天修改了一下PNN使之可以运行直接生成图片,而不是敲两段命令行.首先是使用python中subprocess启动新进程来达到命令行输命令的效果,即生成xx.pdf:再用os.unlink将中间品删除 ...

  8. css/js使用小技巧记录

    1.白底小图标换色 .iconBox { position: relative; width: 19px; height: 19px; overflow: hidden; // 隐藏原本颜色的图片 . ...

  9. 通用CSS命名惯例

    通用的 CSS 命名惯例 在参与规模庞大.历时漫长.且参与人数众多的项目时,要确保每一行代码都像是同一个人编写的:这就要求所有开发者,都遵守相同的代码规范.在先前的文章前端项目开发规范意见,从宏观角度 ...

  10. WinCC插件制作教程

    目录 插件的编写 插件的使用 参考资料 Creation of .NET Controls 109759944_Prepare.NetControls_DOC_en.pdf 插件的编写 创建插件项目, ...