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 ...
随机推荐
- [HDU - 5170GTY's math problem 数的精度类
题目链接:HDU - 5170GTY's math problem 题目描述 Description GTY is a GodBull who will get an Au in NOI . To h ...
- arcgis api for js入门开发系列十五台风轨迹
上一篇实现了demo的地图最近设施点路径分析,本篇新增台风轨迹,截图如下: 下面简单介绍相关知识点: 警戒线 警戒线坐标集合: var lineArr24=[[127,34],[127,21],[11 ...
- P、NP、NP完全问题
如果一个算法的最差时间效率属于O(p(n)),则该算法可以在多项式的时间内对问题进行求解,其中p(n)是输入规模n的一个多项式函数. 可以在多项式时间内求解的问题是易解的.不能在多项式时间内求解的问题 ...
- Vue入门总结
技术栈:VUE:Vue-router:Vue-resource:Vue-cli: 项目:个人博客vue重构 一.vue-cli脚手架搭建项目结构 全局安装vue-cli: npm install vu ...
- Hello TensorFlow
官方说明:https://www.tensorflow.org/install/ 环境: 操作系统 :Windows 10 家庭中文版 处理器 : Intel(R) Core(TM) i7-7700 ...
- golang sql database drivers
https://github.com/golang/go/wiki/SQLDrivers SQL database drivers The database/sql and database/sql/ ...
- 【原创】java NIO FileChannel 学习笔记 FileChannel 简介
java NIO 中FileChannel 的实现类是 FileChannelImpl,FileChannel本身是一个抽象类. 先介绍FileChannel File Channels 是线程安全 ...
- 基于zepto的移动端日期和时间选择控件
前段时间给大家分享过一个基于jQuery Mobile的移动端日期时间拾取器,大家反应其由于加载过大的插件导致影响调用速度.那么今天我把从网络上搜集到的两个适合移动端应用的日期和时间选择插件分享给大家 ...
- 关于 Python 入门的一些问题?
一.用 python 能够做什么?解决什么问题? A1:理论上来说,计算机能做什么,python 语言就能让它做什么,也即 python能做什么. 数值计算.机器学习.爬虫.云相关开发.自动化测试.运 ...
- SpringCloud学习笔记(4)——Zuul
参考Spring Cloud官方文档第19章 19. Router and Filter: Zuul 路由是微服务架构的一部分.例如,"/"可能映射到你的web应用,"/ ...