首页 > 其他分享 >ABC 367 题解

ABC 367 题解

时间:2024-08-17 22:26:23浏览次数:5  
标签:ABC int 题解 ll newline long 367 hspace define

AtCoder Beginner Contest 367 题解:

\(Problem \hspace{2mm} A - Shout \hspace{2mm} Everyday\)

题目链接

opinion:

~~ code:

#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
using namespace std;
ll a, b, c;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> a >> b >> c;
	if (b <= c) {
		if (a < b || a > c) {
			cout << "Yes";
		} else {
			cout << "No";
		}
	} else {
		if (!(a + 24 >= b && a <= c)) {
			cout << "Yes";
		} else {
			cout << "No";
		}
	}
	return 0;
}

\(\newline\)
\(\newline\)

\(Problem \hspace{2mm} B - Cut .0\)

题目链接

opinion:

code:

#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	bool fg = false;
	int n = s.size();
	while (s[n - 1] == '0') n --;
	if (s[n - 1] == '.') n -= 1;
	for (int i = 0; i < n; ++i)
		cout << s[i];
	return 0;
}

\(\newline\)
\(\newline\)

\(Problem \hspace{2mm} C - Enumerate \hspace{2mm} Sequences\)

题目链接

opinion:

code:

#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
using namespace std;
const int N = 1e6 + 10;
int n, k, a[N], x[N];
inline void dfs(int step, int ret) {
	if (step > n) {
		if (ret % k == 0) {
			for (int i = 1; i <= n; ++i)
				cout << x[i] << " ";
			cout << "\n";
		}
		return ;
	}
	for (int i = 1; i <= a[step]; ++i) {
		x[step] = i;
		dfs(step + 1, ret + i);
		x[step] = 0;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	dfs(1, 0);
	return 0;
}

~~
\(\newline\)
\(\newline\)

\(Problem \hspace{2mm} D - Pedometer\)

题目链接

opinion:

code:

#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
using namespace std;
const int N = 1e6 + 10;
ll n, m, a[N], cnt[N], pre[N];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[n + i] = a[i];
    }
    for (int i = 2; i <= n + n - 1; i++) {
        pre[i] = pre[i - 1] + a[i - 1];
        pre[i] %= m;
    }
    for (int i = 1; i <= n; i++)
        cnt[pre[i]]++;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += cnt[pre[i]] - 1;
        cnt[pre[i + n]]++;
        cnt[pre[i]]--;
    }
    cout << ans;
    return 0;
}

\(\newline\)
\(\newline\)

\(Problem \hspace{2mm} F - Rearrange \hspace{2mm} Query\)

题目链接

opinion:

Hash + 前缀和,竟然没被卡掉,绷不住了。

code:

#include <bits/stdc++.h>
#include <random>
#define ll long long
#define pii pair <int, int>
using namespace std;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
ll n, q, a[N], b[N];
ll Hash[N];
ll pre_a[N], pre_b[N];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n; ++i)
    	cin >> a[i];
    for (int i = 1; i <= n; ++i)
    	cin >> b[i];
    srand(time(NULL));
    for (int i = 1; i <= n; ++i)
    	Hash[i] = rand() % mod;
    for (int i = 1; i <= n; ++i) {
    	(pre_a[i] = pre_a[i - 1] + Hash[a[i]]) %= mod;
    	(pre_b[i] = pre_b[i - 1] + Hash[b[i]]) %= mod;
    }
    while (q -- ) {
    	int l[2], r[2];
    	cin >> l[0] >> r[0] >> l[1] >> r[1];
    	ll ans1 = pre_a[r[0]] - pre_a[l[0] - 1] + mod;
    	ll ans2 = pre_b[r[1]] - pre_b[l[1] - 1] + mod;
    	if (ans1 % mod == ans2 % mod) puts("Yes");
    	else puts("No");
	}
    return 0;
}

\(\newline\)
\(\newline\)

标签:ABC,int,题解,ll,newline,long,367,hspace,define
From: https://www.cnblogs.com/2026zhaoyl/p/18365096

