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 ...
随机推荐
- php-基于面向对象的MySQL类
class sqlHelper{ private $conn; private $host = 'localhost'; private $user = 'root'; private $pwd = ...
- CentOS5 可用yum源
[base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever& ...
- LAMP第二部分apache配置
课程大纲:1. 下载discuz! mkdir /data/wwwcd /data/wwwwget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3 ...
- lesson - 13 Linux系统日常管理2
内容概要: 1. Linux抓包工具 tcpdump 系统自带抓包工具tcpdump -nn -i eth0 tcp and host 192.168.0.1 and port 80tcpdump - ...
- Java编程学习知识点分享 入门必看
Java编程学习知识点分享 入门必看 阿尔法颜色组成(alpha color component):颜色组成用来描述颜色的透明度或不透明度.阿尔法组成越高,颜色越不透明. API:应用编程接口.针对软 ...
- JavaBean转Map方法
Map<String, Object> fieldMap =new HashMap<String, Object>(); BeanInfo beanInfo = Introsp ...
- ProjectA: 多元非线性回归
https://www.youtube.com/watch?v=n9XycstdPYs&t=907s
- JMeter集合点
位置:添加--> 定时器-->Synchronizing Timer 注意:集合点放在所有操作之前. 假设线程组线程数设置的是50个,那么希望50个都准备好一块上,那么集合点中 ...
- Shader 1:能接受阴影的透明shader
第一次接触Shader,项目需要,直接说需求吧,需要一个透明并且能接受阴影的shader.unity系统自带的shader已经满足不了了.上一段代码吧 Shader "GreenArch/T ...
- js中的call()方法与apply()方法
摘自:http://blog.csdn.net/chelen_jak/article/details/21021101 在web前端开发过程中,我们经常需要改变this指向,通常我们想到的就是用cal ...