首页 > 其他分享 >Codeforces Round 864 (Div. 2)

Codeforces Round 864 (Div. 2)

时间:2023-04-10 23:22:27浏览次数:46  
标签:cnt no 打印 864 Codeforces Div include yes

Codeforces Round 864 (Div. 2)

题目链接

Codeforces Round 864 (Div. 2)

A题

这个题是一个思维题稍微想一下应该就可以解决.

1.我们可以发现如果点(x,y)位于正方形的四个角上把这个点围起来需要两次操作

2.如果点(x,y)在正方形的4条边上,需要3个操作将其其围起来

3.如果点(x,y)在其他地方需要4个操作将其围起来

我们求出两个坐标的最小值打印出来就可以

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 100008;
int n, m;
int length(int x, int y) {
	if ((x == 1 && y == 1) || (x == 1 && y == m) || (x == n && y == 1) || (x == n && y == m)) { //4个点
		return 2;
	} else if (x == 1 || y == 1 || x == n || y == m) { //除去4个点的4条边

		return 3;
	} else {
		return 4;//其他情况
	}


}
void solve() {

	scanf("%lld %lld", &n, &m);
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << min(length(x1, y1), length(x2, y2)) << '\n'; //求出x1,y1和x2,y2的最小值



}
signed main () {
	int t;
	cin >> t;
	while (t) {
		solve();
		t--;
	}


	return 0;
}

B题

1.先将这个图形变成翻转180度可以重合的图形,如果两个点(x1,y1)(x2,y2)关于点(x,y)对称的话,(x1+x2)/2=x,(y1+y2)/2=y.记录需要的次数cnt

2.如果k<cnt的话是不可能得到结果的打印NO

3.如果cnt>=k计算(cnt-k)%2==0的话,说明可以多操作偶数次打印yes

4,如果(cnt-k)%2==1的话,分情况讨论,如果n为奇数打印yes,因为最中心可以操作一次,如果n为偶数打印no

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
//#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 1004;
int n, k;
int a[N][N];
int number(double x, double y) {
	int cnt = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[i][j] == 0 && a[(int)round(2 * x - i)][(int)round(2 * y) - j] == 1) {//遍历点(i,j)找到旋转180度对应的点(2 * x - i,2 * y - j);
				cnt++;//统计次数
				a[(int)round(2 * x - i)][(int)round(2 * y) - j] = 0;//将对称点设置为0
			}


		}
	}
	return cnt;//返回cnt


}
void solve() {

	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	int ans = 0;
	double x, y;
	x = (n + 1) * 1.0 / 2.0;//可以发现边长为n的正方形的对称点为点((n+1)/2.0,(n+1)/2.0)
	y = (n + 1) * 1.0 / 2.0;
	ans = number(x, y);//得到答案
//	for (int i = 1; i <= n; i++) {
//		for (int j = 1; j <= n; j++) {
//			printf("%d ", a[i][j]);
//		}
//		cout<<'\n';
//	}
//	cout<<ans<<'\n';
	if (ans > k) {//如果答案大于k打印no
		no;

	} else {
		if (n % 2 == 1) {//如果n为奇数无论什么情况都打印yes
			yes;
		} else {
			if ((k - ans) % 2 == 0) {//否则如果(k-ans)%2==0的时候&&n%2==0的时候打印yes
				yes;
			} else {
				no;//否则打印no

			}
		}

	}





}
signed main () {
	int t;
	cin >> t;
	while (t) {
		solve();
		t--;
	}


	return 0;
}

标签:cnt,no,打印,864,Codeforces,Div,include,yes
From: https://www.cnblogs.com/harper886/p/17304715.html

相关文章

  • 洛谷与 Codeforces 的难度评级
    为了比较CF与洛谷的题目难度评级,我写了一个爬虫,爬取了CF题目在源站和洛谷中的难度,并进行比较。这里先给出两者的换算:洛谷入门普及-普及/提高-普及+/提高提高+/省选-省选/NOI-NOI/NOI+/CTSCCF800900-11001200-15001600-19002000-23002400-29003000-350......
  • Codeforces Round 677 (Div. 3) E. Two Round Dances(数论)
    https://codeforces.com/contest/1433/problem/E题目大意:n个人(n是偶数)跳了两轮舞,每轮舞正好有n/2个人。你的任务是找出n个人跳两轮舞的方法,如果每轮舞正好由n/2个人组成。每个人都应该属于这两种圆舞中的一种。人相同位置不同也算是同一种方案。input2output1input......
  • Codeforces Round 864 (Div. 2)
    题解报告基本的一些理解和问题都在注释中A:LiHuaandMaze就是判断把其中一个点围起来所需要的最小的格子,考虑下边界的情况就行了#include<bits/stdc++.h>usingnamespacestd;intmain(void){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);intT;c......
  • Codeforces Round 864 (Div. 2) E. Li Hua and Array
    CodeforcesRound864(Div.2E.LiHuaandArray)(暴力修改线段树+lca和数论的结合)Exampleinput5481637215234113234output1021Solution首先你得知道什么是欧拉函数我们\(O(n)\)求出\([1,5e6]\)范围内的每个数的欧拉函数后可以求一下最大的跳......
  • cf-div2-856c
    题目链接:https://codeforces.com/contest/1816/problem/C我是傻逼,否了自己的第一直觉。。。思路:构造方法:以最后一个值的数值\(x\)为基准,把所有的的数字(除第一个)调整为\(x\)。以n的奇偶性分为两种情况。当n为奇数时:\(第一个数字y小于等于x,构造成功。否则就除了第一个数字外......
  • Codeforces Round 863 (Div. 3)
    题解报告基本的一些理解和问题都在注释中A:InsertDigit找到第一个小于输入数字的数的位置塞进去就好了,可以细推,但是粗略想想也能知道#include<bits/stdc++.h>usingnamespacestd;intmain(void){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int......
  • Codeforces Round 865 (Div. 2)
    CodeforcesRound865(Div.2)A.IanVisitsMaryvoidsolve(){intx=read(),y=read();if(__gcd(y,x)!=1){cout<<2<<endl;cout<<1<<""<<y-1<<endl;cout<<x<<"&q......
  • 练习记录-cf-div2-865(A-C)
    反转就是写的非常烂Awa10其他还行吧丢人A.IanVisitsMary如果这两个数的gcd是1可以直接过去如果是0那就绕一个1过去变成三角形不然就用(1,b-1)到(a,1)这样就是两次的1不会遇到#include<bits/stdc++.h>#defineclosestd::ios::sync_with_stdio(false),cin.ti......
  • Codeforces Round 864 (Div. 2) C和D
    比赛地址C.LiHuaandChess题意:给出一个棋盘长宽n,m,有一颗棋子在棋盘上,向八个方向走一步的路程代价都为1,现在进行最多3次询问,问能否确认棋子的位置Solution第一次做交互题,想很好想,先询问(1,1),得到x,再询问(1+x,1+x),得到y,最后询问(1+x,1+x-y),如果得到的是0,则输出这个点,反之输......
  • 练习记录-cf-div2-856(A-C)
    vp的写出4道C感觉目前不是能力范围以后有机会留下来打比赛的话再说A-PrefixandSuffixArray给出字符串的前缀和后缀问是不是回文 我采用枚举长度为n-1和1的拼凑但是这并不奏效一直wa3后来改用拼两个n/2的就过了如果有大佬看到了希望能解答一下qwq#include<b......