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

Codeforces Round #833 (Div. 2)

时间:2022-11-21 14:15:25浏览次数:49  
标签:833 lceil frac int Codeforces 木块 Div rceil

C 题挂 \(4\) 发赛后再挂 \(4\) 发 AB 耻辱跑路。

A. The Ultimate Square

有 \(n\) 个木块,第 \(i\) 块长 \(\lceil\frac {i} {2}\rceil\) 宽 \(1\), 则用这些木块拼成的最大的正方形边长为多少。


见样例知结论。


若 \(n\bmod 2 = 1\), 则长 \(1\sim \lceil\frac {n}{2}\rceil-1\) 的木块有 \(2\) 个,长 \(\lceil\frac {n}{2}\rceil\) 的木块有 \(1\) 个。
我们则可以单独放 \(\lceil\frac{n}{2}\rceil\) 的木块,对于剩下的木块首尾配对就可以组成边长 \(\lceil\frac{n}{2}\rceil\) 的木块。

若 \(n\bmod 2 = 0\),则长 \(1\sim \frac{n}{2}\) 的都有 \(2\) 个。
便可以选一个长 \(\frac{n}{2}\) 的丢掉另一个,剩下的首尾配对,边长为 \(\frac{n}{2}\)。


// Problem: The Ultimate Square
// Contest: Codeforces
// URL: http://m3.codeforces.com/contest/1748/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h> 
using namespace std;
int main () {
	ios :: sync_with_stdio (false);
	cin .tie (0);
	cout .tie (0);
	int t;
	cin >> t;
	while (t --) {
		int n;
		cin >> n;
		cout << (n + 1) / 2 << endl;
	}
	return 0;
}

B. Diverse Substrings

定义“好”的序列为出现的最多的元素的数量 \(\le\) 出现的元素种类数量,给你一个序列,你需要回答序列中有多少子序列是“好”的序列,元素 \(=0\sim 9\)。


很妙的一道题。


一开始不难想到 \(n^2\) 的枚举起点依次后推终点的暴力。

我们选择筛掉无用的。我们发现元素种类最多也只有 \(10\) 种,则每种元素最多出现次数也只有 \(10\) 种,则合法的序列长度最长也只有 \(100\),便可以筛去长度 \(>100\) 的序列。

时间复杂度 \(O(w^2n)\),\(w\) 为元素数量,这里为 \(10\)。


// LUOGU_RID: 94000172
// Problem: B. Diverse Substrings
// Contest: Codeforces - Codeforces Round #833 (Div. 2)
// URL: https://codeforc.es/contest/1748/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
const int N = 100100, T = 10;
int a [N];
int cnt [T];
int main () {
	int t;
	scanf ("%d", &t);
	while (t --) {
		int n;
		scanf ("%d", &n);
		for (int i = 1; i <= n; i ++) {
			scanf ("%1d", & a[i]);
		}
		int ans = 0;
		for (int i = 1; i <= min (100, n); i ++) {//这里采用的枚举长度
			for (int j = 0; j < T; j ++) {
				cnt [j] = 0;
			}
			int scnt = 0;
			for (int j = 1; j <= i; j ++) {
				cnt [a [j]] ++;
				if (cnt [a [j]] == 1) {
					scnt ++;
				}
			}
			for (int j = i; j <= n; j ++) {
				int Max = 0;
				for (int k = 0; k < T; k ++) {
					Max = max (Max, cnt [k]);
				}	
				if (Max <= scnt) {
					ans ++;
				}
				cnt [a [j - i + 1]] --;
				if (!cnt [a [j - i + 1]]) {
					scnt --;
				}
				cnt [a [j + 1]] ++;
				if (cnt [a [j + 1]] == 1) {
					scnt ++;
				}
			}
		}
		printf ("%d\n", ans);
	}
	return 0;
}

C. Zero-Sum Prefixes

先咕到晚上吧。

标签:833,lceil,frac,int,Codeforces,木块,Div,rceil
From: https://www.cnblogs.com/lhzawa/p/16911224.html

相关文章

  • mysql中eq_range_index_dive_limit参数学习
    ​概念官方文档如下描述:Thisvariableindicatesthenumberofequalityrangesinanequalitycomparisonconditionwhentheoptimizershouldswitchfromusingind......
  • Codeforces 1740 F Conditional Mix 题解
    题目链接对于任意一个multiset,我们都把它的元素从大到小排序来观察。发现一个multiset合法有个必要条件:对于每个i,multiset中最大的i个元素之和不能超过\(lim_i\),如果令\(c......
  • VP 记 #1 - Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)
    VP记#1-DeltixRound,Autumn2021(openforeveryone,rated,Div.1+Div.2)VP信息时间:2022年11月20日14:40~17:10。场次:DeltixRound,Autumn2021(o......
  • Codeforces 704 B Antman 题解 (dp,贪心,结论)
    题目链接这题两种不同做法,普通的\(O(n^2)\)和奇怪的\(O(nlogn)\)。如果用\(O(nlogn)\)的话可以加强到1e6。做法1时间复杂度\(O(n^2)\)先把最终的排列随便画一个出来观......
  • CodeForces - 797F Mice and Hole
    题意:有n只老鼠,m个洞。n只老鼠的坐标分别为x[i],m个洞坐标分别为p[i],能装c[i]只老鼠。现在老鼠要往洞里跑,求所有老鼠跑的最短路线之和。解:一开始准备拿老鼠转移,然后复杂度爆......
  • 如何获取div下的子标签-字标签不一定还是div-如何获取div下的h5标签
    varhtmlStr="";htmlStr+="<divid=\"div_"+data.retData.id+"\"class=\"remarkDiv\"style=\"height:60px;\">";htmlStr+="<divstyle=\"position:relative;top:-4......
  • Codeforces Round #834 (Div. 3) A-G
    比赛链接A题目知识点:模拟。确定开头字母,然后循环比较即可。时间复杂度\(O(n)\)空间复杂度\(O(n)\)题解#include<bits/stdc++.h>#definelllonglongusingn......
  • Codeforces Round #834 (Div. 3) G
    G.RestorethePermutation对于一个序列要是我们从数小a[i]的开始每次给这个a[i]选一个最接近她的一个小的显然我们这样是最合法的但是怎么保证字典序最小呢显然我......
  • 题解 Codeforces Round #834 (Div. 3) ABCDEF
    A.Yes-Yes?problem判断给定的字符串是否为无穷个YesYesYes拼接组成的字符串的连续子串。\(|S|\leq50\)。solution暴力。具体地,判断\(S,Ye+S,Y+S\)是否有一个是......
  • Codeforces Round #834 (Div. 3)
    ABC略。D.MakeItRound问题可以看成凑出尽可能多的\(10\)作为因子。注意到\(10\)的因子只有\(1,2,5,10\)。首先,\(n\)自己已经凑出来的\(10\)没必要拆开,并......