zoukankan      html  css  js  c++  java
  • CodeFroce 879D Teams Formation 暴力瞎搞

    D. Teams Formation
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.

    Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times).

    After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city.

    Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected.

    Input

    The first line contains three integers n, k and m (1 ≤ n ≤ 105, 2 ≤ k ≤ 109, 1 ≤ m ≤ 109).

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number of city, person from which must take seat i in the bus.

    Output

    Output the number of remaining participants in the line.

    Examples
    input
    4 2 5
    1 2 3 1
    output
    12
    input
    1 9 10
    1
    output
    1
    input
    3 2 10
    1 2 1
    output
    0
    Note

    In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.

    题意:有一辆车每次运送n个人,这n个人分别来自于不同的城市。一共运送m趟,现在题目要求你将每次排队的n个人进行分队,每一队的人数要求是k个,也就是说如果相邻的人来自于同一个城市,同时满足加在一起的人数是大于或等于K的,那么就可以减少k个人,问你最后能能够剩下多少人?
    思路:因为是n个人不断地重复,可能符合要求的位置可能有两个n的交接处,同时还有就是不断删除的同时会有前后的数字相接,然后达成条件,然后被删除。其实这也就是对于一个n的性质的判断,如果从这n个数的前后开始找一个数字,如果可以找到有大于或等于k个数字,那么在重复的时候就可以被删除。同样的,对于一个n内部而言这样做也是可以的。
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #include<stack>
    #include<bitset>
    #include<cstdlib>
    #include<cmath>
    #include<set>
    #include<list>
    #include<deque>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int maxn=100000+10;
    const int mod=1e9+7;
    int aa[maxn];
    int bb[maxn],cc[maxn];
    int  main()
    {
        int n,k,m;
        while(scanf("%d%d%d",&n,&k,&m)==3)
        {
            int i,j;
            for(i=0;i<n;i++)
            {
                scanf("%d",&aa[i]);
            }
            int num1=0,num2=0;
            ll num3;
            for(i=0;i<n;i++)
            {
                bb[i]=1;
            }
            cc[0]=aa[0];
            ll ans=0;
            int p,q=0;
            for(i=1;i<n;i++)
            {
                if(aa[i]==cc[num2])
                {
                    bb[num1]++;
                    cc[num2]=aa[i];
                }
                if(aa[i]!=cc[num2])
                {
                    num1++;
                    num2++;
                    cc[num2]=aa[i];
                }
                if(bb[num1]>=k)
                {
                    p=bb[num1]/k;
                    q=bb[num1]%k;
                    bb[num1]=q;
                    ans=ans+1ll*p*k*m;
                    if(q==0)
                    {
                       bb[num1]=1;
                       num1--;
                       cc[num2]=0;
                       num2--;
                    }
                }
            }
            num1++;
            i=0;
            for(i=0;i<(num1/2);i++)
            {
                if(cc[i]==cc[num1-i-1]&&(bb[i]+bb[num1-i-1])%k==0)
                {
                    ans=ans+1ll*(m-1)*k;
                }
                else
                    break;
            }
            if(i!=(num1/2)&&cc[i]==cc[num1-i-1]&&(bb[i]+bb[num1-i-1])>k)
            {
                ans=ans+1ll*(m-1)*k;
            }
            if(i==(num1/2)&&num1%2)
            {
                num3=1ll*m*bb[i];
                if(num3%k==0)
                {
                    ans=1ll*n*m;
                }
                else
                {
                    int num4=num3%k;
                    ans=ans+num3-num4;
                }
            }
            printf("%I64d
    ",1ll*n*m-ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    SQL Server数据库损坏、检测以及简单的修复办法
    迭代法
    求两个数组的交集
    jQuery的动画处理总结
    ASP.NET MVC企业开发的基本环境
    ASP.NET WebForm 的路由
    CMStepCounter Class Refernce
    C++输入一个字符串,把其中的字符按照逆序输出的两种方法
    5.2 列出表的列
    Mac Outlook数据文件的位置
  • 原文地址:https://www.cnblogs.com/yewa/p/7757870.html
Copyright © 2011-2022 走看看