ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Atcoder ABC240 赛后反思及部分题解

2022-02-21 17:33:30  阅读:286  来源: 互联网

标签:Atcoder const int 题解 LL cin ABC240 hh define


AtCoder Beginner Contest 240

比赛链接
在这强烈dls的视频讲解
dls的视频讲解及解题过程

A - Edge Checker

Problem Statement
In the figure shown in the image below, are the points numbered
a and b directly connected by a line segment?
在这里插入图片描述Input
Input is given from Standard Input in the following format:
a b
Output

If the points numbered
a and b are directly connected by a line segment, print Yes; otherwise, print No.
The judge is case-sensitive: be sure to print uppercase and lowercase letters correctly.

思路
看两个数字是否在同一条线上。

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define rep2(i, l, r) for (int i = l; i * i <= r; i++)
#define rep3(i, l, r) for (LL i = l; i * i * i <= r; i++)
#define Min(a, b) a > b ? b : a
#define Max(a, b) a > b ? a : b
#define endl '\n'
#define debug "-----"
using namespace std;
typedef long long LL;
const LL mod = 1e9;
const int N = 1e6 + 10, M = 1050;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
int main()
{
	IOS;
	int a,b;
	cin >> a >> b;
	if( abs(a-b)==1 || ( a==10&&b==1 ) || (b==10&&a==1) )
		cout << "Yes";
	else cout << "No";
	return 0;
}

B - Count Distinct Integers

思路:
找不同的数字有多少个

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define rep2(i, l, r) for (int i = l; i * i <= r; i++)
#define rep3(i, l, r) for (LL i = l; i * i * i <= r; i++)
#define Min(a, b) a > b ? b : a
#define Max(a, b) a > b ? a : b
#define endl '\n'
#define debug "-----"
using namespace std;
typedef long long LL;
const LL mod = 1e9;
const int N = 1e6 + 10, M = 1050;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

map<int,int>mp;
int ans = 0;

int main()
{
	IOS;
	int n;
	cin >> n;
	rep( i , 1 , n+1 ){
		int t; cin >> t;
		mp[t]++;
		if( mp[t] == 1 ) ans++;
	}
	cout << ans;
	return 0;
}

C - Jumping Takahashi

思路
当初自己写这道题的时候用了DFS结果超时了。一直想到了结束,自己还是太菜了QAQ。
在这推荐下dls Atcoder的视频讲解
dls的题解

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define rep2(i, l, r) for (int i = l; i * i <= r; i++)
#define rep3(i, l, r) for (LL i = l; i * i * i <= r; i++)
#define Min(a, b) a > b ? b : a
#define Max(a, b) a > b ? a : b
#define endl '\n'
#define debug "-----"
using namespace std;
typedef long long LL;
const LL mod = 1e9;
const int N = 1e6 + 10, M = 1050;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

bitset<10001>f;

int main()
{
	IOS;
	f[0] = 1;
	int n,x;
	cin >> n >> x;
	rep( i , 1 , n+1){
		int a,b;
		cin >> a >> b;
		f = ( f<<a )|( f<<b );
	}
	f[x]?cout << "Yes":cout << "No";
	return 0;
}

D - Strange Balls

思路:
模拟及一些优化,感觉有点类似kmp的next

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define rep2(i, l, r) for (int i = l; i * i <= r; i++)
#define rep3(i, l, r) for (LL i = l; i * i * i <= r; i++)
#define Min(a, b) a > b ? b : a
#define Max(a, b) a > b ? a : b
#define endl '\n'
#define debug "-----"
using namespace std;
typedef long long LL;
const LL mod = 1e9;
const int N = 1e6 + 10, M = 1050;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

int s[N],stk[N];
int hh;

int main()
{
	IOS;
	int n;
	cin >> n;
	rep( i , 1 , n+1 ){
		int t;
		cin >> t;
		stk[++hh] = t;
		if( hh == 1 || stk[hh]!=stk[hh-1] ) s[hh] = 1;
		else s[hh] = s[hh-1]+1;

		if( s[hh] == t ) hh -= t;
		cout << hh << endl;
	}
	return 0;
}

标签:Atcoder,const,int,题解,LL,cin,ABC240,hh,define
来源: https://blog.csdn.net/m0_52552463/article/details/123049470

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有