AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
A. Diversity
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.
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).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
yandex
6
0
yahoo
5
1
7
impossible
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
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:
- All cells in a set have the same color.
 - Every two cells in a set share row or column.
 
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 single integer — the number of non-empty sets from the problem description.
1 1
0
1
2 3
1 0 1
0 1 0
8
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
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.
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.
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.
6
3 2 1 6 5 4
4
2 1 3
1 2
2 4 6
1 5
6
83 -75 -49 11 37 62
1
6 1 2 3 4 5 6
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+排序)的更多相关文章
- 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 ...
 - 【AIM Tech Round 4 (Div. 2)  D Prob】
		
·题目:D. Interactive LowerBound ·英文题,述大意: 有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...
 - AIM Tech Round 4 Div. 1
		
A:显然最优方案是对所形成的置换的每个循环排个序. #include<iostream> #include<cstdio> #include<cmath> #inc ...
 - AIM Tech Round 4 (Div. 2)
		
A题 分析:暴力 #include "iostream" #include "cstdio" #include "cstring" #inc ...
 - codeforces AIM Tech Round 4 div 2
		
A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...
 - AIM Tech Round 3 (Div. 2)
		
#include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...
 - AIM Tech Round 3 (Div. 2) A B C D
		
虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...
 - AIM Tech Round 3 (Div. 2) B
		
Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...
 - 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 ...
 
随机推荐
- JavaScript 中 apply 、call 的详解
			
apply 和 call 的区别 ECMAScript 规范给所有函数都定义了 call 与 apply 两个方法,它们的应用非常广泛,它们的作用也是一模一样,只是传参的形式有区别而已. 原文作者:林 ...
 - APP闪退问题
			
1.iOS-中app启动闪退的原因 2.iOS开发-闪退问题-解决之前上架的 App 在 iOS 9 会闪退问题 3.iOS-应用闪退总结 4.iOS开发-捕获程序崩溃日志 5.iOS开发-应用崩溃日 ...
 - Python3.5:爬取网站上电影数据
			
首先我们导入几个pyhton3的库: from urllib import requestimport urllibfrom html.parser import HTMLParser 在Python ...
 - 搭建lnmp教程
			
LNMP指的是一个基于CentOS/Debian 上安装Nginx.PHP.MySQL.php.可以在独立主机上轻松的安装LNMP生产环境. 1 安装nginx 如果是一台新的服务器可直接安装(若以前 ...
 - AO之Addins开发[杂谈1] Toolbar中添加一条分割线
			
在XML代码中,给Item添加separator属性,需要从哪里打分割线,就将其设置为true即可.如下图所示: 如紫色框住的灰色竖线所示. 默认separator属性是false的,这个小东西极其隐 ...
 - Linux Centos  使用 yum 安装java
			
centos 使用 yum 安装java 首先,在你的服务器上运行一下更新. yum update 然后,在您的系统上搜索,任何版本的已安装的JDK组件. rpm -qa | grep -E '^op ...
 - 一、源代码-面向CLR的编译器-托管模块-(元数据&IL代码)
			
本文脉络图如下: 1.CLR(Common Language Runtime)公共语言运行时简介 (1).公共语言运行时是一种可由多种编程语言一起使用的"运行时". (2).CLR ...
 - Qt个人研究进展
			
1:纯socket通信实现多线程邮件发送,支持多个收件人和附件,通用任何平台,包括ARM.2:纯串口通信AT命令实现多线程短信收发,支持多个收件人和长短信,通用任何平台,包括ARM.3:纯串口通信PO ...
 - think queue 消息队列初体验
			
使用的是tp5 自带的消息队列 thinkphp top里的 消息队列框架 think-queue 这是thinkphp官方团队开发的一个专门支持队列服务的扩展包 消息队列应用场景: 消息队列适用于 ...
 - CRM项目总结
			
CRM项目总结 一:开发背景 在公司日益扩大的过程中,不可避免的会伴随着更多问题出现. 对外 : 如何更好的管理客户与公司的关系?如何更及时的了解客户日益发展的需求变 ...