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

A

#include<bits/stdc++.h>
using namespace std;

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    int b = a[0] + a[1];
    int ans = 0;
    if(a[2] > b) ans = (a[2] - b) + 1;
    else if(a[2] == b) ans = 1;
    else ans = 0;
    cout << ans << endl;
    return 0;
}

B

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;

int solve(ll n){
	int cnt = 0;
	while(n){
		if(n%2 == 1) cnt ++;
		n /= 2;
	}
	return cnt;
}

int main(){
	/*for(int i = 0; i <= 10; i++){
		int cnt = 0;
		for(int j = 0; j <= i; j++){
			if((i - j) == (i ^ j)) cnt ++;
		}
		printf("%d ", cnt);
	}*/
	int t;
	cin >> t;
	while(t--){
		ll a, num;
		cin >> a;
		int tot = solve(a);
		num = 1 << tot;
		cout << num << endl;
	}
	return 0;
}

C

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;

char s[maxn];

int main(){
    int n;
    scanf("%d %s", &n, s);
    sort(s, s+n);
    puts(s);
    return 0;
}

D


 #include<bits/stdc++.h>
using namespace std;
int n,m;
int x,y;
int ln,rn;
const int maxn = 2336;
char maze[maxn][maxn];
bool vis[maxn][maxn];
struct node{
    int x,y;
    int l,r;
    node (int _x, int _y, int _l, int _r) {x = _x, y = _y, l = _l, r = _r;}
};
bool check(int x,int y){
    return x >= 1 && x <= n && y >= 1 && y <= m;
}
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int LL[maxn][maxn],RR[maxn][maxn];
int ans;
void bfs(int sx, int sy){
    queue<node> q;
    q.push(node(sx,sy,ln,rn));
    for(int i = 1; i <= n; i++){
    	for(int j = 1; j <= m; j++){
    		LL[i][j] = RR[i][j] = -1;
		}
	}
    while(!q.empty()){
        node rt = q.front();
        q.pop();
		if(!vis[rt.x][rt.y]){
            ans++;
        	vis[rt.x][rt.y] = 1;
		}
        for(int i = 0; i < 4; i++){
            int dx = rt.x + dir[i][0];
            int dy = rt.y + dir[i][1];
            int ll = rt.l;
			int rr = rt.r;
            if(i == 1) --ll;
            if(i == 0) --rr;
            if(check(dx,dy)&&maze[dx][dy] == '.' && ll >= 0 && rr >= 0 && (ll > LL[dx][dy] || rr > RR[dx][dy])) {
            	q.push(node(dx,dy,ll,rr));
            	LL[dx][dy] = ll;
            	RR[dx][dy] = rr;
			}
        }
    }
}
int main(){
    ans = 0;
    cin >> n >> m >> x >> y >> ln >> rn;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> maze[i][j];
        }
    }
    bfs(x, y);
    cout << ans << endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值