首页 > 其他分享 >AtCoder Beginner Contest 318

AtCoder Beginner Contest 318

时间:2023-09-26 21:33:20浏览次数:43  
标签:AtCoder 318 cout Beginner int cin i64 ++ ans

AtCoder Beginner Contest 318

A - Full Moon (atcoder.jp)

以\(M\)为首项,\(P\)为公差,看\(1 \sim N\)里包含了多少项的个数

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M,P;
    cin >> N >> M >> P;

    cout << 1ll * max(N - M, 0) / P + (N >= M) << '\n';

    return 0;
}

B - Overlapping sheets (atcoder.jp)

数据不大,直接枚举即可

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';

using namespace std;
using i64 = long long;

typedef pair<i64, i64> PII;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;

	i64 ans = 0;
	vector<bitset<110>> g(110, 0);
	for (int i = 0; i < N; i ++) {
		int A, B, C, D;
		cin >> A >> B >> C >> D;
		for (int j = A; j < B; j ++)
			for (int k = C; k < D; k ++)
				g[j][k] = 1;
	}
	
	for (int i = 0; i < 100; i ++)
		for (int j = 0; j < 100; j ++)
			ans += g[i][j];

	cout << ans << '\n';

	return 0;
}

C - Blue Spring (atcoder.jp)

题意就是在\(N\)天的旅游中,每天会花费\(A_i\)元,但是可以花费\(P\)元使得\(D\)天的花费免费,这\(D\)天可以是分开的.

我们可以将每天的费用从大到小排序,做一个前缀和,将\(D\)天内的花费与\(P\)做一个比较,取其小的费用即可

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';

using namespace std;
using i64 = long long;

typedef pair<i64, i64> PII;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	i64 N, D;
	i64 ans = 0, P;
	cin >> N >> D >> P;

	vector<i64> F(N + D + 1);
	for (int i = 1; i <= N; i ++)
		cin >> F[i];

	sort(F.begin() + 1, F.begin() + N + 1,greater<>());
	for (int i = 1; i <= N + D; i ++)
		F[i] += F[i - 1];

	for (int i = D; i <= N + D; i += D)
		ans += min(P, F[i] - F[i - D]);

	cout << ans << '\n';

	return 0;
}

D - General Weighted Max Matching (atcoder.jp)

\(N\)最多只有\(16\),可以直接\(dfs\)暴搜(

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';

using namespace std;
using i64 = long long;

typedef pair<i64, i64> PII;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	vector<vector<int>> g(N + 1, vector<int>(N + 1));
	for (int i = 1, D; i < N; i ++) {
		for (int j = i + 1; j <= N; j++) {
			cin >> g[i][j];
			g[j][i] = g[i][j];
		}
	}

	bitset<20> vis;
	i64 ans = 0;
	auto dfs = [&](auto self, int n, i64 sum) ->void{

		if (n > N) {
			ans = max(ans, sum);
			return ;
		}

		if (!vis[n]) {
			vis[n] = 1;
			for (int i = n + 1; i <= N; i ++) {
				if (!vis[i]) {
					vis[i] = 1;
					self(self, n + 1, sum + g[i][n]);
					vis[i] = 0;
				}
			}
			vis[n] = 0;
		}

		self(self, n + 1, sum);

	};

	dfs(dfs,1,0);

	cout << ans << '\n';

	return 0;
}

E - Sandwiches (atcoder.jp)

对于\(A_i\)和\(A_k\),设其中间的长度为\(L\),当只有这两个点相等时,则这两个点的贡献为\(L\),若\(A_i\)左边还有点,则它们可以与\(A_k\)产生\(Num_左 \times L\)的贡献,同理,\(A_k\)右边还有点的话则与\(A_i\)产生\(Num_右 \times L\)的贡献,所以对于相邻的两个值相等的点产生的贡献为\(L(k-i-1(不包括A_i和A_k)) \times 左边点 \times 右边点\)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n';

using namespace std;
using i64 = long long;

typedef pair<i64, i64> PII;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	vector<i64> A(N), g[N + 1];

	for (int i = 0; i < N; i ++) {
		cin >> A[i];
		g[A[i]].emplace_back(i);
	}

	i64 ans = 0;
	for (int i = 1; i <= N; i ++) {
		for (int j = 1; j < g[i].size(); j ++) {
			ans += (g[i][j] - g[i][j - 1] - 1) * j * (g[i].size() - j);
		}
	}

	cout << ans << '\n';

	return 0;
}

