第一次比赛的时候离4题最近的一次,可惜思维太慢加手速太慢最终没有能在比赛中A掉。

A:可知,能且只能操作MIN(N,M)次,所以判断奇偶即可

 1 // File Name: a.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月24日 星期四 23时31分20秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 
25 using namespace std;
26 
27 int main(){
28   int n , m ; 
29   scanf("%d %d",&n,&m);
30   n = min(n,m);
31   if(n % 2 == 1)
32       printf("Akshat\n");
33   else printf("Malvika\n");
34 return 0;
35 }
View Code

B:分几种情况讨论即可

 1 // File Name: b.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月24日 星期四 23时40分41秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 
25 using namespace std;
26 int a[100005];
27 int b[100005];
28 int main(){
29   int n ;
30   scanf("%d",&n);
31   int ok = 0 ;
32   for(int i = 1;i <= n;i ++)
33   {
34     scanf("%d",&a[i]);
35     if(a[i] < a[i-1])
36     {
37         b[i] = b[i-1]+1;
38         b[i-1] = 0;
39     }
40   }
41   a[n+1] = 1e9+7;
42   int sum = 0 ; 
43   int site = 0 ;
44   for(int i =1 ;i <= n;i ++)
45   {
46      if(b[i])
47      {
48          sum ++ ;
49          site = i; 
50      }
51   }
52 
53   if(sum >= 2)
54      printf("no\n");   
55   if(sum == 0 )
56       printf("yes\n1 1\n");
57   if(sum == 1 )
58   {
59       if(a[site] > a[site -b[site]-1] && a[site-b[site]] < a[site+1])
60         printf("yes\n%d %d\n",site-b[site],site);
61       else printf("no\n");
62   }
63 return 0;
64 }
View Code

C:二进制枚举所有情况,再看其是否满足K和M 的要求

 1 // File Name: c.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月24日 星期四 23时57分43秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 
25 #define LL long long 
26 using namespace std;
27 
28 int main(){
29     int ca; 
30     scanf("%d",&ca);
31     while(ca--)
32     {
33        LL n , k ,d1,d2;
34        scanf("%I64d %I64d %I64d %I64d",&n,&k,&d1,&d2);
35        LL a[4];
36        LL b[4];
37        LL is = 0 ;
38        for(LL i = 0;i <= 3; i ++)
39        {
40            memset(a,0,sizeof(a));
41            memset(b,0,sizeof(b));
42            LL t = k ; 
43            if(i % 2 == 0 )
44            {
45                t -= d1;
46                b[1] = d1;
47            }
48            else {
49                t += d1;
50                b[1] = -d1;
51            }
52            
53            if(i /2 == 0 ){
54                t -=d2;
55                b[3] = d2; 
56            }
57            else{ t += d2;
58               b[3] = -d2;
59            }
60            if(t % 3 != 0 )
61                continue;
62 
63            LL ok = 0 ; 
64            for(LL i = 1;i <= 3 ;i ++)
65            {
66               a[i] = t/3 + b[i];
67               if(a[i] < 0)
68                   ok = 1; 
69            }
70            if(ok == 1 )
71                continue;
72 
73            if(n % 3 != 0)
74                continue;
75            LL p = n/3;
76 
77            ok = 0 ; 
78            for(LL i =1;i <= 3;i ++)
79            {
80               if(a[i]>p)
81                   ok = 1; 
82            }
83            if(ok == 1)
84                continue;
85            is = 1; 
86            break;
87        }
88        if(is)
89            printf("yes\n");
90        else printf("no\n");
91        
92     }
93 return 0;
94 }
View Code

D:因为字符串只有A,B组成,可知一个字符串的字串个数有 len*(len+1)/2 种,所以只有两个端点取到相同的字符才能构成 good 字符串,分奇偶的话就只需要统计

