开始补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. lua中self的意义

    原文链接 最近在用合宙的Air302开发物联网项目,因为合宙用的自家的luatOS操作系统,二次开发全都要用lua写,据说lua写起代码比C更方便,但是不会就是不会啊喂!!学不会就是不方便啊,例如这个 ...

  2. 解决eclipse创建动态Web项目没有Web->Dynamic Web Project问题

    有时候在eclipse新建Dynamic Web Project,File->New->Other->Web并没有发现Dynamic Web Project选项如下图:(那也不要慌解 ...

  3. iOS源码调试Podspec如何写

    { "name": "XXX", "version": "1.0.0", "summary": &q ...

  4. WPF_MahApps.Metro界面主题使用

    一.创建WPF项目: 二.下载MahApps.Metro: 三.修改MainWindow.xaml 1.添加一栏: xmlns:mah="clr-namespace:MahApps.Metr ...

  5. 使用SonarQube对Unity项目进行代码分析的问题记录

    1.这里不仔细描述每个步骤,只记录一些关键问题,到官网下载解压最新版的SonarQube(我用的是8.9.1). 2.下载安装jdk,这里要注意官网的说明,我一开始下的jdk16,启动Sonar后报错 ...

  6. ubuntu 安装错误解决

    1. ubuntu 安装错误解决: Preparing to unpack .../apport_2.20.9-0ubuntu7.15_all.deb .../var/lib/dpkg/info/ap ...

  7. 3、一个简单的Java应用程序

    /* 1.Java中区分大小写,如果出现了大小写拼写错误,例如将main拼写成Main,则程序将无法运行. 2.关键字public成为访问修饰符,用来控制程序的其他部分对这段代码的访问级别. 3.关键 ...

  8. jetson TX2 + opencv3.4 + python3 + 双目 +人脸检测

    淘宝看到一款很便宜的双目,150元,就买了.想着用它学习一下opencv,好换个工作.当然,也想着能否用它做一些好玩的,比如三维重建之类高大上的东西.先用便宜的入个门,等以后眼界高了再看是不是买那些更 ...

  9. RabbitMQ博文收藏

    RabbitMQ基本概念 消息队列之 RabbitMQ

  10. mysql80解决不支持中文的问题

    1.查看mysql80字符集 show variables like 'character_set%'; 2.修改server编码格式 在mysql安装目录下找到my-default.ini文件并复制 ...