AtCoder Beginner Contest 166 题解报告

A:A?C

题目链接:

https://atcoder.jp/contests/abc166/tasks/abc166_a

Code:

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int t,n,m;

int main(void) {
	string str;
	cin >> str;
	if(str == "ABC") puts("ARC") ;
	else puts("ABC");

	return 0;	
} 

B:Trick or Treat

题目链接:

https://atcoder.jp/contests/abc166/tasks/abc166_b

Code:

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int t,n,k,len,value;

int dp[maxn];

int main(void) {
	cin >> n >> k;
	for(int i = 1; i <= k; i ++) {
		scanf("%d",&len);
		for(int j = 1; j <= len; j ++){
			scanf("%d",&value);
			dp[value] = value;
		}
		
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		if(dp[i] != i) ans ++;
	}
	cout << ans << endl;
	return 0;	
} 

C:Peaks

题目链接:

https://atcoder.jp/contests/abc166/tasks/abc166_c

题目大意:

给几条双向的道路,每个节点都有一个权值,只有高的能到达较低的,
然后问满足 从某个节点出发是否能到达所有和它相邻的节点 这样
的条件的路线有多少?

侃侃:

直接枚举即可,注意,单个节点也算。

Code:

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int t,n,m;

vector<int>G[maxn];

int value[maxn];

int main(void) {
	int n,m;
	cin >> n >> m;
	int u,v,a;
	for(int i = 1; i <= n; i ++) {
		scanf("%d",&a);
		value[i] = a;
	}
	for(int i = 1; i <= m; i ++) {
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		bool flag = true;
		for(int j = 0; j < G[i].size(); j ++) {
			if(value[i] <= value[G[i][j]]) {
				flag = false;
				break;
			}
		}
		if(flag || G[i].size() == 0) ans ++;
	}
	cout << ans << endl;
	return 0;	
} 

D:I hate Factorization

题目链接:

https://atcoder.jp/contests/abc166/tasks/abc166_d

侃侃:

按照题目给的意思走,暴力即可,注意一下负数的范围。

Code:

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

//#define int long long

using namespace std;

//typedef int long long;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int t,n,m;


int main(void) {
	scanf("%d",&n);
	for(int i = -120; i <= 120; i ++) {
		for(int j = -120; j <= 120; j ++) {
			if(pow(i,5) - pow(j,5) == n) {
				printf("%d %d\n",i,j);
				return 0;
			}
		}
	}
	return 0;	
} 

E:This Message Will Self-Destruct in 5s

题目链接:

https://atcoder.jp/contests/abc166/tasks/abc166_e

题目大意:

给一个数组序列,问满足 A[i] + A[j] = j - i (i < j)
这样的对数有多少个?

侃侃:

我们将式子转换一下:  A[i] + A[j] = j - i
                => A[i] + i = j - A[j]
又因为 i < j,所以我们可以将左右都当做同一部分
即 A[i] + i = i - A[i] (j 是 i 后面的数)
这样我们每次统计前面是否出现 和 i - A[i] 相等的数。
前面每次累加的就是 i + A[i],这样我们就将两个式子
弄成一个式子了。

Code:

#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int a[maxn];

int t,n,m;

map<int,int>maps; 

int main(void) {
	scanf("%d",&n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d",&a[i]);
	}
	LL ans = 0;
	for(int i = 1; i <= n; i ++) {
		if(maps.count(i - a[i]) != 0) {
			ans += maps[i - a[i]];
		}		
		maps[i + a[i]] ++;
	}
	cout << ans << endl;
	return 0;	
} 

posted @ 2020-05-04 10:30  IceSwords  阅读(335)  评论(0编辑  收藏  举报