AtCoder Beginner Contest 161 E Yutori 贪心

AtCoder Beginner Contest 161 The   number of contestants is 9927   fast, see all questions 5 minutes after the start of the contest

AtCoder Beginner Contest 161 E Yutori 贪心

See https://blog.csdn.net/mrcrack/article/details/104454762 for the general catalog

Online evaluation address https://atcoder.jp/contests/abc161/tasks/abc161_e

The sample simulation is as follows

11 3 2
ooxxxoxxxoo

6
工作日选择
(1,6,10)正向选择
(1,6,11)
(2,6,10)
(2,6,11)反向选择
必须工作的日子是6

5 2 3
ooxoo

1
5
工作日选择
(1,5)正向选择,反向选择
必须工作的日子是1,5

5 1 0
ooooo
工作日选择
(1)
(2)
(3)
(4)
(5)
没有必须工作的日子

16 4 3
ooxxoxoxxxoxoxxo

11
16
工作日选择
(1,5,11,16)正向选择
(2,5,11,16)反向选择
必须工作的日子是11,16

By choosing a working day, you can see that there is the biggest difference between forward selection and reverse selection. If there are similar working days in the two options, then it is the day that must work.

The idea is the same as https://www.cnblogs.com/zdragon1104/p/12636429.html

#include <stdio.h>
#define maxn 200010
int L[maxn],R[maxn],lc,rc;
char s[maxn];
int main(){
	int n,k,c,i;
	scanf("%d%d%d%s",&n,&k,&c,s+1);
	for(i=1;i<=n;){//正向寻找
		if(s[i]=='o'){
			L[++lc]=i,i+=c;
			if(lc==k)break;
		}
		i++;
	}
	for(i=n;i>=1;){//反向寻找
		if(s[i]=='o'){
			R[++rc]=i,i-=c;
			if(rc==k)break;
		}
		i--;
	}
	for(i=1;i<=k;i++)//重合工作日的寻找
		if(L[i]==R[k-i+1])printf("%d\n",L[i]);
	return 0;
}

 

 

 

 

 

 

 

 

 

 

Published 660 original articles · praised 562 · 480,000 views

Guess you like

Origin blog.csdn.net/mrcrack/article/details/105327778