Codeforces Round #258 (Div. 2)

A

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 #include<list>
11 using namespace std;
12 #define N 135
13 #define LL long long
14 #define INF 0xfffffff
15 const double eps = 1e-8;
16 const double pi = acos(-1.0);
17 const double inf = ~0u>>2;
18 
19 
20 int main()
21 {
22 
23     int n,m;
24     cin>>n>>m;
25     if(min(n,m)%2)
26     puts("Akshat");
27     else puts("Malvika");
28     return 0;
29 }
View Code

B

排序后比较

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 #include<list>
11 using namespace std;
12 #define N 101000
13 #define LL long long
14 #define INF 0xfffffff
15 const double eps = 1e-8;
16 const double pi = acos(-1.0);
17 const double inf = ~0u>>2;
18 int a[N],b[N];
19 
20 int main()
21 {
22 
23     int n,i;
24     cin>>n;
25     for(i = 1; i <= n; i++)
26     {
27         cin>>a[i];
28         b[i] = a[i];
29     }
30     sort(a+1,a+n+1);
31     int f = 0;
32     int flag = 1,st = 1,en = 1;
33     for(i = 1; i <= n ;i++)
34     {
35         if(a[i]!=b[i]&&!f)
36         {
37             st = i;
38             f = 1;
39         }
40         else if(a[i]!=b[i])
41         en = i;
42     }
43     int j = en;
44     for(i = st ; i <= en ; i++)
45     {
46         if(a[j--]!=b[i])
47         {
48             flag = 0;
49             break;
50         }
51     }
52     if(flag) printf("yes\n%d %d\n",st,en);
53     else printf("no\n");
54     return 0;
55 }
View Code

C

根据d1d2的符号 分四种情况讨论,注意k和n的取值范围

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 #include<list>
11 using namespace std;
12 #define N 101000
13 #define LL long long
14 #define INF 0xfffffff
15 const double eps = 1e-8;
16 const double pi = acos(-1.0);
17 const double inf = ~0u>>2;
18 int a[N],b[N];
19 
20 int main()
21 {
22 
23     int t,i,j;
24     cin>>t;
25     LL n,k,d1,d2;
26     while(t--)
27     {
28         LL tk;
29         scanf("%I64d%I64d%I64d%I64d",&n,&k,&d1,&d2);
30 
31         tk = n-k;
32         if(n%3!=0)
33         {
34             puts("no");
35             continue;
36         }
37         if(d1+d2+d2<=k&&3*(d1+d2)<=n)
38         {
39             LL k1 = d1+d2+d1;
40             if((tk>=k1&&(tk-k1)%3==0))
41             {
42                 puts("yes");
43                 continue;
44             }
45         }
46         if(max(d1,d2)+abs(d1-d2)<=k&&3*d1<=n&&3*d2<=n)
47         {
48             LL k2 = d1+d2;
49             if(tk>=k2&&(tk-k2)%3==0)
50             {
51                 puts("yes");
52                 continue;
53             }
54         }
55         if((d1+d2+d1)<=k&&3*(d2+d1)<=n)
56         {
57             LL k3 = d2+d2+d1;
58             if((tk>=k3&&(tk-k3)%3==0))
59             {
60                 puts("yes");
61                 continue;
62             }
63         }
64         if((d1+d2)<=k&&3*max(d1,d2)<=n)
65         {
66             LL k4 = max(d1,d2)+abs(d2-d1);
67             if(tk>=k4&&(tk-k4)%3==0)
68             {
69                 puts("yes");
70                 continue;
71             }
72         }
73         puts("no");
74     }
75     return 0;
76 }
View Code

 

D

因为只含ab 所以只要头尾相同肯定就是回文串,然后就统计一下第奇偶个位置上a,b的数目计数就可以了。

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 100010
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 char s[N];
18 LL num[2][2],ans[2];
19 int main()
20 {
21     int n,i,j;
22     cin>>s;
23     int k = strlen(s);
24     for(i = 0 ;i < k ;i++)
25     {
26         j = s[i]-'a';
27         num[i&1][j]++;
28         ans[0]+=num[(i+1)&1][j];
29         ans[1]+=num[i&1][j];
30     }
31     cout<<ans[0]<<" "<<ans[1]<<endl;
32     return 0;
33 }
View Code

 

E

组合数学的知识。

组合数学P113有同等类型题目讲解。

具有重复的组合,可以先求出无限制的T*集合  然后根据容斥原理去除超出限制的组合个数。

T* = C(n+m-1,n)  = C(n+m-1,m-1)

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 100010
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 #define mod 1000000007
18 LL a[22],inv[22];
19 LL getInv(LL x)
20 {
21     LL ret = 1;
22     x %= mod;
23     for (int a = mod - 2; a; a /= 2, x = x * x % mod)
24         if (a % 2 == 1)
25             ret = ret * x % mod;
26     return ret;
27 }
28 
29 int C(LL n, int m)
30 {
31     if (n < m)
32         return 0;
33     int ret = 1;
34     for (LL i = n; i > n - m; -- i)
35         ret = ret * (i % mod) % mod * inv[n - i + 1] % mod;
36     return ret;
37 }
38 int main()
39 {
40     int n,i,j;
41     LL s;
42     for(i = 0 ; i <= 20 ; i++)
43         inv[i] = getInv(i);
44     cin>>n>>s;
45     for(i = 0 ; i< n; i++)
46         cin>>a[i];
47     LL ans = C(s+n-1,n-1);//元素个数无限制的S集
48     for(i = 1; i < (1<<n) ; i++)
49     {
50         LL ss = s;
51         int o = 0;
52         for(j =0 ; j< n ; j++)
53             if(i&(1<<j))
54             {
55                 ss-=(a[j]+1);//超过限制的
56                 o++;
57             }
58         if(ss<0) continue;
59         if(o&1) ans-=C(ss+n-1,n-1);
60         else ans+=C(ss+n-1,n-1);
61         ans = (ans%mod+mod)%mod;//mod
62     }
63     cout<<ans<<endl;
64     return 0;
65 }
View Code
posted @ 2014-07-25 12:16  _雨  阅读(183)  评论(0编辑  收藏  举报