首页 > 其他分享 >Codeforces Round 920 (Div. 3)

Codeforces Round 920 (Div. 3)

时间:2024-01-16 22:11:08浏览次数:29  
标签:int Codeforces long -- solve ans 920 Div define

Codeforces Round 920 (Div. 3)

A - Square

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 5e5 + 10;


void solve()
{		
	map<int,int> x;
	map<int,int> y;																					
	for(int i=0;i<4;i++)
	{
		int a,b;
		cin >> a >> b;
		x[a]++;
		y[b]++;
	}
	vector<int> path1,path2;
	for(auto [x,y]:x) path1.push_back(x);
	for(auto [x,y]:y) path2.push_back(x);
	cout << abs(path1[1]-path1[0])*abs(path2[0]-path2[1])<<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}

B - Arranging Cats

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 5e5 + 10;


void solve()
{		
	int n;
	string a,b;
	cin >> n;
	cin >> a >> b;
	int ans = 0;
	int cnt1=0,cnt2=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]=='1'&&b[i]=='0') cnt1++;
		else if(a[i]=='0'&&b[i]=='1') cnt2++;
	}
	cout << max(cnt1,cnt2) <<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}

C - Sending Messages

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 5e5 + 10;
int a[N];

void solve()
{		
	int n,f,c,b;
	cin >> n >> f >> c >>b;
	for(int i=1;i<=n;i++) cin >> a[i];
	a[0] = 0;
	for(int i=1;i<=n;i++){
		int cnt = min((a[i]-a[i-1])*c,b);
		f -= cnt;
		//cout << cnt << " " <<f<<endl;
		if(f<=0){
			cout<<"NO"<<endl;
			return;
		}
	}
	cout <<"YES"<<endl;
	
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}

D - Very Different Array

好丑陋的code

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 2e5 + 10;
int b[N];
int c[N];

void solve()
{		
	int n,m;
	cin >> n >> m;
	deque<int> a;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin >> x;
		a.push_back(x);
	}
	for(int i=1;i<=m;i++) cin>>b[i];
	sort(b+1,b+1+m);
	sort(a.begin(),a.end());
	int l = 1, r = m;
	int ans = 0;
	while(a.size())
	{
		int x,y,z,q;
		x = abs(a.front()-b[l]);
		y = abs(a.front()-b[r]);
		z = abs(a.back() -b[l]);
		q = abs(a.back() -b[r]);
		int qq=max({x,y,z,q});
		if(x==qq&&x==y){
			ans +=x ;
			r--;
			a.pop_front();
		}else if(z==qq&&z==q){
			ans += z;
			l++;
			a.pop_back();
		}else if(x==qq&&y!=x){
			ans += x;
			l++;
			a.pop_front();
		}else if(y==qq&&x!=y){
			ans += y;
			r--;
			a.pop_front();
		}else if(z==qq&&z!=q){
			ans +=z;
			l++;
			a.pop_back();
		}else if(q==qq&&z!=q){
			ans += q;
			r--;
			a.pop_back();
		}
	}
	cout << ans <<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}

E - Eat the Chip

  1. 一个移动一次一定会往上移动一行 一个移动一定会往下移动一行
  2. 所以谁能赢跟行差的奇偶有关
  3. 赢不了的那个一定会往两边跑争取不输
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve()
{		
	int h,w,x1,y1,x2,y2;
	cin >> h >> w >> x1 >> y1 >> x2 >> y2;
	if(x1>=x2)
	{
		cout << "Draw" <<endl;
		return;
	}
	int len = x2 - x1 - 1;
	if(len&1)
	{
		int cnt = len/2 + 1;
		int l1 = max(1ll,y1-cnt);
		int r1 = min(w,y1+cnt);
		int l2 = max(1ll,y2-cnt);
		int r2 = min(w,y2+cnt);
		if(l2<=l1&&r2>=r1)
		{
			cout << "Bob" <<endl;
			return;
		}
		else
		{
			cout << "Draw" <<endl;
		}
	}
	else
	{
		int cnt = len/2;
		int l1 = max(1ll,y2-cnt);
		int r1 = min(w,y2+cnt);
		cnt++;
		int l2 = max(1ll,y1-cnt);
		int r2 = min(w,y1+cnt);
		if(l2<=l1&&r2>=r1)
		{
			cout << "Alice" <<endl;
			return;
		}
		else
		{
			cout << "Draw" <<endl;
		}
	}
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}

F. Sum of Progression

又是被分治腐乳的一天

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 1e5 + 10;

