• 题意:有一个字符串,要求使用其中字符构造一个环(不必全部都用),定义一个环是k美的,如果它转\(k\)次仍是原样,现在给你\(k\),要求最长的k美环的长度.

  • 题解:我们首先看\(k\),如果一个环转\(k\)的因子次是美的,那么\(k\)次也一定是美的,然后再看环,假如一个环最少转\(d\)次是美的,那么这个环的长度\(n\)一定能被\(d\)整除.也就是这个环有\(d\)种不同的数,每种数有\(n/d\)个.其实也就可以把看作是一个循环节构成的,画一画也就知道了.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL; int t;
    int n,k;
    string s;
    map<char,int> mp;
    vector<int> v; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>t;
    while(t--){
    mp.clear();
    v.clear();
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<n;++i){
    mp[s[i]]++;
    }
    for(int i=1;i<=k;++i){
    if(k%i==0){
    v.pb(i);
    }
    }
    int ans=0;
    for(int i=1;i<=n;++i){
    for(auto w:v){
    if(w%i==0){
    ans=max(ans,i); //worst situation
    }
    if(i%w==0){
    int d=i/w;
    int cnt=0;
    for(char j='a';j<='z';++j){
    cnt+=mp[j]/d;
    }
    if(cnt>=w){
    ans=max(ans,i);
    }
    }
    }
    }
    cout<<ans<<endl; } return 0;
    }

Codeforces Round #650 (Div. 3) E. Necklace Assembly (暴力)的更多相关文章

  1. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  2. Codeforces Round #650 (Div. 3) C. Social Distance

    题目链接:https://codeforces.com/contest/1367/problem/C 题意 给出一个长为 $n$ 的 $01$字符串,两个相邻 $1$ 间距应大于 $k$,初始序列合法 ...

  3. Codeforces Round #650 (Div. 3) B. Even Array

    题目链接:https://codeforces.com/contest/1367/problem/B 题意 有一大小为 $n$ 的数组 $a$,问能否经过交换使所有元素与下标奇偶性相同(0 - ind ...

  4. Codeforces Round #650 (Div. 3) A. Short Substrings

    题目链接:https://codeforces.com/contest/1367/problem/A 题意 给出一个字符串 $t$,找出原字符串 $s$,$t$ 由 $s$ 从左至右的所有长为 $2$ ...

  5. Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)

    题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\( ...

  6. Codeforces Round #650 (Div. 3) D. Task On The Board (构造,贪心)

    题意:有一个字符串和一组数,可以对字符串删去任意字符后为数组的长度,且可以随意排序,要求修改后的字符串的每个位置上的字符满足:其余大于它的字符的位置减去当前位置绝对值之和等于对应序列位置上的数. 题解 ...

  7. Codeforces Round #650 (Div. 3) C. Social Distance (前缀和)

    题意:有一排座位,要求每人之间隔\(k\)个座位坐,\(1\)代表已做,\(0\)代表空座,问最多能坐几人. 题解:我们分别从前和从后跑个前缀和,将已经有人坐的周围的位置标记,然后遍历求每一段连续的\ ...

  8. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  9. Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力

    C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...

随机推荐

  1. MyBatis初级实战之三:springboot集成druid

    OpenWrite版: 欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kuber ...

  2. Flink源码剖析:Jar包任务提交流程

    Flink基于用户程序生成JobGraph,提交到集群进行分布式部署运行.本篇从源码角度讲解一下Flink Jar包是如何被提交到集群的.(本文源码基于Flink 1.11.3) 1 Flink ru ...

  3. 入门训练 - 蓝桥杯(Python实现)

    A+B问题: 题目: 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 输入A.B,输出A+B. 输入格式 输入的第一行包括两个整数,由空格分隔,分别表示A.B. 输出格式 输出一行, ...

  4. bean与map之间的转化

    import java.util.HashMap; import java.util.Map; import org.apache.commons.beanutils.BeanUtils; impor ...

  5. pandas模块的使用详解

    为什么学习pandas numpy已经可以帮助我们进行数据的处理了,那么学习pandas的目的是什么呢? numpy能够帮助我们处理的是数值型的数据,当然在数据分析中除了数值型的数据还有好多其他类型的 ...

  6. Netty服务端Server代码说明

    本文是简单的Netty启动服务端代码理解笔记 public class MyServer { public static void main(String[] args) throws Excepti ...

  7. 设置一个两边固定中间自适应的css

    1.两边浮动,中间自动宽度 给左右两个盒子设置左右浮动,中间的盒子不设置宽度,左右两边边距为左右盒子的宽度,中间盒子的位置必须写在右盒子下面,不然会把右盒子挤下去 如:   <div class ...

  8. Bitter.Core系列十一:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore 之 字段变更收集器

    有时候我们业务层需要记录 数据库表更改之前的值和更改之后的值的记录集合--此过程在 Bitter.Core 中有强有力的支持.Bitter.Core 字段收集器提供了方便简单易用的 收集对象在修改之前 ...

  9. Scheduling Multithreaded Computations by Work Stealing

    steal.pdf http://supertech.csail.mit.edu/papers/steal.pdf This paper studies the problem of eciently ...

  10. Optimistic concurrency control 死锁 悲观锁 乐观锁 自旋锁

    Optimistic concurrency control https://en.wikipedia.org/wiki/Optimistic_concurrency_control Optimist ...