题目:MIN-MEX Cut
由於观察 3、4两点 ,推断用穷举的方式应该不会太复杂,分别举出 s[0] == '0'
跟 s[0] == '1'
的情况:
s | minimal sum of MEX |
---|---|
0 | 1 |
01 | 1 |
010 | 2 |
0101 | 2 |
01010 | 2 |
010101 | 2 |
0101010 | 2 |
s | minimal sum of MEX |
---|---|
1 | 0 |
10 | 1 |
101 | 1 |
1010 | 2 |
10101 | 2 |
101010 | 2 |
1010101 | 2 |
10101010 | 2 |
依照这两张表,把程序写出来就好
// https://codeforces.com/contest/1566/problem/B
#include <stdio.h>
#define SIZE (int)1e5
int count_part(char *s)
{
int result = 1;
char *p = s;
while (*(++p) != '\0')
if (*p != *(p-1))
result++;
return result;
}
int main()
{
int t, parts;
scanf("%d\n", &t);
while (t--) {
char s[SIZE+1];
scanf("%s", s);
parts = count_part(s);
if (parts == 1) {
if (*s == '0')
printf("1");
else
printf("0");
} else if (parts == 2) {
printf("1");
} else if (parts == 3 && *s == '1') {
printf("1");
} else {
printf("2");
}
printf("\n");
}
return 0;
}
从昨天的文章中,我们获得了数种进行绿野仙踪实验的方法 在今日的文章,假定我们已经获取用户的反馈。并...
Windows Event Log & FullEventLogView LOG 是监识调查...
逻辑运算子(Logical Operator)有 AND &&、OR ||、NOT...
今天我们要先来介绍 Gulp 基本的四个 API 提供使用 gulp.task 执行工作 gulp....
前言 为什麽要特别提一下 Payload ? 是因为像 mutations 跟 actions,其实...