Codeforces Round #666 (Div. 2) (A B C D)

##Practice link: https://codeforces.ml/contest/1397

 

solved: 3/5   rank:1488


 

##A. Juggling Letters

思路:统计n个字符串中各个字符的数量,然后只要各个字符的数量可以整除n,答案就是YES。

代码:

 1 //#include<bits/stdc++.h>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<iostream>
 6 #include<string>
 7 #include<vector>
 8 #include<stack>
 9 #include<bitset>
10 #include<cstdlib>
11 #include<cmath>
12 #include<set>
13 #include<list>
14 #include<deque>
15 #include<map>
16 #include<queue>
17 #define ll long long
18 #define MOD 1000000007
19 #define INF 0x3f3f3f3f
20 #define mem(a,x) memset(a,x,sizeof(a))
21 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22 using namespace std;
23 const int maxn=1000005;
24 inline int rd() {
25     int res = 0,flag = 0;
26     char ch;
27     if ((ch = getchar()) == '-')flag = 1;
28     else if(ch >= '0' && ch <= '9')res = ch - '0';
29     while ((ch = getchar()) >= '0' && ch <= '9')res = (res<<1) + (res<<3) + (ch - '0');
30     return flag ? -res : res;
31 }
32 /*
33 int head[maxn];
34 int num=0;
35 struct edg{
36     int next,to,w;
37 }edge[maxn];
38 void add_edge(int u,int v,int w)
39 {
40     num++;
41     edge[num].next=head[u];edge[num].to=v;edge[num].w=w;head[u]=num;
42     edge[++num].next=head[v];edge[num].to=u;edge[num].w=w;head[v]=num;
43 } */
44 //-----------
45 string s;
46 int a[30];
47 int main()
48 {
49     int T,n;
50     cin>>T;
51     while(T--){
52         mem(a,0);
53         cin>>n;
54         for(int i=1;i<=n;i++){
55             cin>>s;
56             for(int j=0;j<s.size();j++){
57                 a[s[j]-'a']++;
58             }
59         }
60         int k=1;
61         for(int i=0;i<26;i++){
62             if(a[i]%n!=0){
63                 k=0;
64                 break;
65             }
66         }
67         if(k){
68             cout<<"YES"<<endl;
69         }else{
70             cout<<"NO"<<endl;
71         }
72     }
73 }
View Code

 

##B. Power Sequence

思路:考虑当${}^{c^{i}}$的底数c>=2时,如果n>=50的情况下要变成的最大的数将达到$2^{50}$,那么由于$1\leqslant a_{i}\leqslant 10^{9}$,所以此时的答案一定是当底数c为1时,即$a_{i}$于1的差值。当n<50时,我们枚举从1到100000所有可行的底数,然后去最小值即可。

代码:

 1 //#include<bits/stdc++.h>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<iostream>
 6 #include<string>
 7 #include<vector>
 8 #include<stack>
 9 #include<bitset>
10 #include<cstdlib>
11 #include<cmath>
12 #include<set>
13 #include<list>
14 #include<deque>
15 #include<map>
16 #include<queue>
17 #define ll long long
18 #define MOD 1000000007
19 #define INF 0x3f3f3f3f
20 #define mem(a,x) memset(a,x,sizeof(a))
21 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22 using namespace std;
23 const int maxn=1000005;
24 inline int rd() {
25     int res = 0,flag = 0;
26     char ch;
27     if ((ch = getchar()) == '-')flag = 1;
28     else if(ch >= '0' && ch <= '9')res = ch - '0';
29     while ((ch = getchar()) >= '0' && ch <= '9')res = (res<<1) + (res<<3) + (ch - '0');
30     return flag ? -res : res;
31 }
32 /*
33 int head[maxn];
34 int num=0;
35 struct edg{
36     int next,to,w;
37 }edge[maxn];
38 void add_edge(int u,int v,int w)
39 {
40     num++;
41     edge[num].next=head[u];edge[num].to=v;edge[num].w=w;head[u]=num;
42     edge[++num].next=head[v];edge[num].to=u;edge[num].w=w;head[v]=num;
43 } */
44 //-----------
45 string s;
46 int a[100005];
47 int main()
48 {
49     int n;
50     cin>>n;
51     ll num=0;
52     for(int i=0;i<n;i++){
53         scanf("%d",&a[i]);
54         num+=abs(a[i]-1);
55     }
56     sort(a,a+n);
57     if(n>=50){
58         printf("%lld",num);
59     }else{
60         ll minn;
61         for(int i=2;i<=100000;i++){
62             ll p=1;
63             minn=abs(a[0]-p);
64             int kk=1;
65             for(int j=1;j<n;j++){
66                 p=p*i;
67                 minn+=abs(a[j]-p);
68                 if(p>10000000000000){
69                     kk=0;
70                     break;
71                 }
72             }
73 //            cout<<minn<<endl;
74             if(kk){
75                 num=min(num,minn);
76             }
77         }
78         cout<<num;
79     }
80         return 0;
81 }
View Code

 

 ##C. Multiples of Length

