zoukankan      html  css  js  c++  java
  • AIM Tech Round 4 (Div. 2)

    好晚好晚,还是不打了,这个时候我们看到了群友的神力,我这是赛后补题

    A. Diversity
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Calculate the minimum number of characters you need to change in the string s, so that it contains at least kdifferent letters, or print that it is impossible.

    String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

    Input

    First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s).

    Second line of input contains integer k (1 ≤ k ≤ 26).

    Output

    Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

    Examples
    input
    yandex
    6
    output
    0
    input
    yahoo
    5
    output
    1
    input
    google
    7
    output
    impossible
    Note

    In the first test case string contains 6 different letters, so we don't need to change anything.

    In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.

    In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

      字符串长度<k,自然就不能实现操作了。怎么改都小于k啊

    >k的就讨论下字母出现一次的有几个,k-a就是所求了,但是可能小于0,所以取两者最小值

    #include <bits/stdc++.h>
    using namespace std;
    char s[1005];
    int cnt[256];
    int main()
    {
        scanf("%s",s+1);
        int n =strlen(s+1);
        int k;
        scanf("%d",&k);
        int a=0;
        for(int i=1; i<=n; i++)
        {
            int idx = s[i]-'a';
            if(!cnt[idx])a++;
            cnt[idx]++;
        }
        if(n<k)puts("impossible");
        else printf("%d
    ",max(k-a,0));
        return 0;
    }
    B. Rectangles
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:

    1. All cells in a set have the same color.
    2. Every two cells in a set share row or column.
    Input

    The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly.

    The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.

    Output

    Output single integer  — the number of non-empty sets from the problem description.

    Examples
    input
    1 1
    0
    output
    1
    input
    2 3
    1 0 1
    0 1 0
    output
    8
    Note

    In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.

     简单的枚举,就是可能不好理解,但是其实就是2^k-1的和阿

    #include <cstdio>
    int n,m,a[50][50];
    int main()
    {
        scanf("%d%d",&n,&m);
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                scanf("%d",a[i]+j);
        long long res=0;
        for(int i=0; i<n; i++)
        {
            int u=0,v=0;
            for(int j=0; j<m; j++)
                a[i][j]?u++:v++;
            res+=(1LL<<u)+(1LL<<v)-2;
        }
        for(int i=0; i<m; i++)
        {
            int u=0,v=0;
            for(int j=0; j<n; j++)
                a[j][i]?u++:v++;
            res+=(1LL<<u)+(1LL<<v)-2;
        }
        printf("%lld",res-n*m);
        return 0;
    }
    C. Sorting by Subsequences
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.

    Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places.

    Every element of the sequence must appear in exactly one subsequence.

    Input

    The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence.

    The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.

    Output

    In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements.

    In the next k lines print the description of subsequences in the following format: the number of elements in subsequence ci (0 < ci ≤ n), then ci integers l1, l2, ..., lci (1 ≤ lj ≤ n) — indices of these elements in the original sequence.

    Indices could be printed in any order. Every index from 1 to n must appear in output exactly once.

    If there are several possible answers, print any of them.

    Examples
    input
    6
    3 2 1 6 5 4
    output
    4
    2 1 3
    1 2
    2 4 6
    1 5
    input
    6
    83 -75 -49 11 37 62
    output
    1
    6 1 2 3 4 5 6
    Note

    In the first sample output:

    After sorting the first subsequence we will get sequence 1 2 3 6 5 4.

    Sorting the second subsequence changes nothing.

    After sorting the third subsequence we will get sequence 1 2 3 4 5 6.

    Sorting the last subsequence changes nothing.

     这个算什么,蜜汁枚举??大暴力??二分应该也可以的

    #include<bits/stdc++.h>
    using namespace std;
    const int N=N;
    int n,a[N],b[N];
    bool v[N];
    vector<int>g[N];
    bool cmp(int x,int y)
    {
        return a[x]<a[y];
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(int i=0; i<n; i++)
            b[i]=i;
        sort(b,b+n,cmp);
        int nn=0;
        for(int i=0; i<n; i++)
            if(!v[i])
            {
                int p=i;
                v[i]=1;
                g[++nn].push_back(p);
                while(b[p]!=i)
                {
                    p=b[p];
                    v[p]=1;
                    g[nn].push_back(p);
                }
            }
        printf("%d
    ",nn);
        for(int i=1; i<=nn; i++)
        {
            printf("%d ",g[i].size());
            for(int j=0; j<(int)g[i].size(); j++)
            printf("%d ",g[i][j]+1);
            putchar(10);
        }
        return 0;
    }
  • 相关阅读:
    【转载】apache kafka系列之-监控指标
    自动恢复被挂掉的hbase region server
    beeline连接hive server遭遇MapRedTask (state=08S01,code=1)错误
    sqoop-1.4.6安装配置
    spark RDD的元素顺序(ordering)测试
    【转载】常用Maven插件介绍
    【转载】Spark SQL 1.3.0 DataFrame介绍、使用
    SparkSQL之数据源
    spark集成hive遭遇mysql check失败的问题
    hive启动报错: Found class jline.Terminal, but interface was expected
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7427649.html
Copyright © 2011-2022 走看看