首页 > 其他分享 >Codeforces Round 872 (Div. 1 & Div. 2)

Codeforces Round 872 (Div. 1 & Div. 2)

时间:2023-05-08 22:57:24浏览次数:48  
标签:__ pbds gnu int tree 872 Codeforces Div include

这场寄大了。

My predictor say -101pts。

https://codeforces.com/contest/1824

https://codeforces.com/contest/1825

2A. LuoTianyi and the Palindrome String

因为给出的 \(s\) 是一个回文串,所以答案只可能是 \(-1\) 或者 \(n - 1\),只需要看一下删掉哪一个即可,然后判定,这些都是平凡的。

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef pair < int, int > PII;
typedef int itn;
mt19937 RND_MAKER (chrono :: steady_clock :: now ().time_since_epoch ().count ());
inline ll randomly (const ll l, const ll r) {return (RND_MAKER () ^ (1ull << 63)) % (r - l + 1) + l;}
//#define int long long
const double pi = acos (-1);
//__gnu_pbds :: tree < Key, Mapped, Cmp_Fn = std :: less < Key >, Tag = rb_tree_tag, Node_Upadte = null_tree_node_update, Allocator = std :: allocator < char > > ;
//__gnu_pbds :: tree < PPS, __gnu_pbds :: null_type, less < PPS >, __gnu_pbds :: rb_tree_tag, __gnu_pbds :: tree_order_statistics_node_update > tr;
inline int read () {
	int x = 0, f = 0;
	char c = getchar ();
	for ( ; c < '0' || c > '9' ; c = getchar ()) f |= (c == '-');
	for ( ; c >= '0' && c <= '9' ; c = getchar ()) x = (x << 1) + (x << 3) + (c & 15);
	return !f ? x : -x;
}
char s[55], t[55];
int n;
signed main () {
	int _ = read ();
	while (_ --) {
		scanf ("%s", s + 1);
		n = strlen (s + 1);
		int ans = -1;
		for (int i = 1;i <= n; ++ i) {
			int tot = 0;
			for (int j = 1;j <= n; ++ j) {
				if (i != j) t[++ tot] = s[j];
			}
			int ok = 1;
			for (int j = 1;j <= n - 1; ++ j) {
				ok &= (t[j] == t[n - 1 - j + 1]);
			}
			if (!ok) ans = n - 1;
		}
		printf ("%d\n", ans);
	}
}
/* PT is thinking here ...... */
/* Hope to be candidate master tonight! */

2B. LuoTianyi and the Table

我们要最大化每个前缀矩形的极差之和,那么在 \(a_{1,1},a_{1,2},a_{2,1}\) 必须放最大的,次大的,最小的,次小的,然后枚举这几种情况然后将极差之和取个 max 就行。

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
typedef long long ll;
typedef pair < int, int > PII;
typedef int itn;
mt19937 RND_MAKER (chrono :: steady_clock :: now ().time_since_epoch ().count ());
inline ll randomly (const ll l, const ll r) {return (RND_MAKER () ^ (1ull << 63)) % (r - l + 1) + l;}
#define int long long
const double pi = acos (-1);
//__gnu_pbds :: tree < Key, Mapped, Cmp_Fn = std :: less < Key >, Tag = rb_tree_tag, Node_Upadte = null_tree_node_update, Allocator = std :: allocator < char > > ;
//__gnu_pbds :: tree < PPS, __gnu_pbds :: null_type, less < PPS >, __gnu_pbds :: rb_tree_tag, __gnu_pbds :: tree_order_statistics_node_update > tr;
inline int read () {
	int x = 0, f = 0;
	char c = getchar ();
	for ( ; c < '0' || c > '9' ; c = getchar ()) f |= (c == '-');
	for ( ; c >= '0' && c <= '9' ; c = getchar ()) x = (x << 1) + (x << 3) + (c & 15);
	return !f ? x : -x;
}
int n, m, b[10005], a[105][105];
inline int f () {
	int ans = 0;
	ans += a[1][1];
	ans += max (a[1][1], a[1][2]) * (m - 1);
	ans += max (a[1][1], a[2][1]) * (n - 1);
	ans += max ({a[1][1], a[1][2], a[2][1]}) * (n - 1) * (m - 1);
	ans -= a[1][1];
	ans -= min (a[1][1], a[1][2]) * (m - 1);
	ans -= min (a[1][1], a[2][1]) * (n - 1);
	ans -= min ({a[1][1], a[1][2], a[2][1]}) * (n - 1) * (m - 1);
//	if (ans == 12) {
//		printf ("a[1][1] = %lld, a[1][2] = %lld, a[2][1] = %lld\n", a[1][1], a[1][2], a[2][1]);
//	}
	return ans;
}
signed main () {
	int _ = read ();
	while (_ --) {
		n = read (), m = read ();
		int ans = -9e18;
		for (int i = 1;i <= n * m; ++ i) b[i] = read ();
		sort (b + 1, b + 1 + n * m);
		a[1][1] = b[n * m], a[1][2] = b[1], a[2][1] = b[2], ans = max (ans, f ());
		a[1][1] = b[n * m], a[1][2] = b[2], a[2][1] = b[1], ans = max (ans, f ());
		a[1][1] = b[1], a[1][2] = b[n * m], a[2][1] = b[n * m - 1], ans = max (ans, f ());
		a[1][1] = b[1], a[1][2] = b[n * m - 1], a[2][1] = b[n * m], ans = max (ans, f ());
		printf ("%lld\n", ans);
	}
	return 0;
}
/* PT is thinking here ...... */
/* Hope to be candidate master tonight! */

