【比赛】 AtCoder Beginner Contest 166

题意/题解

A A?C

  • 题意:输入一个字符串可能是'ABC'也可能是'ARC',如果是'ABC'就输出'ARC',如果是'ARC'就输出'ABC'。
  • 题解:sb题

B Trick or Treat

  • 题意:有 \(n\) 个人,\(k\) 个小吃,给你第 \(i\) 个小吃有哪几个人有,让你判断没有小吃的有几个人。
  • 题解:开个数组记一下谁没小吃就行。

C Peaks

  • 题意:有 \(n\) 个天文台,天文台之间有道路链接,判断有多少天文台比与其链接的其他天文台都高。
  • 题解:一边读边一边一边判断这座天文台是否满足条件。

D I hate Factorization

  • 题意:给你 \(X\),让你找到一组 \(A,B\) 使得 \(A^5-B^5=X\)
  • 题解:\(100 ^ 5 = 10000000000\),然后在 \(-100 \sim 100\) 之间枚举 \(A,B\) 发现过不了,那就在 \(-200 \sim 200\) 之间枚举 \(A,B\) 了。

E This Message Will Self-Destruct in 5s

  • 题意:让你求满足 \(j-i= a_j+a_i\) 这个条件的对数。
  • 题解:\(j-i= a_j+a_i\)\(j-a_j=a_i+i\),用一个map记录一下 \(a_i+i\) 出现的次数,对于每个 \(j-a_j\) 答案加上 \(j-a_j\)map中出现的次数。

F Three Variables Game

  • 题意:给你 \(n\) 个操作和三个数 \(A,B,C\),每次操作都为 ABACBC 的形式,每次操作为从两个数中选一个加一,另一个减一,让你判断最后能不能都不为负数。
  • 题解:dfs可以过。

代码

A A?C

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

std::string s;

int main() {
	std::cin>>s;
	if(s=="ABC") puts("ARC");
	else if(s=="ARC") puts("ABC");
	return 0;
}

B Trick or Treat

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int n,k;
bool haved[101];

int main() {
	read(n),read(k);
	for(int i=1,d;i<=k;++i) {
		read(d);
		for(int j=1,x;j<=d;++j) {
			read(x);
			haved[x]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i) {
		if(!haved[i]) ++ans;
	}
	std::cout<<ans<<'\n';
	return 0;
}

C Peaks

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int n,m,a[100001];
bool OK[100001];

int main() {
	read(n),read(m);
	for(int i=1;i<=n;++i) read(a[i]);
	for(int i=1,u,v;i<=m;++i) {
		read(u),read(v);
		if(a[u]>=a[v]) OK[v]=1;
		if(a[v]>=a[u]) OK[u]=1;
	}
	int ans=0;
	for(int i=1;i<=n;++i) {
		if(!OK[i]) ++ans;
	}
	std::cout<<ans<<'\n';
	return 0;
}

D I hate Factorization

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

typedef long long ll;
inline void read(ll &T) {
	ll x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

ll x;

ll qpow(ll a,ll b) {
	ll ans=1,base=a;
	while(b) {
		if(b&1) ans=ans*base;
		base=base*base;
		b>>=1;
	}
	return ans;
}

int main() {
	read(x);
	for(ll i=-200;i<=200;++i) {
		for(ll j=-200;j<=200;++j) {
			if(qpow(i,5)-qpow(j,5)==x) {
				std::cout<<i<<" "<<j<<'\n';
				return 0;
			}
		}
	}
	return 0;
}

E This Message Will Self-Destruct in 5s

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#define MAXN 200001

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int n,a[MAXN];
std::map<int,int> m;

int main() {
	read(n);
	for(int i=1;i<=n;++i) {
		read(a[i]);
		++m[a[i]+i];
	}
	long long ans=0;
	for(int i=1;i<=n;++i) {
		if(i>a[i]) ans+=m[i-a[i]];
	}
	std::cout<<ans<<'\n';
	return 0;
}

F Three Variables Game

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int n,a,b,c;
char ans[100001];
std::string cmd[100001];

void dfs(int step,int a,int b,int c) {
	if(step>n) {
		puts("Yes");
		for(int i=1;i<=n;++i) {
			printf("%c\n",ans[i]);
		}
		exit(0);
	}
	if(cmd[step]=="AB") {
		if(a) {
			ans[step]='B';
			dfs(step+1,a-1,b+1,c);
		}
		if(b) {
			ans[step]='A';
			dfs(step+1,a+1,b-1,c);
		}
	}
	if(cmd[step]=="AC") {
		if(a) {
			ans[step]='C';
			dfs(step+1,a-1,b,c+1);
		}
		if(c) {
			ans[step]='A';
			dfs(step+1,a+1,b,c-1);
		}
	}
	if(cmd[step]=="BC") {
		if(b) {
			ans[step]='C';
			dfs(step+1,a,b-1,c+1);
		}
		if(c) {
			ans[step]='B';
			dfs(step+1,a,b+1,c-1);
		}
	}
}

int main() {
	read(n),read(a),read(b),read(c);
	for(int i=1;i<=n;++i) std::cin>>cmd[i];
	dfs(1,a,b,c);puts("No");
	return 0;
}

反思:

  • 读题浪费了太多时间。
  • 太菜了。
posted @ 2020-05-03 21:54  yu__xuan  阅读(344)  评论(5编辑  收藏  举报