2019CCPC湖南全国邀请赛的题解

Hello GDCPC

1005 Hello GDCPC

题意:给你一个n长的字符串, 问你能从中找出多少个xtCpc字符串,注意!HDu这场重现赛上的样列的题目是错的!还要多组输入!!话说hdu上的比赛已经发生好多次这种情况了,,,字符串可以分开,但每个字符顺序不能变;

题解:我们想到如果我们要找最多的字符串,那么最先出现的字符前缀为何不与最先出现的字符后缀匹配呢?一旦出现一个x,那么后面能和他组成目标字符串的就优先和他匹配,这样能吧尽量多的x匹配成目标字符串,不浪费任何一个x,那么我们遍历这个字符串,,当出现字符能成为有效后缀时就将字符位的有效量加一,而成为有效后缀的条件就是他前面的那个字符前缀有效量不为零,当集满一个字符串就找到了一个字符串了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*************************************************************************
> File Name: hello.cpp
> Author: ghost_lzw
> Mail: lanzongwei@gmail.com
> Created Time: Sun May 19 12:06:45 2019
************************************************************************/

#include<bits/stdc++.h>
using namespace std;

int fin[6];
int n;
map<char, int>M;

int solve(string tem){
int tot = 0;
for(int i = 0; i < n; i++){
if(M.find(tem[i]) == M.end())continue;
int wz = M[tem[i]];
if(wz == 1)fin[wz]++;
else if(fin[wz - 1] > fin[wz])fin[wz]++;//判断前面那个字符是否存在;
if(fin[5]){
for(int j = 1; j <= 5; j++)
fin[j]--;
tot++;
}
}
return tot;
}

int main(){
M['x'] = 1, M['t'] = 2;
M['C'] = 3, M['p'] = 4;
M['c'] = 5;
int tot = 0;
while(~scanf("%d", &n)){
memset(fin, 0, sizeof(fin));
string tem;
cin>> tem;
tot = solve(tem);
printf("%d\n", tot);
}

return 0;
}

SSY and JLBD

1011

题意:给你14块麻将,如果你每种麻将的1和9都有,且东南西北中发财白板全部都有,那么就输出shisanyao,如果你只有一种麻将,且1至少有三个,9至少有三个,其他2~8至少有一个;

题解:直接模拟,一开始读错题了,,所以写法麻烦了,,,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*************************************************************************
> File Name: ssy.cpp
> Author: ghost_lzw
> Mail: lanzongwei@gmail.com
> Created Time: Sun May 19 14:03:07 2019
************************************************************************/

#include<bits/stdc++.h>
using namespace std;

map<string, int>M;
string word[] = {"dong", "nan", "xi", "bei", "zhong", "fa", "bai"};
char aim[] = {'p', 'w', 's'};

bool PanHua(){
int can = 0;
if(M["1w"] == 0 && M["1s"] == 0 && M["1p"] >= 3)can = 1;
if(M["1w"] >= 3 && M["1s"] == 0 && M["1p"] == 0)can = 2;
if(M["1w"] == 0 && M["1s"] >= 3 && M["1p"] == 0)can = 3;
if(!can)return false;
for(int i = 0; i < 9; i++){
string ju;
ju += char('1' + i);
if(M[ju + aim[can - 1]] < (i == 0 || i == 9 ? 3 : 1))return false;
}
for(int i = 0; i < 7; i++)
if(M[word[i]])return false;
return true;
}

bool PanSan(){
int more = 0;
for(int j = 0; j < 3; j++)
for(int i = 0; i < 9; i += 8){
string ju;
ju += char('1' + i);
int temp;
if((temp = M[ju + aim[j]]) <= 0)
return false;
else more += temp - 1;
}
for(int i = 0; i < 7; i++)
if(M[word[i]] <= 0)return false;
else more += M[word[i]] - 1;
if(more == 1)return true;
else return false;
}

int main(){
string tem;
while(cin>>tem){
M[tem]++;
}
if(PanHua()){
puts("jiulianbaodeng!");
}else if(PanSan()){
puts("shisanyao!");
}else
puts("I dont know");

return 0;
}

Can you raed it croretcly?

1012

题意:给你两个字符串,如果相同输出相同,如果第一个字符和最后一个字符相同,其他能通过交换达到相同,就输出Yes,其他输出No

题解:简单模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*************************************************************************
> File Name: 12.cpp
> Author: ghost_lzw
> Mail: lanzongwei@gmail.com
> Created Time: Sun May 19 12:14:05 2019
************************************************************************/

#include<bits/stdc++.h>
using namespace std;

int main(){
string wa, ri;
while(cin >> wa >> ri){
if(wa == ri)puts("Equal");
else {
int lwa = wa.length(), lri = ri.length();
if(lwa != lri)puts("No");
else if(wa[0] == ri[0] && wa[lwa - 1] == ri[lwa - 1]){
map<char, int>ju, jj;
for(int i = 0; i < lwa; i++)
ju[wa[i]]++, jj[ri[i]]++;
bool flag = true;
for(int i = 0; flag && i < lwa; i++)
if(ju[wa[i]] != jj[wa[i]])flag = false;
if(flag)puts("Yes");
else puts("No");
}
else puts("No");
}
}

return 0;
}

后面再补(咕咕咕警告)

Comments

⬆︎TOP