Codeforces Round #482 (Div. 2) :B - Treasure Hunt

题目链接:http://codeforces.com/contest/979/problem/B

解题心得:

  • 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必须改变自己字符串中的一个字母,最后得分就是字符串中出现字符最多的字母的次数。
  • 感觉这个题从题目描述到做法都像一个脑筋急转弯。主要明白一点,如果一个数要变回自己要怎么变。自己->其他->自己。自己->其他->其他->自己,推几个特例很容易就出来了。
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e5+100;
 4 struct Person{
 5     string name;
 6     int Max;
 7     vector <int> ve;
 8 }p[4];
 9 
10 int change_times,len;
11 void init() {
12     map <char, int> maps;
13     for(int i='a', j='A';i<='z'&&j<='Z';i++,j++) {
14         maps[i] = 0;
15         maps[j] = 0;
16     }
17     char ri[maxn];
18     p[0].name = "Kuro";
19     p[1].name = "Shiro";
20     p[2].name = "Katie";
21     scanf("%d",&change_times);
22     map <char, int> :: iterator iter;
23     for(int i=0;i<3;i++) {
24         maps.clear();
25         scanf("%s",ri);
26         len = strlen(ri);
27         for(int j=0;j<len;j++)
28             maps[ri[j]]++;
29         for(iter=maps.begin();iter!=maps.end();iter++){
30             p[i].ve.push_back(iter->second);
31         }
32         for(int k='a', j='A';k<='z'&&j<='Z';k++,j++) {
33             if(maps[k] == 0 || maps[j] == 0)
34                 p[i].ve.push_back(0);
35         }
36     }
37 }
38 
39 bool cmp(Person a, Person b) {
40     return a.Max > b.Max;
41 }
42 
43 void solve() {
44     for(int i=0;i<3;i++) {
45         for(int j=0;j<p[i].ve.size();j++) {
46             int k = p[i].ve[j];
47             if(k == len && change_times == 1) {
48                 p[i].Max = len -1;
49                 break;
50             }
51             int ch = len - k;
52             if(change_times < ch) {
53                 p[i].Max = max(p[i].Max, k+change_times);
54             } else {
55                 p[i].Max = len;
56             }
57         }
58     }
59     sort(p, p+3, cmp);
60     if(p[0].Max == p[1].Max)
61         printf("Draw");
62     else
63         cout<<p[0].name<<endl;
64 }
65 
66 int main() {
67     init();
68     solve();
69     return 0;
70 }
View Code

猜你喜欢

转载自www.cnblogs.com/GoldenFingers/p/9281145.html