void solve()
{		
	int n,q;
	cin >> n >> q;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++) cin >>a[i];

	vector<vector<int>> pre(n*2,vector<int>(220));
	vector<vector<int>> sum(n*2,vector<int>(220));
	
	for(int d=1;d<=200;d++)
	{
		for(int i=1;i<=n;i++)
		{
			if(i-d<=0)
			{
				pre[i][d]=a[i];
				sum[i][d]=a[i];
			}
			else
			{
				int k=i/d;
				if(i%d) k++;
				pre[i][d]=pre[i-d][d] + a[i]*k;
				sum[i][d]=sum[i-d][d] + a[i];
			}
		}
	}
	while(q--)
	{
		int s,d,k;
		cin >> s >> d >> k;
		int ans = 0;
		if(d>200)
		{
			for(int i=0;i<k;i++)
				ans += a[s+i*d]*(i+1);
		}
		else
		{
			if(s-d<0)
			{
				ans = pre[s+(k-1)*d][d];
			}
			else
			{
				ans = pre[s+(k-1)*d][d] - pre[s-d][d];
				int z = s/d-1;
				if(s%d) z++;
				ans -= (sum[s+(k-1)*d][d]-sum[s-d][d])*z;
			}
		}
		cout << ans <<" ";
	}	
	cout << endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}

标签:int,Codeforces,long,--,solve,ans,920,Div,define
From: https://www.cnblogs.com/zfxyyy/p/17968666

相关文章

  • Codeforces Round 920 (Div. 3)
    目录写在前面ABCDEFG写在最后写在前面比赛地址:https://codeforces.com/contest/1921写完C题去泡了个面边吃边看D,吃着吃着不对劲味儿怎么这么冲一看过期两个月了我草以及div3都AK不了了呃呃博弈论把我鲨了还剩最后一门近代史,周四才考,开摆!感觉除了离散可能有点拉其他都......
  • Codeforces Round 920 (Div. 3)
    基本情况A、C秒的很快。B、D都错了一发才过。E博弈论属于是短板。E.EattheChipProblem-E-Codeforces首先考虑谁可能赢。因为\(Alice\)只能向下,\(Bob\)只能向上,而\(Alice\)先手。显然两者行差为奇数时\(Alice\)有可能赢,偶数时\(Bob\)有可能赢。再考虑平......
  • Codeforces Round 920 (Div. 3) D Very Different Array
    DVeryDifferentArray题意给出两个长度分别为\(n,m\)的数组\(a,c\),\(n<m\),从\(c\)中选择\(n\)个数并找到一个序列使得\(D=\sum_{i=1}^{n}|a_i-c_i|\)尽可能大,求D的值思路假设如果\(m\)和\(n\)一样大,那么找到这个序列的方法很简单:将两个序列分别排序后将其中一个转置,......
  • hey_left 3 Codeforces Round 918 (Div. 4) 再续
    题目链接F.找了些题解,但都看的不是很懂先去又梳理了一遍堆优化版的dij每次用当前可到达的最小的边去进行松弛操作标记数组,若该点已经加入确定点集,就跳过别忘了dist[]数组初始化为无穷大,这样才会全部都被更新#definelllonglongconstintinf=0x3f3f3f3f;constintN=1e......
  • CodeForces 1500C Matrix Sorting
    洛谷传送门CF传送门做了好久。怎么会是呢。题目的操作可以看成,求出一些关键字,使得\(B\)矩阵的行是由\(A\)按照这些第\(1\)关键字、第\(2\)关键字一直到第\(k\)关键字,最后还有一个原来所在行下标的关键字,从小到大排序。肯定是从排好序的\(B\)矩阵入手。首先任意找......
  • abc336 E - Digit Sum Divisible 题解 数位DP
    题目链接:https://atcoder.jp/contests/abc336/tasks/abc336_e题目大意:我们定义一个整数\(n\)的数位和为\(n\)的十进制表示中的各位上的数字之和。比如:整数\(2024\)的数位和为\(2+0+2+4=8\)。一个正整数\(n\)被称作一个好数如果\(n\)能被它的数位和整除......
  • CF1818B ndivisible 题解
    题意简述构造一个长度为\(n\)的排列\(A\),使得对于任意的\(l,r\)(\(1\lel<r\len\))都满足\(A_l+A_{l+1}+⋯+A_r\)不可以被\(r-l+1\)整除。输出其中一种合法排列即可。解题思路构造题。考虑对\(n\)进行分类讨论:当\(n=1\)时,由样例即可得合法排列为\(1\)......
  • CodeForces 1266F Almost Same Distance
    洛谷传送门CF传送门好厉害。特判\(k=1\)。首先经过观察,我们可以按照\(k\)的奇偶性讨论:\(k\)为偶数,有一个中心点挂了若干条长度为\(\frac{k}{2}\)的链。\(k\)为偶数,有两个中心点,两边挂了若干条长度为\(\frac{k}{2}\)的链;\(k\)为奇数,有一个中心点挂了若干条长度......
  • hey_left 2 Codeforces Round 918 (Div. 4) 续
    题目链接F.常规的树状数组求逆序对需要注意的是,因为是下标与值的映射,所以数值不能为负数,也不能太大然后传参数的时候,参数是最大数值切记切记#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;template<typenameT>structTreeArray{vector<T>t......
  • Codeforces Round 919 (Div. 2)(A~D) 题解
    CodeforcesRound919(Div.2)(A~D)题解A.SatisfyingConstraints题意:给你一些条件让你求出满足条件的整数有多少个。模拟即可。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constllMAXN=2e5+5;llTex=1,n;voidAC(){ cin>>n; lll=......