ABC348

A

link

这道题就先输出整个的\(oox\),再输出剩一个两个的。

点击查看代码
#include<bits/stdc++.h>

using namespace std;

int n;

signed main(){
	
	cin >> n;
	
	int t = n/3;
	for(int i = 1;i <= t;++ i)
		cout << "oox";
	
	if(n%3 == 1) cout << "o";
	if(n%3 == 2) cout << "oo";
	
	return 0;
	
}

B

link

可以用二维数组记录每个点到其他各点的距离,再找最小的。

点击查看代码
#include<bits/stdc++.h>

#define int long long

using namespace std;

int n;
int x[105],y[105];
double g[105][105];

signed main(){
	
	cin >> n;
	for(int i = 1;i <= n;++ i)
		cin >> x[i] >> y[i];
	
	for(int i = 1;i <= n;++ i){
		for(int j = 1;j < i;++ j){
			g[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j])
			+(y[i]-y[j])*(y[i]-y[j]));
			g[j][i] = g[i][j];
		}
	}
	
	for(int i = 1;i <= n;++ i){
		double mx =-1e6;
		for(int j = 1;j <= n;++ j)
			if(i != j) mx = max(mx,g[i][j]);
		for(int j = 1;j <= n;++ j){
			if(abs(g[i][j]-mx) <= 1e-6&&i != j){
				cout << j << endl;
				break;
			}
		}
	}
	
	return 0;
	
}

C

link

这个题也不难。
把每个颜色中的最小值存下来,再从这些中取最大值。
判断这个颜色之前出没出现过,新建一个位置,否则再原来的位置上再取\(min\)

点击查看代码
#include<bits/stdc++.h>

#define int long long

using namespace std;

int n,c[200005],tp;
map<int,int> mp;

signed main(){
	
	cin >> n;
	for(int i = 1;i <= n;++ i){
		int a,cc;
		cin >> a >> cc;
		if(mp[cc]) c[mp[cc]] = min(c[mp[cc]],a);
		else mp[cc] = ++tp,c[mp[cc]] = a;
	}
	
	int ans = 0;
	for(int i = 1;i <= tp;++ i)
		ans = max(ans,c[i]);
	
	cout << ans;
	
	return 0;
	
}

D

link

一个普普通通的广搜。

点击查看代码
#include<bits/stdc++.h>

using namespace std;

int h,w;
int a[205][205];
int n;
int r,c,e;
int sx,sy,tx,ty;
int eng[205][205];
int le[205][205];
int dx[] = {0,0,0,1,-1};
int dy[] = {0,1,-1,0,0};

struct nd{
	int x,y;
};

signed main(){
	
	cin >> h >> w;
	for(int i = 1;i <= h;++ i)
		for(int j = 1;j <= w;++ j){
			char ch;
			cin >> ch;
			if(ch == '.')a[i][j] = 0;
			if(ch == '#')a[i][j] = 1;
			if(ch == 'S')a[i][j] = 0,sx = i,sy = j;
			if(ch == 'T')a[i][j] = 0,tx = i,ty = j;
		}
	cin >> n;
	for(int i = 1;i <= n;++ i){
		cin >> r >> c >> e;
		eng[r][c] = e;
	}
	
	if(eng[sx][sy] == 0){
		cout << "No";
		return 0;
	}
	
	queue<nd> q;
	q.push({sx,sy});
	le[sx][sy] = eng[sx][sy];
	while(!q.empty()){
		int x = q.front().x;
		int y = q.front().y;
		q.pop();
		for(int i = 1;i <= 4;++ i){
			int xx = x+dx[i];
			int yy = y+dy[i];
			if(a[xx][yy] == 1) continue;
			if(xx <= 0||yy <= 0||xx > h||yy > w)
				continue;
			if(max(le[x][y]-1,eng[xx][yy]) > le[xx][yy]){
				q.push({xx,yy});
				le[xx][yy] = max(le[x][y]-1,eng[xx][yy]);
			}
			if(xx == tx&&yy == ty){
				cout << "Yes";
				return 0;
			}
		}
	}
	
	cout << "No";
	
	return 0;
	
}

E

link

posted @ 2024-04-08 22:28  学贵坚持  阅读(18)  评论(0编辑  收藏  举报