相关文章

  • abc364 题解
    第一次场切A~F,写个题解纪念一下。比赛链接:https://atcoder.jp/contests/abc367A-ShoutEveryday题意:高桥每天\(B\)时刻睡觉,\(C\)时刻起床(\(B,C\)时刻也在睡觉),请问高桥\(A\)时刻是否没睡。思路:对于\(B<=C\)和\(B>C\)分别处理即可。代码:https://atcoder.jp/con......
  • AtCoder Beginner Contest 367
    A-ShoutEveryday(abc367A)题目大意高桥从\(A\)睡到\(B\),如果在\(C\)时,他醒着,他则会对章鱼烧发癫,问他今天是否发癫。解题思路由于只有\(24\)小时,直接枚举\(A\toB\),看看是否遍历到\(C\)即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=......
  • AtCoder Beginner Contest 367 补题记录(A~F)
    很Easy一场,共计用时\(34\)minAconstintN=1000100;signedmain(){strings;cin>>s;intcnt=0;intn=s.size();if(s[n-1]=='0'&&s[n-2]=='0'&&s[n-3]=='0'){s.pop_back();s.p......
  • AtCoder Beginner Contest 367
    喜欢我\(\log_210^{18}=18\)吗?A#include<bits/stdc++.h>#defineebemplace_back#defineepemplaceusingnamespacestd;usingll=longlong;inta,b,c;intmain(){ cin.tie(0)->sync_with_stdio(0); cin>>a>>b>>......
  • 题解:AtCoder Beginner Contest 367
    总体情况A题意在AtCoder王国,居民们每天都要在\(A\)点大声喊出他们对章鱼烧的热爱。住在AtCoder王国的高桥每天\(B\)点睡觉,\(C\)点起床(\(24\)小时钟)。他醒着的时候可以喊出对章鱼烧的爱,但睡着的时候却不能。判断他是否每天都能喊出对章鱼烧的爱。这里,一天有\(24......
  • P10886 【MX-S3-T2】「FeOI Round 1」Journey 题解
    我们肯定是要先求出来一个位置被加的次数,然后和权值乘一下就行。对于一个位置\(i\),右端点\(b\)肯定是随便选,一共\(n-i+1\)种情况。再是对于每一种步长\(c\),左端点\(a\)都有\(\left\lceil\dfrac{i}{c}\right\rceil\)种取值,暴力计算,时间复杂度\(O(n^2)\)。(提交记录)考虑......
  • P10888 【MX-S3-T4】「FeOI Round 1」醒餞の鳥 (feat. Feryquitous) 题解
    话说这题真的有紫吗(问号注意到数据范围中提到$\sum{nm}\le2\times10^5$,这里实际上是隐含了\(\min(n,m)\le\sqrt{2\times10^5}\)的。我们考虑根据\(n\)和\(m\)的大小关系设计出不同的算法。\(m<n\)一个比较直接的想法是对于每一个科目先按该科目的分数排序,这样......
  • 在相思树下 III 题解
    前言题目链接:洛谷。赛时脑子坨成一坨了,估计是T1的影响,写一篇题解来理清思路。题意简述给你一个长为\(n\)的序列\(a_{1\dotsn}\),你需要对它进行两种操作共\(n-1\)次。对一个长度为\(l\)的序列\(b_{1\dotsl}\)进行一次操作将会把序列变为一个长为\(l-1\)的序列......
  • n1gr tS0i 题解
    前言题目链接:洛谷。想了一个小时,想到后只用\(1\)分钟过了的题。官方题解过于晦涩,看到一篇很清晰的题解,于是写题解以记之。终于遇到时间瓶颈在输入的题目。题意简述有一个长度为\(n\)的\(\tt01\)串\(S\),你要对\(S\)进行恰好\(n\)次操作。每次操作选择\(1\leq......
  • 洛谷 B3735 B3736 B3787 题解
    嘿嘿我发烧已经好了!题目目录:No.1 B3735[信息与未来2018]圣诞树No.2 B3736[信息与未来2018]最大公约数No.3 B3787[信息与未来2023]精密计时 OK,开始正文!第一题:B3735[信息与未来2018]圣诞树 题目描述圣诞树共有 nn 层,从上向下数第 11 层有 11 个......