思路:也就是把题目描述的操作证明一下。

         step1: 选择$\left[ 1,n-1\right]$这个区间,然后把这个区间上的${}_{a_{1}\sim a_{n-1}}$加上$(n-1)\times a_{i}$ 那么此时$\left[ 1,n-1\right]$上   的${}_{a_{i}}$都变成了${}_{n\times a_{i}}$。

         step2: 把第n个数变成0。

         step3: 选择$\left[ 1,n\right]$这个区间,这个区间上都是n的倍数,此时都加上${}_{-a_{i}}$即可。

         特别注意:当n=1时的情况。

代码:

 1 //#include<bits/stdc++.h>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<iostream>
 6 #include<string>
 7 #include<vector>
 8 #include<stack>
 9 #include<bitset>
10 #include<cstdlib>
11 #include<cmath>
12 #include<set>
13 #include<list>
14 #include<deque>
15 #include<map>
16 #include<queue>
17 #define ll long long
18 #define MOD 1000000007
19 #define INF 0x3f3f3f3f
20 #define mem(a,x) memset(a,x,sizeof(a))
21 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22 using namespace std;
23 const int maxn=1000005;
24 inline int rd() {
25     int res = 0,flag = 0;
26     char ch;
27     if ((ch = getchar()) == '-')flag = 1;
28     else if(ch >= '0' && ch <= '9')res = ch - '0';
29     while ((ch = getchar()) >= '0' && ch <= '9')res = (res<<1) + (res<<3) + (ch - '0');
30     return flag ? -res : res;
31 }
32 /*
33 int head[maxn];
34 int num=0;
35 struct edg{
36     int next,to,w;
37 }edge[maxn];
38 void add_edge(int u,int v,int w)
39 {
40     num++;
41     edge[num].next=head[u];edge[num].to=v;edge[num].w=w;head[u]=num;
42     edge[++num].next=head[v];edge[num].to=u;edge[num].w=w;head[v]=num;
43 } */
44 //-----------
45 string s;
46 ll a[100005];
47 int main()
48 {
49     ll n;
50     cin>>n;
51     if(n==1){
52         scanf("%lld",&a[1]);
53         printf("1 1\n0\n1 1\n0\n1 1\n%lld",-a[1]);
54     }else{
55         for(int i=1;i<=n;i++){
56             scanf("%lld",&a[i]);
57         }
58         printf("1 %lld\n",n-1);
59         for(int i=1;i<n;i++){
60             printf("%lld%c",a[i]*(n-1)," \n"[i==n-1]);
61             a[i]=a[i]+a[i]*(n-1);
62         }
63         printf("%lld %lld\n",n,n);
64         printf("%lld\n",-a[n]);
65         a[n]=0;
66         printf("1 %lld\n",n);
67         for(int i=1;i<n;i++){
68             printf("%lld ",-a[i]);
69         }
70         printf("0");
71     }
72     return 0;
73 }
View Code

 

##D. Stoned Game

题意:给你n堆石子,两个人轮流选一堆取石子,一个人不可以取上一个人取的那堆石子和已经没有了的那堆石子,最后不能取石子的人失败。

思路:首先,如果最多的一堆石子的数量大于其它所有石子之和,那么先手必胜,即先手一直取最多的那堆石子。然后猜结论,石子总和为偶数,后手赢,否则先手赢。

代码:

 1 //#include<bits/stdc++.h>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<iostream>
 6 #include<string>
 7 #include<vector>
 8 #include<stack>
 9 #include<bitset>
10 #include<cstdlib>
11 #include<cmath>
12 #include<set>
13 #include<list>
14 #include<deque>
15 #include<map>
16 #include<queue>
17 #define ll long long
18 #define MOD 1000000007
19 #define INF 0x3f3f3f3f
20 #define mem(a,x) memset(a,x,sizeof(a))
21 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22 using namespace std;
23 const int maxn=1000005;
24 inline int rd() {
25     int res = 0,flag = 0;
26     char ch;
27     if ((ch = getchar()) == '-')flag = 1;
28     else if(ch >= '0' && ch <= '9')res = ch - '0';
29     while ((ch = getchar()) >= '0' && ch <= '9')res = (res<<1) + (res<<3) + (ch - '0');
30     return flag ? -res : res;
31 }
32 /*
33 int head[maxn];
34 int num=0;
35 struct edg{
36     int next,to,w;
37 }edge[maxn];
38 void add_edge(int u,int v,int w)
39 {
40     num++;
41     edge[num].next=head[u];edge[num].to=v;edge[num].w=w;head[u]=num;
42     edge[++num].next=head[v];edge[num].to=u;edge[num].w=w;head[v]=num;
43 } */
44 //-----------
45 int n;
46 int a[105];
47 int main()
48 {
49     int T;
50     int sum;
51     cin>>T;
52     while(T--){
53         cin>>n;
54         sum=0;
55         for(int i=1;i<=n;i++){
56             scanf("%d",&a[i]);
57             sum+=a[i];
58         }
59         sort(a+1,a+n+1);
60         if(a[n]>sum-a[n]){
61             printf("T\n");
62         }else{
63             if(sum%2==0){
64                 printf("HL\n");
65             }else{
66                 printf("T\n");
67             }
68         }
69     }
70     return 0;
71 }
View Code

 

##E. Monster Invaders :0

posted @ 2020-08-31 20:47  hachuochuo  阅读(242)  评论(0编辑  收藏  举报