Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)(A,B,C,D)

A.

水题,不多说。

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int a, b, c;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	while(scanf("%d %d %d", &a, &b, &c) == 3){
		int x1 = c - (a + b);
		int x2 = a - (c + b);
		int x3 = b - (a + c);
		int maxx = max(x1, x2);
		maxx = max(maxx, x3);
		if(maxx < 0){
			printf("0\n");
		}else{
			printf("%d\n", maxx + 1);
		}
		
	}

	return 0;
}
/**/

B.

找规律,a[2*n]=a[n], a[2*n+1]=2*a[n]+1,a[0]=1,a[1]=1,a[2]=1,答案为a[n]+1;(其实可以oeis的)

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int solve(int n){
	if(n == 1) return 1;
	if(n == 2) return 1;
	int ans;
	if(n & 1){
		ans = 2 * solve((n - 1) >> 1) + 1;
	}else{
		ans = solve(n >> 1);
	}
	return ans;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	// int ans;
	// for (int i = 1; i <= 100; i++){
	// 	ans = 0;
	// 	for (int j = 0; j <= i; j++){
	// 		if(i - (i ^ j) == j){
	// 			ans++;
	// 		}
	// 	}
	// 	printf("%d %d\n", i, ans);
	// }
	int t, n;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		if(n == 0){
			printf("1\n");
			continue;
		}
		printf("%d\n", solve(n) + 1);
	}

	return 0;
}
/**/

看lol比赛rng连跪自闭了,什么都想不出来了,然后rating疯狂扣,惨不忍睹。不祥的一天

好了,补题开始

c.

求回文数最多,是真的服气,看见别人两行的代码,膜拜

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

string s;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	int n;
	while(scanf("%d", &n) == 1){
		cin >> s;
		sort(s.begin(), s.end());
		cout << s << endl;
	}

	return 0;
}
/**/

D.

bfs一下就行,我用的优先队列+bfs

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int n, m;
int sx, sy;
int l, r;
char s[2005][2005];
int vis[2005][2005];
int dist[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int ans;

struct node
{
	int x, y;
	int step, l, r;
	bool operator <(const node &x)const{
		return step > x.step;
	}
};

void bfs(){
	priority_queue<node>q;
	q.push(node{sx, sy, 0, 0, 0});
	vis[sx][sy] = 0;
	s[sx][sy] = '+';
	while(q.size()){
		node u = q.top();
		q.pop();
		for (int i = 0; i < 4; i++){
			int x = u.x + dist[i][0], y = u.y + dist[i][1];
			if(x < 1 || x > n || y < 1 || y > m || s[x][y] == '*') continue;
			if(i == 0){
				if(u.r + 1 > r) continue;
				if(vis[x][y] > u.r + 1 + u.l || !vis[x][y]){
					q.push(node{x, y, u.r + u.l + 1, u.l, u.r + 1});
					vis[x][y] = u.r + u.l + 1;
					s[x][y] = '+';
				}
			}else if(i == 1){
				if(u.l + 1 > l) continue;
				if(vis[x][y] > u.r + u.l + 1 || !vis[x][y]){
					q.push(node{x, y, u.r + u.l + 1, u.l + 1, u.r});
					vis[x][y] = u.r + u.l + 1;
					s[x][y] = '+';
				}
			}else{
				if(vis[x][y] > u.r + u.l + 1 || !vis[x][y]){
					q.push(node{x, y, u.r + u.l + 1, u.l, u.r});
					vis[x][y] = u.r + u.l + 1;
					s[x][y] = '+';
				}
			}
		}
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d %d", &n, &m);
	scanf("%d %d", &sx, &sy);
	scanf("%d %d", &l, &r);

	for (int i = 1; i <= n; i++){
		scanf("%s", s[i] + 1);
	}
	bfs();
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if(s[i][j] == '+') ans++;
		}
	}
	printf("%d\n", ans);

	return 0;
}
/**/

 

全部评论

相关推荐

微风不断:兄弟,你把四旋翼都做出来了那个挺难的吧
点赞 评论 收藏
分享
威猛的小饼干正在背八股:挂到根本不想整理
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务