寒假222_Topcoder SRM648

序号1:

       A,随便模拟好了,最后30秒发现一个都比的错误,无奈输错格式。

2:

     B,问你出去两个点,以及所产生的边 问你:产生多的联通快 加答案加1.

        数据小,随便写暴力

3:

        copy思路。

我们先证明产生的最大答案是:A:x个 B:y个 ,C:z个;

那么most=x*y+y*z+z*x;

               x+y+z;

由数学公式可得:x=n/3,y=n/3;z=n-z-y;

然后构造是:预先构造:AAABBBCCC 答案

K=1                         AAABBCBCC

 K=2                        AAABCCBBC

类似产生左 移就好

#include<stdio.h>
#include<algorithm>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<string.h>
#include <vector>
#include<map>
using namespace std;
typedef long long ll;
class ABC {
public:
   string createString(int N,int K)
   {
       string ss="CBA";
       int n=N;
       string s;
       while (n)
       {
           s+=ss[n%3];
           n--;
       }
       sort(s.begin(),s.end());
       int t=0;
       int num=0;
       if (K==num) return s;
       while (t<N)
       {
           int ci=N-1;
           while (ci>t)
           {
               swap(s[ci-1],s[ci]);
               if (s[ci-1]>s[ci]) num++;
               if (num==K) return s;
               ci--;
           }
           t++;
       }
       return "";
   }
};
int main()
{
    ABC p;
    int n,k;
    cin>>n>>k;
    cout<<p.createString(n,k);
    return 0;
}

 4:DIV 1 A:是C题的简化版,

所以思路类似

原文地址:https://www.cnblogs.com/forgot93/p/4271310.html