csust-8.7早训CF之800-1600分

目录

 

A - Text Document Analysis

B - Polycarp at the Radio

C - Lakes in Berland

D - Transformation: from A to B

E - Bill Total Value

F - The New Year: Meeting Friends


A - Text Document Analysis

 CodeForces - 723B 

题目链接https://codeforces.com/problemset/problem/723/B

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ok(p) ((p>='a' && p<='z') || (p>='A' && p<='Z')) 
string s;
int main()
{
	IOS;
	int n;
	cin >> n;
	cin >> s;
	int len = s.size();
	int mxlen = 0, word = 0, lglen = 0;
	for (int i = 0; i < len; i++) {
		lglen = 0;
		while (ok(s[i])) {
			lglen++; i++;
		}
		if (s[i] == '(') {
			i++;
			int mark = 0;
			while (s[i] != ')') {
				mark = 0;
				while (ok(s[i])) {
					if (!mark) word++;
					mark = 1; i++;
				}
				if (s[i]!=')') i++;			
			}
		}
		mxlen = max(mxlen, lglen);
	}
	cout << mxlen << " " << word << endl;
	return 0;
}

B - Polycarp at the Radio

 CodeForces - 723C 

题目链接https://codeforces.com/problemset/problem/723/C

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
const int mac = 1e5 + 10;
struct node
{
	int val, id;
}vis[mac];
int q[mac], vs[mac];
int a[mac];
int main()
{
	IOS;
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] <= m) q[a[i]]++;
	}
	cout << n / m << " ";
	int ave = n / m, nb = 0;
	for (int i = 1; i <= m; i++) {
		if (q[i] - ave < 0)
			vis[++nb].val = q[i] - ave, vis[nb].id = i;
	}
	int k = 1, head = 1, opo = 0;
	for (int i = 1; i <= nb; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[j]>m || !q[a[j]] || q[a[j]] > ave) {
				if (a[j]<=m && q[a[j]] > ave) q[a[j]]--;
				a[j] = vis[i].id; opo++;
				vis[i].val++; q[a[j]]++;
				if (vis[i].val >= 0) break;
			}
		}
	}
	cout << opo << endl;
	for (int i = 1; i <= n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}

C - Lakes in Berland

 CodeForces - 723D 

题目链接https://codeforces.com/problemset/problem/723/D

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
#define ok(x,y,n,m) (x>1 && x<n && y>1 && y<m)
#define ok2(x,y,n,m) (x>=0 && x<=n+1 && y>=0 && y<=m+1)
struct node
{
	int x, y;
	node(){}
	node(int x,int y):x(x),y(y){}
};
struct SZ
{
	vector<node>g;
	bool operator<(const SZ& a)const {
		return g.size() < a.g.size();
	}
};
SZ lak[3000];
char s[200][200];
int vis[60][60], mk[60][60], n, m, nb = 0;
void done(int x, int y);
int main()
{
	IOS;
	int k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++)
		cin >> s[i] + 1;
	for (int i = 0; i <= n + 1; i++) {
		s[i][0] = '.';
		s[i][m + 1] = '.';
	}
	for (int i = 0; i <= m + 1; i++) 
		s[0][i] = s[n + 1][i] = '.';
	int sx = 0, sy = 0;
	s[0][0] = '#';
	vis[0][0] = 1;
	queue<int>qx, qy;
	qx.push(0), qy.push(0);
	while (!qx.empty()) {
		int xx = qx.front(), yy = qy.front();
		qx.pop(); qy.pop();
		for (int i = 0; i < 4; i++) {
			int px = xx + dx[i], py = yy + dy[i];
			if (vis[px][py]) continue;
			vis[px][py] = 1;
			if (ok2(px, py, n, m) && s[px][py]=='.') {
				s[px][py] = '#';
				qx.push(px); qy.push(py);
			}
		}
	}
	for (int i = 2; i < n; i++) {
		for (int j = 2; j < m; j++) {
			if (s[i][j] == '.' && !vis[i][j]) {
				done(i, j);
			}
		}
	}
	if (nb <= k) {
		cout << "0" << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++)
				if (s[i][j]=='#') cout<<'.';
				else cout << s[i][j];
			cout << endl;
		}
	}
	else {
		int ans = 0;
		sort(lak + 1, lak + 1 + nb);
		for (int i = 1; i <= nb - k; i++) {
			ans += lak[i].g.size();
			for (int j = 0; j < lak[i].g.size(); j++) {
				int nx = lak[i].g[j].x, ny = lak[i].g[j].y;
				s[nx][ny] = '*';
			}
		}
		cout << ans << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++)
				if (s[i][j]=='#') cout<<'.';
				else cout << s[i][j];
			cout << endl;
		}
	}
	return 0;
}
void done(int x, int y)
{
	vis[x][y] = 1;
	nb++;
	lak[nb].g.push_back(node(x, y));
	queue<int>qx, qy;
	qx.push(x), qy.push(y);
	while (!qx.empty()) {
		int xx = qx.front(), yy = qy.front();
		qx.pop(); qy.pop();
		for (int i = 0; i < 4; i++) {
			int px = xx + dx[i], py = yy + dy[i];
			if (vis[px][py]) continue;
			vis[px][py] = 1;
			if (ok(px, py, n, m) && s[px][py] == '.') {
				lak[nb].g.push_back(node(px, py)); 
				qx.push(px); qy.push(py);
			}
		}
	}
}

D - Transformation: from A to B

 CodeForces - 727A 

题目链接https://codeforces.com/problemset/problem/727/A

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define ok(p) ((p>='a' && p<='z') || (p>='A' && p<='Z')) 
struct node
{
	ll d;
	vector<ll>g;
};
string s;
int main()
{
	IOS;
	ll a, b;
	cin >> a >> b;
	queue<node>q;
	node ss;
	ss.d = a; ss.g.push_back(a);
	q.push(ss);
	while (!q.empty()) {
		node p = q.front();
		q.pop();
		if (p.d > b) continue;
		if (p.d == b) {
			cout << "YES" << endl;
			cout << p.g.size() << endl;
			for (int i = 0; i < p.g.size(); i++) {
				cout << p.g[i] << " ";
			}
			cout << endl;
			return 0;
		}
		if (p.d * 2 <= b) {
			node nx = p;
			nx.d = p.d << 1; nx.g.push_back(p.d << 1);
			q.push(nx);
		}
		if (p.d * 10 + 1 <= b) {
			node nx = p;
			nx.d = p.d *10+1; nx.g.push_back(p.d *10+1);
			q.push(nx);
		}
	}
	cout << "NO" << endl;
	return 0;
}

E - Bill Total Value

 CodeForces - 727B 

题目链接https://codeforces.com/problemset/problem/727/B

 

F - The New Year: Meeting Friends

 CodeForces - 723A 

https://codeforces.com/problemset/problem/723/A

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
const int inf = 1e9 + 10;
int a[5500];
int main()
{
	IOS;
	int a, b, c;
	cin >> a >> b >> c;
	int ans = inf;
	int ans1 = abs(a - b) + abs(c - b);
	ans = min(ans, ans1);
	int ans2 = abs(a - b) + abs(c - a);
	ans = min(ans, ans2);
	int ans3 = abs(a - c) + abs(b - c);
	ans = min(ans, ans3);
	cout << ans << endl;
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值