D. Carousel

194 篇文章 1 订阅
32 篇文章 0 订阅

链接:https://codeforces.ml/contest/1328/problem/D

The round carousel consists of nn figures of animals. Figures are numbered from 11 to nn in order of the carousel moving. Thus, after the nn-th figure the figure with the number 11 follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type of animal of the ii-th figure equals titi.

14b03eb81d32a3e2f92254a8c4ea43e5871f2a6d.pnguploading.4e448015.gif正在上传…重新上传取消The example of the carousel for n=9n=9 and t=[5,5,1,15,1,5,5,1,1]t=[5,5,1,15,1,5,5,1,1].

You want to color each figure in one of the colors. You think that it's boring if the carousel contains two different figures (with the distinct types of animals) going one right after another and colored in the same color.

Your task is to color the figures in such a way that the number of distinct colors used is the minimum possible and there are no figures of the different types going one right after another and colored in the same color. If you use exactly kk distinct colors, then the colors of figures should be denoted with integers from 11 to kk.

Input

The input contains one or more test cases.

The first line contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases in the test. Then qq test cases follow. One test case is given on two lines.

The first line of the test case contains one integer nn (3≤n≤2⋅1053≤n≤2⋅105) — the number of figures in the carousel. Figures are numbered from 11 to nn in order of carousel moving. Assume that after the nn-th figure the figure 11 goes.

The second line of the test case contains nn integers t1,t2,…,tnt1,t2,…,tn (1≤ti≤2⋅1051≤ti≤2⋅105), where titi is the type of the animal of the ii-th figure.

The sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

Print qq answers, for each test case print two lines.

In the first line print one integer kk — the minimum possible number of distinct colors of figures.

In the second line print nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤k1≤ci≤k), where cici is the color of the ii-th figure. If there are several answers, you can print any.

Example

input

Copy

4
5
1 2 1 2 2
6
1 2 2 1 2 2
5
1 2 1 2 3
3
10 10 10

output

Copy

2
1 2 1 2 2
2
2 1 2 1 2 1
3
2 3 2 3 1
1
1 1 1 

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,h,k,l,t,u,v,max1=0;
map<long long,long long>m[200001];
long long a[200001],b[200001],d[200001],c[200001];
int main()
{
cin>>t;
    while(t--)
    {
        cin>>n;
        int flag=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        a[0]=a[n];
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]==a[1])
            {
                cnt++;
            }
        }
        if(cnt==n)
        {
            cout<<1<<endl;
            for(int i=1; i<=n; i++)
            {
                cout<<1<<' ';
            }
            cout<<endl;
            continue;
        }
        cnt=0;
        flag=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]==a[(i+1)%n])
            {
                flag=1;
            }
            else
            {
                cnt++;
            }
        }
        if(cnt%2==1)
        {
            if(flag==1)
            {
                cout<<2<<endl;
                cnt=0;
                flag=0;
                for(int i=1; i<=n; i++)
                {
                    if(cnt==0)
                    {
                        cout<<1<<' ';
                    }
                    else
                    {
                        cout<<2<<' ';
                    }
                    if(a[i]==a[(i+1)%n])
                    {
                        if(flag==0)
                        {
                            flag++;
                            cnt++;
                            cnt%=2;
                        }
                    }
                    else
                    {
                        cnt++;
                        cnt%=2;
                    }
                }
                cout<<endl;
            }
            else
            {
                cout<<3<<endl;
                if(n%3==1)
                {
                    for(int i=1; i<=n-1; i++)
                    {
                        cout<<i%3+1<<' ';
                    }
                    cout<<3;
                }
                else
                {
                    for(int i=1; i<=n; i++)
                    {
                        cout<<i%3+1<<' ';
                    }
                }
                cout<<endl;
            }
        }
        else
        {
            cout<<2<<endl;
            cnt=0;
            for(int i=1; i<=n; i++)
            {
                if(cnt==0)
                {
                    cout<<1<<' ';
                }
                else
                {
                    cout<<2<<' ';
                }
                if(a[i]!=a[(i+1)%n])
                {
                    cnt++;
                    cnt%=2;
                }
            }
            cout<<endl;
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要取消 Bootstrap Carousel 的自动轮播并改为手动切换,需要使用 JavaScript 进行一些编程。 以下是实现步骤: 1. 在 Carousel 的 HTML 标签中添加 data-interval="false" 属性,以禁用自动轮播。 2. 针对每个 Carousel 实例,使用 JavaScript 获取该 Carousel 的 ID,然后使用 jQuery 在 Carousel 上绑定 slide.bs.carousel 事件,该事件会在 Carousel 的幻灯片切换时触发。 3. 在 slide.bs.carousel 事件的回调函数中,使用 jQuery 获取当前 Carousel 的 active 幻灯片索引和下一个幻灯片索引,然后根据这些索引获取相应的控制按钮(prev 和 next),并将它们的 disabled 属性设置为 false,这样用户就可以手动切换幻灯片了。 下面是一个示例代码,可以帮助你更好地理解如何实现手动切换: HTML: ```html <div id="carouselExampleControls" class="carousel slide" data-ride="carousel" data-interval="false"> <div class="carousel-inner"> <div class="carousel-item active"> <img src="..." class="d-block w-100" alt="..."> </div> <<div class="carousel-item"> <img src="..." class="d-block w-100" alt="..."> </div> <div class="carousel-item"> <img src="..." class="d-block w-100" alt="..."> </div> </div> <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> ``` JavaScript: ```javascript $(document).ready(function() { $('#carouselExampleControls').on('slide.bs.carousel', function (e) { var active = $(e.target).find('.carousel-item.active'); var next = e.relatedTarget; var prevControl = $(this).find('.carousel-control-prev'); var nextControl = $(this).find('.carousel-control-next'); if(next.classList.contains('carousel-item-left') && active.index() === 0) { prevControl.prop('disabled', true); nextControl.prop('disabled', false); } else if(next.classList.contains('carousel-item-right') && active.index() === $(this).find('.carousel-item').length - 1) { prevControl.prop('disabled', false); nextControl.prop('disabled', true); } else { prevControl.prop('disabled', false); nextControl.prop('disabled', false); } }); }); ``` 在这个示例代码中,我们使用了 jQuery 来监听 slide.bs.carousel 事件,并在回调函数中根据当前幻灯片索引和下一个幻灯片索引来启用或禁用控制按钮。当幻灯片处于最左侧或最右侧时,我们禁用相应的控制按钮,以避免切换到不存在的幻灯片。否则,我们启用所有控制按钮,以允许用户手动切换幻灯片。 希望这个示例代码能够帮助你实现 Bootstrap Carousel 的手动切换。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值