每种字符出现的位置有多少个偶数,多少个奇数,排除只有一个字母的字串的情况(单独计数)同为偶数或奇数的长度为奇数,奇偶互异的长度为偶数,想清楚这些就可以求解了。

  1 // File Name: d.cpp
  2 // Author: darkdream
  3 // Created Time: 2014年07月25日 星期五 00时31分33秒
  4 
  5 #include<vector>
  6 #include<list>
  7 #include<map>
  8 #include<set>
  9 #include<deque>
 10 #include<stack>
 11 #include<bitset>
 12 #include<algorithm>
 13 #include<functional>
 14 #include<numeric>
 15 #include<utility>
 16 #include<sstream>
 17 #include<iostream>
 18 #include<iomanip>
 19 #include<cstdio>
 20 #include<cmath>
 21 #include<cstdlib>
 22 #include<cstring>
 23 #include<ctime>
 24 #define LL long long 
 25 using namespace std;
 26 char str[100005];
 27 int sum[100005];
 28 LL pike2(LL x)
 29 {
 30    return x*(x-1)/2;
 31 }
 32 int main(){
 33     scanf("%s",str);
 34     int len = strlen(str);
 35     int t= 0;
 36     int p = 0 ;
 37     for(int i =1 ;i < len ;i ++)
 38     {
 39         if(str[i] != str[i-1])
 40          {
 41             t ++ ; 
 42             sum[t] = i-p;
 43             p = i;    
 44          }        
 45     }
 46     t ++ ; 
 47     sum[t] = len -p ;
 48     LL sume ,sumo;
 49     sume = sumo = 0 ;
 50     LL sumek[3];
 51     LL sumok[3];
 52     LL ans = 1ll*len*(len+1)/2;
 53     LL tsum = 0 ;
 54     memset(sumek,0,sizeof(sumek));
 55     memset(sumok,0,sizeof(sumok));
 56     for(int i =1;i <= t ;i ++)
 57     {
 58         if(i % 2 == 1)
 59         {
 60           sumo += sum[i];
 61           if(sum[i] % 2 == 0 )
 62           {
 63               sumok[1] += sum[i]/2;
 64               sumok[2] += sum[i]/2;
 65           }else{
 66              if((tsum+1)%2 == 1)
 67              {
 68                 sumok[1] += sum[i]/2+1;
 69                 sumok[2] += sum[i]/2;
 70              }else{
 71                  sumok[1] += sum[i]/2;
 72                  sumok[2] += sum[i]/2+1;
 73              }
 74           }
 75            
 76         }else {
 77           if(sum[i] % 2 == 0 )
 78           {
 79               sumek[1] += sum[i]/2;
 80               sumek[2] += sum[i]/2;
 81           }else{
 82              if((tsum+1)%2 == 1)
 83              {
 84                 sumek[1] += sum[i]/2+1;
 85                 sumek[2] += sum[i]/2;
 86              }else{
 87                  sumek[1] += sum[i]/2;
 88                  sumek[2] += sum[i]/2+1;
 89              }
 90           }
 91           sume += sum[i] ; 
 92         }
 93         tsum += sum[i];
 94     }
 95 //    printf("%lld %lld %lld %lld\n",sumok[1],sumok[2],sumek[1],sumek[2]);
 96     ans = ans - sumo*sume;
 97     LL temp = pike2(sumek[1])+pike2(sumek[2])+pike2(sumok[1]) + pike2(sumok[2])+sumo+sume;
 98     printf("%lld %lld\n",ans-temp,temp); 
 99 return 0;
100 }
View Code

又看到Bman巨简洁的代码,膜拜一下

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6 const int maxn = 1e5 + 10;
 7 char s[maxn];
 8 int a[2][2];
 9 int main()
10 {
11     scanf("%s", s);
12     long long x = 0, y = 0;
13     for(int i = 0; s[i] != '\0'; i++)
14     {
15         a[i&1][s[i] - 'a']++;
16         x += a[i&1][s[i] - 'a'];
17         y += a[(i&1)^1][s[i] - 'a'];
18     }
19     cout << y << " " << x;
20     return 0;
21 }
View Code

E:容斥定理 未解

posted on 2014-07-25 08:42  dark_dream  阅读(200)  评论(0编辑  收藏  举报