AIM Tech Round 4 (Div. 2)ABCD
1 second
256 megabytes
standard input
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.
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.
题意:给你一个字符串,问你至少要改变多少个字符才能有k个不同字符?
题解:先看字符串长度是否有k个,然后用一个vis数组标记有多少个不用字符出现(tmp),然后如果k>tmp的话ans=k-tmp,否则为0;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn=1e3+;
const ll inf=0x4f4f4f4f4f;
int n,k;
char b[maxn];
int tmp;
bool vis[];
int main()
{
scanf("%s %d",b,&k);
int len=strlen(b);
if(len<k)
{
puts("impossible");return ;
}
for(int i=;i<len;i++)
{
int t=b[i]-'a';
if(!vis[t])vis[t]=true,tmp++;
}
if(k>tmp)
printf("%d\n",k-tmp);
else
printf("0\n");
return ;
}
1 second
256 megabytes
standard input
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:
- 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.
题解:先从n行上算,后再同理从m列上算,每行算出白的个数tmp,黑的个数就是n-tmp,从中tmp挑出1~tmp个的和是2^tmp-1,但这样挑出一个的会算两次,最后把结果再减去n*m就可以了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int maxn=1e3+;
const ll inf=0x4f4f4f4f4f;
int n,m,k;
int a[][];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n>>m;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>a[i][j];
}
}
ll ans=;
for(int i=;i<n;i++)
{
int tmp=;
for(int j=;j<m;j++)
{
if(a[i][j])tmp++;
}
ans=ans+pow(.,tmp)-+pow(.,m-tmp)-;
}
for(int i=;i<m;i++)
{
int tmp=;
for(int j=;j<n;j++)
{
if(a[j][i])tmp++;
}
ans=ans+pow(.,tmp)-+pow(.,n-tmp)-;
}
cout<<ans-n*m<<endl;
return ;
}
1 second
256 megabytes
standard input
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.
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.
题意:就是把一个序列分成尽可能多的子序列,使得每子序列排好序之后,整个序列也是拍好序的
题解:把数组储存再a[]和b[]中,后再把b[]排好序找到每个数应该在的位置,再从a[]开始dfs()找调换的位置,调换好的标记,用vector<int>储存答案就好了,具体dfs()过程看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
#include<vector>
#define pb push_back
#define ll long long
using namespace std;
const int maxn=1e5+;
int n,m,tmp;
int a[maxn];
int b[maxn];
map<int,int>mp;
map<int,bool>mp2;
vector<int> ans[maxn];
void dfs(int x,int p)
{
mp2[x]=true;
if(mp[x]==p)
{
ans[tmp++].pb(p);
return;
}
ans[tmp].pb(p);
if(a[mp[x]]==b[p])
{
ans[tmp++].pb(mp[x]);
mp2[b[p]]=true;
return ;
}
if(!mp2[a[mp[x]]])
dfs(a[mp[x]],mp[x]);
else
{
tmp++;
return ;
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
b[i]=a[i];
}
sort(b+,b++n);
for(int i=;i<=n;i++)
{
mp[b[i]]=i;
mp2[b[i]]=false;
}
for(int i=;i<=n;i++)
{
if(!mp2[a[i]])
{
dfs(a[i],i);
}
}
cout<<tmp<<endl;
for(int i=;i<tmp;i++)
{
cout<<ans[i].size()<<' ';
for(int j=;j<ans[i].size();j++)
{
cout<<ans[i][j]<<' ';
}
cout<<'\n';
}
return ;
}
1 second
256 megabytes
standard input
standard output
This is an interactive problem.
You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.
More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the integer value in this element, and nexti that is the index of the next element of the singly linked list (or -1, if the current element is the last). The list is sorted, i.e. if nexti ≠ - 1, then valuenexti > valuei.
You are given the number of elements in the list n, the index of the first element start, and the integer x.
You can make up to 2000 queries of the following two types:
- ? i (1 ≤ i ≤ n) — ask the values valuei and nexti,
- ! ans — give the answer for the problem: the minimum integer, greater than or equal to x, or ! -1, if there are no such integers. Your program should terminate after this query.
Write a program that solves this problem.
The first line contains three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109) — the number of elements in the list, the index of the first element and the integer x.
To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to x, or -1, if there is no such integer.
To make a query of the first type, print ? i (1 ≤ i ≤ n), where i is the index of element you want to know information about.
After each query of type ? read two integers valuei and nexti (0 ≤ valuei ≤ 109, - 1 ≤ nexti ≤ n, nexti ≠ 0).
It is guaranteed that if nexti ≠ - 1, then valuenexti > valuei, and that the array values give a valid singly linked list with start being the first element.
Note that you can't ask more than 1999 queries of the type ?.
If nexti = - 1 and valuei = - 1, then it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive "Wrong Answer", it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.
Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including the final answer.
To flush you can use (just after printing a query and line end):
- fflush(stdout) in C++;
- System.out.flush() in Java;
- stdout.flush() in Python;
- flush(output) in Pascal;
- For other languages see documentation.
Hacks format
For hacks, use the following format:
In the first line print three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109).
In the next n lines print the description of the elements of the list: in the i-th line print two integers valuei and nexti (0 ≤ valuei ≤ 109, - 1 ≤ nexti ≤ n, nexti ≠ 0).
The printed structure should be a valid singly linked list. In particular, it should be possible to reach all elements from start by following links nexti, and the last element end should have -1 in the nextend.
5 3 80
97 -1
58 5
16 2
81 1
79 4
? 1
? 2
? 3
? 4
? 5
! 81
You can read more about singly linked list by the following link: https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list
The illustration for the first sample case. Start and finish elements are marked dark.
题意:交互题,给你一个单向列表这(单调递增)的长度和起始下标,以及一个数x,然后你可以询问不超过2000次某个下标的的值和他下个数的下标,让你找到这这个列表中>=x的最小值
题解:生成一个随机数组,询问前一千个找到其中小于x的最大值和下标,然后再去一个一个询问找到>=x的值,找不到就为-1
srand(time(NULL));random_shuffle(s.begin(),s.end());这两句可以把有序的数组变成随机数组
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int maxn=1e5+;
int n,m,st;
vector<int>s;
int main()
{
srand(time(NULL));
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n>>st>>m;
int ans=,p=st;
for(int i=;i<=n;i++)
{
s.pb(i);
}
random_shuffle(s.begin(),s.end());
for(int i=;i<min(n,);i++)
{
int v,next;
cout<<"? "<<s[i]<<endl;
cout.flush();
cin>>v>>next;
if(ans<v&&v<=m)
{
ans=v;p=next;
}
}
while(p!=-&&ans<m)
{
cout<<"? "<<p<<endl;
cout.flush();
cin>>ans>>p;
}
if(ans<m)
{
cout<<"! "<<-<<endl;
}
else
{
cout<<"! "<<ans<<endl;
}
cout.flush();
return ;
}
AIM Tech Round 4 (Div. 2)ABCD的更多相关文章
- 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 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 ...
- AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)
rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...
- AIM Tech Round 3 (Div. 2) B 数学+贪心
http://codeforces.com/contest/709 题目大意:给一个一维的坐标轴,上面有n个点,我们刚开始在位置a,问,从a点开始走,走n-1个点所需要的最小路程. 思路:我们知道,如 ...
- AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)
D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...
- AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)
A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
随机推荐
- ascii codec can't decode byte 0xe8 in position 0:ordinal not in range(128) python代码报错
import sys reload(sys) sys.setdefaultencoding('utf-8')
- C++ 将函数作为形参
今天偶然看到一段代码,其中将函数作为形参进行设计,一开始不理解,自己试了一下,发现果然可行 #include <iostream> using namespace std; void vi ...
- java与32/64位虚拟机
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt232 32位电脑与64位电脑有什么不同? 我们通常说的64位技术是相对于32 ...
- 遇到的一些Jquery函数
jQuery.extend() jQuery.merge():函数用于合并两个数组内容到第一个数组. <script> $(function () { ,,], [,,] ...
- 编译make的出错提示解决方案
编译出错笔记:start.s:20: Error: no such instruction: `ldr r0,=WTCON' 错误:没有这样的指令 解决:编译文件后缀名必须为大写S,改为start.S ...
- 【.net 深呼吸】WPF 中的父子窗口
与 WinForm 不同,WPF 并没有 MDI 窗口,但 WPF 的窗口之间是可以存在“父子”关系的. 我们会发现,Window 类公开了一个属性叫 Owner,这个属性是可读可写的,从名字上我们也 ...
- 数据库学习任务四:数据读取器对象SqlDataReader、数据适配器对象SqlDataAdapter、数据集对象DataSet
数据库应用程序的开发流程一般主要分为以下几个步骤: 创建数据库 使用Connection对象连接数据库 使用Command对象对数据源执行SQL命令并返回数据 使用DataReader和DataSet ...
- 图论中DFS与BFS的区别、用法、详解…
DFS与BFS的区别.用法.详解? 写在最前的三点: 1.所谓图的遍历就是按照某种次序访问图的每一顶点一次仅且一次. 2.实现bfs和dfs都需要解决的一个问题就是如何存储图.一般有两种方法:邻接矩阵 ...
- 自制裸眼3D图【推荐】
Welcome to the World of Hidden 3D Stereograms.欢迎进入隐身3D图的世界! 网址:http://hidden-3d.com 裸眼立体图是什么? 立体图是立体 ...
- 团队作业4——第一次项目冲刺(Alpha版本) 2
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 1.完成了大部分查重算法的书写. 余弦查重算法 2.其他非主页面的部分设计. 查重过程的显示页面 四.困难与问题 1.算法是程 ...