SDUT 2536 字母哥站队(乱搞)

题目链接

今天比赛各种没状态,交错语言,各种二货错误。。。

这个题我乱搞过的,zyj从CF上找的,这个题,仔细的想一下,就可以发现一个结论,如果这一段里只有两个字母且这俩字母还敌对,那么就把把较少的删除。。枚举每一种敌对关系,遍历一遍就行了。

 1 #include <cstring>
 2 #include <cstdio>
 3 #include <string>
 4 #include <iostream>
 5 #include <map>
 6 #include <queue>
 7 using namespace std;
 8 char str[1000001];
 9 int o[100][100];
10 int o1[10000],o2[10000];
11 int main()
12 {
13     int n,len,i,j,ans,t1,t2;
14     char ch[5];
15     while(scanf("%s",str)!=EOF)
16     {
17         memset(o,0,sizeof(o));
18         scanf("%d",&n);
19         for(i = 1;i <= n;i ++)
20         {
21             scanf("%s",ch);
22             o1[i] = ch[0]-'a'+1;
23             o2[i] = ch[1]-'a'+1;
24             o[ch[0]-'a'+1][ch[1]-'a'+1] = 1;
25         }
26         len = strlen(str);
27         ans = 0;
28         for(i = 1;i <= n;i ++)
29         {
30             if(o[o1[i]][o2[i]] == 1)
31             {
32                 o[o1[i]][o2[i]] ++;
33                 o[o2[i]][o1[i]] ++;
34                 t1 = t2 = 0;
35                 for(j = 0;j <= len-1;j ++)
36                 {
37                     if(str[j]-'a'+1 == o1[i])
38                     {
39                         t1 ++;
40                     }
41                     else if(str[j]-'a'+1 == o2[i])
42                     {
43                         t2 ++;
44                     }
45                     else
46                     {
47                         ans += min(t1,t2);
48                         t1 = t2 = 0;
49                     }
50                 }
51                 ans += min(t1,t2);
52             }
53         }
54         printf("%d\n",ans);
55     }
56     return 0;
57 }

 

posted @ 2012-12-15 19:49  Naix_x  阅读(174)  评论(0编辑  收藏  举报