2C/1A. LuoTianyi and the Show

这题费了我 80min & penalty*3 /fn /fn /fn。

思路想了好久才想对,一开始想的是 \(-1\) 和 \(-2\) 一定连在一起用,然后就对着错的思路搞了 1h /fn /fn /fn。

发现我们可以分成三种情况处理:

  • 只用 \(-2\)。从 \(1\) 到 \(m\) 扫一遍,如果有 \(i\) 就直接用,否则花费一个 \(-2\)。

  • 只用 \(-1\)。从 \(m\) 到 \(1\) 扫一遍,如果有 \(i\) 就直接用,否则花费一个 \(-1\)。

  • \(-1\) 和 \(-2\) 都用。钦定一个至少出现 \(1\) 次的 \(i\),\(1 \sim i\) 用 \(-1\),有空隙就可以插一个 \(-1\) 进去。\(i + 1 \sim m\) 用 \(-2\),有空隙就插一个 \(-2\) 进去。

自己复了复盘,

标签:__,pbds,gnu,int,tree,872,Codeforces,Div,include
From: https://www.cnblogs.com/RB16B/p/17383406.html

相关文章

  • CodeForces - 631A Interview (思想)水
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-631AInterviewSubmit StatusDescriptionBlakeisaCEOofalargecompanycalled"BlakeTechnologies".Heloveshiscompanyverymuchandhethinksthathi......
  • CodeForces - 630F Selection of Personnel (组合数学)
    TimeLimit: 500MS MemoryLimit: 65536KB 64bitIOFormat: %I64d&%I64uCodeForces-630FSelectionofPersonnelSubmit StatusDescriptionOnecompanyofITCitydecidedtocreateagroupofinnovativedevelopmentsconsistingfrom 5 to 7 peopleandhir......
  • CodeForces - 621B Wet Shark and Bishops (数学几何&技巧)
    TimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-621BWetSharkandBishopsSubmit StatusDescriptionToday,WetSharkisgiven n bishopsona 1000 by 1000 grid.Bothrowsandcolumnsofthegridarenumberedfro......
  • CodeForces - 618A Slime Combining (快速幂)
    CodeForces-618ASlimeCombiningTimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionYourfriendrecentlygaveyousomeslimesforyourbirthday.Youhave n slimesallinitiallywithvalue 1.Youare......
  • CodeForces - 626B Cards (全排列&模拟)
    TimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-626BCardsSubmit StatusDescriptionCatherinehasadeckof ntakeanytwo(notnecessarilyadjacent)cardswithdifferentcolorsandexchangethemforanewcardof......
  • CodeForces - 597A Divisibility (模拟)
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-597ADivisibilitySubmit StatusDescriptionFindthenumberof k-divisiblenumbersonthesegment [a, b].Inotherwordsyouneedtofindthenumberofsuchintegerv......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory题意:给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。分析:对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可code:#include<bits/stdc++.h>usingnamespacestd;intmain(){ std::ios::sync_wit......
  • CF R870 div.2
    C 输出"NO"的充要条件是要在最初就选择\(k\)个物品,使得\(k\midN\)。发现朴素做法是\(O(TM)\),可以对\(N\)的约数进行枚举,优化为\(O(T\sqrt(N))\),再特判\(N\leqM\)和\(N=1\)的情况。#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+10;int......
  • 图片填满div,真让人头大
    家人们,这图片到底怎样才能完全填满div啊,想问度娘结果搜索的问题都乱七八糟的(怎么那么多问题QAQ),描述问题都描述不来具体问题如下:图片有自己的分辨率大小,例如宽100px,高100px,将图片添加到div中:<divclass="xx"><imgsrc="xxx"></div>接着用css代码编辑样式的时候,首先设置di......