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 k different 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.

题目链接:http://codeforces.com/contest/844/problem/A

题意:大概是要在长度为len的字符串中至少要存在x个不同的字符需要变换多少次

emmmm,似乎有坑的题,窝石乐志在Test 6和Test 12上连翻跟头,代码应该很清楚,看代码吧!

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int a[];
int main()
{
string s;
cin>>s;
int len=s.size();
int x;
cin>>x;
if(x>len)
{
printf("impossible");
return ;
}
for(int i=;i<len;i++)
{
a[s[i]-'a'+]++;
}
int sum=;
for(int i=;i<=;i++)
{
if(a[i]!=)
{
a[i]=;
sum++;
}
}
if(x<=sum)
cout<<;
else
cout<<x-sum;
return ;
}

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.

题目链接:http://codeforces.com/contest/844/problem/B

题目大意

求选出在同一行或同一列颜色相同的格子,共有多少种选法。

题解

杨辉三角预处理组合数,设b[i]为第i行1的个数,则: i=1n∑j=1b[i]Cjb[i]

列同理,注意去掉块数为1的。

下面给出AC代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+;
int mymap[][];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",&mymap[i][j]);
}
}
ll ans=n*m;
for(int i=;i<=n;i++)
{
int num1=;
int num2=;
for(int j=;j<=m;j++)
{
if(mymap[i][j]==)
num1++;
else
num2++;
}
ans+=((ll)pow(,num1)--num1);
ans+=((ll)pow(,num2)--num2);
}
for(int i=;i<=m;i++)
{
int num1=;
int num2=;
for(int j=;j<=n;j++)
{
if(mymap[j][i]==)
num1++;
else
num2++;
}
ans+=((ll)pow(,num1)--num1);
ans+=((ll)pow(,num2)--num2);
}
printf("%lld\n",ans);
return ;
}

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.

题目链接:http://codeforces.com/contest/844/problem/C

分析:排序之后,记录每个数字原来在哪里就好.可以形成环的,环的个数就是子列个数。

下面给出AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int n,a[N],sa[N],r[N];
bool vis[N];
bool cmp(int x,int y)
{
return a[x]<a[y];
}
vector<int> v[N];
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%d",&a[i]),sa[i]=i;
sort(sa+,sa+n+,cmp);
int ans=;
for (int i=;i<=n;i++)
if (!vis[i])
{
ans++;
v[ans].push_back(i);
vis[i]=;
for(int x=sa[i];x!=i;x=sa[x])
vis[x]=,v[ans].push_back(x);
}
printf("%d\n",ans);
for(int i=;i<=ans;i++)
{
printf("%d ",(int)v[i].size());
for(int j=;j<v[i].size();j++)
printf("%d ",v[i][j]);
puts("");
}
return ;
}

AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)的更多相关文章

  1. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  2. 【AIM Tech Round 4 (Div. 2) D Prob】

    ·题目:D. Interactive LowerBound ·英文题,述大意:       有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...

  3. AIM Tech Round 4 Div. 1

    A:显然最优方案是对所形成的置换的每个循环排个序. #include<iostream> #include<cstdio> #include<cmath> #inc ...

  4. AIM Tech Round 4 (Div. 2)

    A题 分析:暴力 #include "iostream" #include "cstdio" #include "cstring" #inc ...

  5. codeforces AIM Tech Round 4 div 2

    A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...

  6. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  7. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  8. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...

  9. AIM Tech Round 3 (Div. 2) A

    Description Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Ko ...

随机推荐

  1. 监听键盘弹起View上调

    可以用三方库IQKeyboardManager 用这个第三方 http://www.jianshu.com/p/f8157895 #pragma mark - keyboard events - // ...

  2. htpasswd 命令详解

    htpasswd参数 -c 创建passwdfile.如果passwdfile 已经存在,那么它会重新写入并删去原有内容. -n 不更新passwordfile,直接显示密码 -m 使用MD5加密(默 ...

  3. 用VS2015写一个简单的ASP.net网站

    第一步:打开VS2015,然后新建一个空的解决方案,其中解决方案的名称WebSiteTest可类似认为是本次网站的名称,系统会以该名称(WebSiteTest)生成一个文件夹,在WebSites文件夹 ...

  4. 命令行执行php脚本 中$argv和$argc

    在实际工作中有可能会碰到需要在nginx命令行执行php脚本的时候,当然你可以去配置一个conf用外网访问. 在nginx命令行中 使用 php index.php 就可以执行这个index.php脚 ...

  5. Hybris 项目工程配置

    1.控制台页面进入platform目录 cd F:\hybris640\hybris\bin\platform 并运行 setantenv.bat 生成对应的ant. 2.运行 ant moduleg ...

  6. bzoj 4012: [HNOI2015]开店

    Description 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到 人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱.这样的 想法当然非常好啦,但是她们也发现 ...

  7. 【分治】peak find

    分治算法 算法设计中一种常用的优化方法就是分治的思想,它的解决思路就是将原始的问题划分为性质一样,但是规模减小的子问题,然后通过子问题的解和合并子问题的解得到最终的解,就是分治的思想: 比较常见的分治 ...

  8. [编织消息框架][JAVA核心技术]动态代理应用7-IRpcSend实现

    根据设计生成两个接口,IRpcSend send方法返回数据要求包装成QResult对象 public interface IRpcSend { public <T> QResult< ...

  9. redis实现分布式可重入锁

    利用redis可以实现分布式锁,demo如下: /** * 保存每个线程独有的token */ private static ThreadLocal<String> tokenMap = ...

  10. Ubuntu安装微信

    1.系统是Ubuntu 16.04 64位系统,在网上先去下载electronic-wechat-Linux         https://github.com/geeeeeeeeek/electr ...