首页 > 其他分享 >Codeforces Round 960 (Div. 2) A - D

Codeforces Round 960 (Div. 2) A - D

时间:2024-07-21 12:40:12浏览次数:4  
标签:... 960 int bucket Codeforces cin re tie Div

link

image

好图好图 qwq

这次也是终于装上插件 codeforces better! 了,妈妈再也不用担心我的英语啦


A - Submission Bait

A 先手,B 后手,优先往奇偶性的方向想

一开始我只是单纯考虑 A 总是选最大值的数的奇偶性,样例过了?交上去发现 wa 2

然后恼 ... 瞎搞了个 3 3 3 4 4,发现 A 可以先选 3 则必赢,

咦?如果所有偶数位都只能按照 B -> A,B -> A ... 这样后手一定在 A 上,则 A 必赢

考虑从大到小,有多个 ai 是偶数个,aj 为 第一个 是奇数个的数,那么走一次 aj,B 就只能往更大的数走,但是更大的数都是偶数个,这样就必赢

也就是说,只要有这个 aj 存在就一定能赢,所以,这题的结论就是判断是否(一开始我有考虑多个奇数个数是否影响结论,但这显然不会,因为 A 可以总是选最大的那个,也就是 aj,这样比它小的就没吊用)有奇数个的数即可

code
#include <bits/stdc++.h>
#define re register int 

using namespace std;
const int N = 100;

int T, n, a[N], bucket[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> T;
	while (T --)
	{
		cin >> n;
		
		for (re i = 1; i <= N; i ++) bucket[i] = 0;
		
		for (re i = 1; i <= n; i ++)
		{
			cin >> a[i];
			bucket[a[i]] ++;
		}
		int ji = 0, ou = 0;
		for (re i = 1; i <= N; i ++)
		{
			if (bucket[i] == 0) continue;
			if (bucket[i] % 2 == 0) ou ++;
			else
			{
				ji ++;
			}
		}
		
		cout << (ji ? "Yes" : "No") << '\n';
	}
	
	return 0;
}

B - Array Craft

烦死了这题,没看到 y < x,一直按照 1 ≤ x < y ≤ n 做就不知道为什么一直 wa,要认真审题呀!

构造题

题意就是要构造两个函数,

使 prefix 的最大值区间左界为 x,suffix 的最大值区间右界在 y

image

构造的话,就很显然了

[1, y) 和 (x, n] 可以直接弱化为常数函数,也就是 1, -1, 1 ... 交替

中间一种可行的构造就是保证从左往右单调递增,从右往左也单调递增,那么 [y, x] 全部为 1

注意:在交界处,不能使两个 1 相邻,这样就会拓展出去,

所以必须是 ... 1, -1, 1(y), 1, ... 1, 1(x), -1, 1 ...

code
#include <bits/stdc++.h>
#define re register int 

using namespace std;
const int N = 1e5 + 10;

int T, n, x, y;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> T;
	while (T --)
	{
		cin >> n >> x >> y;
		
		int l = y - 1, r = n - x;
		if (l % 2) 
			for (re i = 1; i <= y - 1; i ++) cout << (i % 2 ? -1 : 1) << ' ';
		else  
			for (re i = 1; i <= y - 1; i ++) cout << (i % 2 ? 1 : -1) << ' ';
		
		for (re i = y; i <= x; i ++) cout << 1 << ' ';
		
		for (re i = x + 1, p = 1; i <= n; i ++) cout << (p ++ % 2 ? -1 : 1) << ' ';
			
		cout << '\n';
	}
	
	return 0;
}

C - Mad MAD Sum

似乎就是简单枚举?那就摸几个样例看看性质

  • 显然的,发现 \(\forall\) b[] ,数组中的数 从左往右是单调不降的

  • 好像还有一种三角形性质?

不关心 a[],它的贡献仅仅是一开始的累加 \(ans += \sum\limits_{i = 1}^{n}a_i\),比如第一个 b[]:0 1 1 2 3 3 4 4 4

b1: 0 1 1 2 3 3 4 4 4
b2: 0 0 1 1 1 3 3 4 4
b3: 0 0 0 1 1 1 3 3 4
b4: 0 0 0 0 1 1 1 3 3
b5: 0 0 0 0 0 1 1 1 3
b6: 0 0 0 0 0 0 1 1 1
b7: 0 0 0 0 0 0 0 1 1
b8: 0 0 0 0 0 0 0 0 1
b9: 0 0 0 0 0 0 0 0 0

三角形这个性质好啊!发现这里的贡献可以分为两种:

  • 一种是边界形似三角形的数,比如 1,它实际的贡献其实是不规则的,但因为单调不降的性质,我们可以先把它直接当做整个三角形累加,后边减去相应的数 pre 再累加贡献即可

  • 一种是孤立的点,比如 2,那贡献就是它本身,注意也要减去 pre,但是注意,单点是不会传递为 pre 的

code
#include <bits/stdc++.h>
#define re register int 

using namespace std;
typedef long long LL;
const int N = 2e5 + 10;

int T, n, a[N], b[N];
LL ans;