标签:AtCoder,318,cout,Beginner,int,cin,i64,++,ans
From: https://www.cnblogs.com/Kescholar/p/17731245.html

相关文章

  • AtCoder Regular Contest 165
    Preface这场前三题是上周四写的,今天课有点多本来想着把最近两场CF的博客先写下的但后面发现还有CCLCC的杂谈没写,写完发现由于晚上要上课没时间了,只能先把这场先写一下A-SumequalsLCM设\(n=\prod_{i=1}^kp_i^{c_i}\),不难发现令\(A_1=p_1^{c_1},A_2=p_2^{c_2},\cdots\),然......
  • thinkphp lang命令执行--struts2 代码执行--(QVD-2022-46174)&&(CVE-2020-17530)&&(CV
    thinkphplang命令执行--struts2代码执行--(QVD-2022-46174)&&(CVE-2020-17530)&&(CVE-2021-31805)thinkphplang命令执行(QVD-2022-46174)影响范围6.0.1<=ThinkPHP<=6.0.13ThinkPHP5.0.xThinkPHP5.1.x漏洞复现POC:?+config-create+/&lang=../../../../......
  • AtCoder Beginner Contest 321
    A-321-likeChecker(abc321A)题目大意给定一个数,问从高位到低位,数字是不是递减的。解题思路可以以字符串读入,然后依次判断即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_stdio(false);......
  • 题解 AtCoder Beginner Contest 267 A~H
    ABC267solutionhttps://atcoder.jp/contests/abc267/ProblemA.Saturday题目描述输入一个表示星期的英文字符串,输出:还有多少天到星期六?solution依题意模拟。\(O(1)\)。ProblemB.Split?题目描述Robin有十个小球,如图排列成这样,然后Robin将一些球击飞了,他告诉你哪些......
  • AtCoder Beginner Contest 318 ABCDE
    AtCoderBeginnerContest318A-FullMoon思路:等差数列求项数//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintmod=1e9+7;constintN=2e5+10;intmain(){ios::sync_with_stdio(false);......
  • AtCoder Beginner Contest 320 ABCDE
    AtCoderBeginnerContest320A-LeylandNumber思路:直接快速幂//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintmod=1e9+7;constintN=2e5+10;llqmi(lla,llb){llans=1;whil......
  • AtCoder Beginner Contest 253 E
    AtCoderBeginnerContest253E-DistanceSequence思路:前缀和优化DP要求$|a[i]-a[i+1]|>=k\(定于\)dp[i][j]:\(前\)i\(个数以\)j\(结尾的合法序列数列\)dp[i][j]+=dp[i-1][1~(j-k)]+dp[i-1][(j+k)~m]$直接写的话复杂度是\(O(nm^2)\)的会TLE,我们发现可以做一个前缀和优化......
  • AtCoder Beginner Contest 313 Ex Group Photo
    洛谷传送门AtCoder传送门考虑若重排好了\(a\),如何判断可不可行。显然只用把\(b\)排序,把\(\min(a_{i-1},a_i)\)也排序(定义\(a_0=a_{n+1}=+\infty\)),按顺序逐个判断是否大于即可。这启示我们将\(\min(a_{i-1},a_i)\)排序考虑。考虑从大到小加入\(a_i\),那么......
  • AtCoder Grand Contest 017
    链接C.SnukeandSpells容易发现合法序列排序后一定是若干段值域连续的部分组成:可以发现最小次数就是重叠/空出的部分大小。每次修改只会对\(O(1)\)个点\(±1\),直接维护即可。#include<iostream>#include<cstdio>#include<cstring>#include<vector>#defineN200010......
  • AtCoder Grand Contest 023 E Inversions
    洛谷传送门AtCoder传送门首先将\(a\)从小到大排序,设\(p_i\)为排序后的\(a_i\)位于原序列第\(p_i\)个位置,\(x_i\)为要填的排列的第\(i\)个数。设\(A=\prod\limits_{i=1}^n(a_i-i+1)\),则\(A\)为排列的总方案数(考虑按\(a_i\)从小到大填即得)。套路地,统......