Necklace - CF613C

Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).

Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace.

Input

The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after n positive integers ai   — the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000.

Output

In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace.

Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point.

Sample test(s)
Input
3
4 2 1
Output
1
abacaba
Input
1
4
Output
4
aaaa
Input
2
1 1
Output
0
ab
Note

In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.

In the second sample there is only one way to compose a necklace.

简单题意

给你很多个珠子(第i种颜色有Ai种,颜色最多有26种,用小写字母表示),让你串成一条项链,然后项链有一个优美值

优美值=优美的cut的个数

一个优美的cut表示从这个地方剪断项链,使得其变成一个回文串

然后你要求出最大的优美值,然后给出一个方案

胡说题解

分情况讨论

1.如果个数中没有奇数,那么答案就是所有数字的gcd,然后构造答案就是输出gcd/2个回文串

2.如果个数中只有一个奇数,那么答案也是所有数字的gcd,然后构造答案就是输出gcd个回文串,个数为奇数的颜色放在回文串的中间

3.如果个数中有两个或以上的奇数,那么答案就是0,因为两个奇数就已经构造不出有优美cut的环来了

 1 #include<cstdio>
 2 using namespace std;
 3 
 4 int n,c,x,a[30];
 5 
 6 int gcd(int a,int b){
 7     if(b==0)return a;
 8     return gcd(b,a % b);
 9 }
10 
11 int main(){
12     scanf("%d",&n);
13     int i,j,k;
14     for(i=1;i<=n;i++)scanf("%d",&a[i]);
15     for(i=1;i<=n;i++)
16     if((a[i]&1)==1)c++,x=i;
17     if(c>1){
18         printf("0\n");
19         for(i=1;i<=n;i++){
20             while(a[i]>0){
21                 --a[i];
22                 printf("%c",'a'-1+i);
23             }
24         }
25     }
26     else
27     if(c==1){
28         c=a[1];
29         for(i=2;i<=n;i++)c=gcd(c,a[i]);
30         printf("%d\n",c);
31         for(i=1;i<=c;i++){
32             for(j=1;j<=n;j++){
33                 if(j!=x)
34                 for(k=1;k<=a[j]/c/2;k++)printf("%c",'a'-1+j);
35             }
36             for(j=1;j<=a[x]/c;j++)printf("%c",'a'-1+x);
37             for(j=n;j>0;j--){
38                 if(j!=x)
39                 for(k=1;k<=a[j]/c/2;k++)printf("%c",'a'-1+j);
40             }
41         }
42     }
43     else{
44         c=a[1];
45         for(i=2;i<=n;i++)c=gcd(c,a[i]);
46         printf("%d\n",c);
47         for(i=1;i<=c/2;i++){
48             for(j=1;j<=n;j++){
49                 for(k=1;k<=a[j]/c;k++)printf("%c",'a'-1+j);
50             }
51             for(j=n;j>0;j--){
52                 for(k=1;k<=a[j]/c;k++)printf("%c",'a'-1+j);
53             }
54         }
55     }
56     return 0;
57 }
AC代码

 

转载于:https://www.cnblogs.com/Randolph87/p/5199423.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值