int tot;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> T;
	while (T --)
	{
		cin >> n;
		int mx = 0, bucket[N];
		for (re i = 1; i <= N; i ++) bucket[i] = 0;
		ans = 0;
		
		for (re i = 1; i <= n; i ++)
		{
			cin >> a[i];
			bucket[a[i]] ++;
			ans += a[i];
			
			if (a[i] > mx && bucket[a[i]] >= 2) mx = a[i];
			b[i] = mx;
		}
	
		int pre = 0;
		for (re i = 1; i <= n; i ++)
		{
			if (b[i] == 0) continue;
			
			int j = i;
			while (j + 1 <= n && b[j + 1] == b[i]) j ++;
			
			if (j == i) ans += b[i] - pre;
			else
			{
				int len = n - i + 1;
				ans += (LL)(b[i] - pre) * (len + 1) * len / 2;
				pre = b[i];
			}
			
			i = j;
		}
		cout << ans << '\n';
	}
	
	return 0;
}

D - Grid Puzzle

E1 - Catch the Mole(Easy Version)(交互题)

E2 - Catch the Mole(Hard Version)

F - Polygonal Segments

标签:...,960,int,bucket,Codeforces,cin,re,tie,Div
From: https://www.cnblogs.com/wenzieee/p/18314360

相关文章

  • 题解:Codeforces Round 960 (Div. 2) B
    B.ArrayCrafttimelimitpertest:1secondmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputForanarray\(b\)ofsize\(m\),wedefine:themaximumprefixpositionof\(b\)isthesmallestindex\(i\)thatsat......
  • Codeforces Round 960 (Div.2) 补题
    A非常容易观察到性质,注意Alice为先手,发现当\(a_{\max}\)的个数为奇数时显然能win,但如果\(a_{\max}\)的个数为偶数且有一个数具有奇数个可以作为跳板,那么也能win,否则就lose。B结论:\(presum_x\geq2+presum_{y-1}\geq2+\min{presum_i}\geq1+\max{presum_i}......
  • 题解:Codeforces Round 960 (Div. 2) A
    A.SubmissionBaittimelimitpertest:1secondmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAliceandBobareplayingagameinanarray\(a\)ofsize\(n\).Theytaketurnstodooperations,withAlicestarting......
  • Codeforces Round 960 (Div. 2) 补题记录(A~D)
    打的稀烂,但是还是上分了(A考虑对值域做一个后缀和。若某一个后缀和的值是奇数那么先手就可以获胜。否则就不可以获胜。(我才不会告诉你我这题吃了一次罚时的)#pragmaGCCoptimize(3)#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;intmysqrt(intx){......
  • 使用牛顿法近似整数的 sqrt,ZeroDivisionError
    Sqrt(x)给定一个非负整数x,返回x的平方根,向下舍入到最接近的整数。返回的整数也应该是非负数。不得使用任何内置指数函数或运算符。例如,不要在c++中使用pow(x,0.5)或在c++中使用x**0.5python.示例1:输入:x=4输出:2解释:4的平方根是2,所......
  • Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)
    A.给定n*m的矩阵a,构造一个同样大小的矩阵b使得[1,n*m]都出现一次,且b和a在任意位置上都不相等。特判完无解后循环移位即可。#include<bits/stdc++.h>usingnamespacestd;inta[12][12];voidsolve(){ intn,m; cin>>n>>m; for(inti=1;i<=n;i++) for(intj=1;j<=m;j++)......
  • CodeForces Round #959 sponsored by NEAR (Div. 1 + Div. 2) 补题记录(A~E)
    简单场.pngA若\(n\timesm=1\)则显然无解。否则因为\(a\)矩阵是一个\(n\timesm\)的排列,所以说只需要让其循环右移一位即可。时间复杂度\(O(nm)\)。#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=500100;inta[233][233];sign......
  • 题解 Codeforces 1994H Fortnite
    首先第一次询问肯定是问\(\texttt{aa}\),答案减去\(1\)得到基数\(p\)。然后我们随意询问一个真实Hash值(取模之前)\(X\)大于模数\(m\)的字符串,例如\(s=\texttt{zzz}\cdots\texttt{zzz}\)(\(50\)个\(\textttz\))。设它取模得到的Hash值是\(a\)。考虑正整数\(1\leqb......
  • CodeForces - 1139D
    题目大意序列每次随机添加一个\([1,m]\)的整数,直到序列\(gcd=1\)停止,求期望操作次数。分析模拟过程发现只关心整个序列的\(gcd\)与下一次会添加什么,那么根据期望\(dp\)套路可得状态\(f_{i}\)表示当前序列\(gcd=i\),期望还操作多少次使得\(gcd=1\)。考虑枚举下一个......
  • 「比赛记录」CF Round 954 (Div. 3)
    CodeforcesRound954(Div.3)题目列表:A.XAxisB.MatrixStabilizationC.UpdateQueriesD.MathematicalProblemE.BeautifulArrayF.Non-academicProblemG1.PermutationProblem(SimpleVersion)G2.PermutationProblem(HardVersion)A.XAxis题......