题解 P9254 [PA 2022] Liczenie punktów

题目传送门

思路

盲猜题目暴力不会超时,结果还真就是……

我们可以先算出它的周期 10n\frac{10}{n},然后每次取出每个长度为一个周期的子字符串,再在这个长度为一个周期的字符串判断是否出现了 N。我们可以设置一个标记 flag,将其初始设置为 true。如果有 N 则把标记设置为 false,这时总数就不需要加 11。反之,如果这个子串中的所有字符都为 T,则 sum++

AC 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
using namespace std;

bool pd(string x){
if(x=="N") return 0;
else return 1;
}

int main(){
int n,sum=0,t;
string s,a;
cin >> n >> s;
t = n/10;
for(int i=0;i<=n/t-1;i++){
bool flag=true;
a = s.substr(i*t,t);
for(int j=0;j<=t-1;j++) if(pd(a.substr(j,1))==false) flag=false;
if(flag) sum++;
}
cout << sum;
return 0;
}

AC 记录


题解 P9254 [PA 2022] Liczenie punktów
https://sunnyli.咕咕咕.eu.org/solution-P9254/
作者
SunnyLi
发布于
2023年4月27日
许可协议