Educational Codeforces Round 25

A

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
char st[105];
int n;

int main(){
	scanf("%d", &n);
	scanf("%s", st);
	int len = strlen(st);
	st[len] = '0';
	int i = 0;
	while(i <= len){
		int cnt = 0;
		while(st[i] == '1' && i <= len)	cnt++, ++i;
		printf("%d", cnt);
		cnt = 0;
		while(st[i] == '0' && i <= len)	cnt++, ++i;
		for(int i = 0; i < cnt - 1; ++i)
			printf("0");
	}
	puts("");
	return 0;
}

B

枚举每一个空位,填上X判断是否有五个连续的X

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 5 + 10;
char mar[qq][qq];
bool Check(){
	for(int i = 1; i <= 10; ++i) {
		for(int j = 1; j <= 10; ++j) {
			int x = i, y = j;
			int cnt = 0, num = 0;
			while(cnt < 5 && x < 11) {
				if(mar[x][y] == 'X')	num++;
				cnt++;
				x++;
			}
			if(num == 5)	return true;
			cnt = num = 0;
			x = i, y = j;
			while(cnt < 5 && y < 11) {
				if(mar[x][y] == 'X')	num++;
				cnt++;
				y++;
			}
			if(num == 5)	return true;
			cnt = num = 0;
			x = i, y = j;
			while(x < 11 && y < 11 && cnt < 5) {
				if(mar[x][y] == 'X')	num++;
				cnt++, x++, y++;
			}
			if(num == 5)	return true;
			cnt = num = 0;
			x = i, y = j;
			while(x > 0 && y > 0 && cnt < 5) {
				if(mar[x][y] == 'X')	num++;
				cnt++, x++, y--;
			}
			if(num == 5)	return true;
		}
	}
	return false;
}


int main(){
	for(int i = 1; i <= 10; ++i) {
		scanf("%s", mar[i] + 1);
	}
	for(int i = 1; i <= 10; ++i) {
		for(int j = 1; j <= 10; ++j) {
			if(mar[i][j] != '.')	continue;
			mar[i][j] = 'X';
			if(Check()){
				puts("YES");
				return 0;
			}
			mar[i][j] = '.';
		}
	}
	puts("NO");
	return 0;
}

C

题意:n道题,已经解决了难度为k的题,能解决某道难度为ai的题的条件是 已经解决过的某道题难度为d, d > ai / 2则可以解决ai这道题,问最少需要在其他OJ解决多少题,才能把给定的n个题解决。

思路:每次对k进行最大值的取值

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
int dif[qq];
int n, k;


int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", dif + i);
	}
	sort(dif + 1, dif + 1 + n);
	int cnt = 0;
	for(int i = 1; i <= n; ++i) {
		if(k * 2 < dif[i]) {
			while(k * 2 < dif[i]) {
				k = k * 2;
				cnt++;
			}
			k = max(k, dif[i]);
		}
		k = max(k, dif[i]);
	}
	printf("%d\n", cnt);
	return 0;
}

D

题意:两个字符串s和t,s中由 '?'和小写字母组成,t由小写字母组成,s字符串中可以交换任意两个字符,现在问你填充s中的问号使得s中有最大数量的不相交的t字符串(交换位置后)

思路:- - 可以暴力答案,我这里用的二分

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e6 + 10;
char st[qq], t[qq];
LL nums[30], numt[30];
LL num[30], p[30];
bool Check(LL x, LL cnt) {
	for(int i = 0; i < 26; ++i) {
		if(numt[i] == 0){
			num[i] = 0;
			continue;
		}
		if(nums[i] - numt[i] * x >= 0)	num[i] = 0;
		else num[i] = numt[i] * x - nums[i];
		cnt = cnt - num[i];
		if(cnt < 0)	return false;
	}
	if(cnt < 0)	return false;
	return true;
}


int main(){
	scanf("%s%s", st, t);
	LL cnt = 0;
	int lens = strlen(st);
	for(int i = 0; i < lens; ++i) {
		if(st[i] == '?')	cnt++;
		else nums[st[i] - 'a']++;
	}
	int lent = strlen(t);
	for(int i = 0; i < lent; ++i) {
		numt[t[i] - 'a']++;
	}
	LL l = 0, r = 1e9, ans = -1, mid;
	while(l <= r) {
		mid = (l + r) / 2;
		if(Check(mid, cnt)) {
			for(int i = 0; i < 26; ++i) {
				p[i] = num[i];
			}
			ans = mid;
			l = mid + 1;
		}else {
			r = mid - 1;
		}
	}
	int j = 0;
	for(int i = 0; i < 26; ++i) {
		if(p[i] == 0)	continue;
		while(p[i] > 0 && j < lens) {
			if(st[j] == '?')	st[j] = i + 'a', p[i]--;
			j++;
		}
	}
	for(int i = 0; i < lens; ++i) {
		if(st[i] == '?')	st[i] = 'a';
	}
	puts(st);
	return 0;
}

E

题意:n个节点,m条有向边,每个节点有一个label值,对于一条有向边u->v, 要求u的label小于v的label,最后按1到n输出每一个节点的label,要求字典序最小

还没看懂这个思路,先挖个坑

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
vector<int> vt[qq];
int n, m;
int deg[qq];
int vis[qq];
priority_queue<int> Q;

int main(){
	scanf("%d%d", &n, &m);
	int a, b;
	for(int i = 1; i <= m; ++i) {
		scanf("%d%d", &a, &b);
		deg[a]++;
		vt[b].pb(a);
	}
	for(int i = 1; i <= n; ++i) {
		if(deg[i] == 0)	Q.push(i);
	}
	int num = n;
	while(!Q.empty()) {
		int u = Q.top();
		Q.pop();
		for(int i = 0; i < (int)vt[u].size(); ++i) {
			int v = vt[u][i];
			deg[v]--;
			if(deg[v] == 0)	Q.push(v);
		}
		vis[u] = num--;
	}
	for(int i = 1; i <= n; ++i) {
		printf("%d ", vis[i]);
	}
	puts("");
	return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值