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 ...
随机推荐
- hover用法实例
//hover,鼠标移入移出的另一种用法 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" &qu ...
- 大数据平台搭建-spark集群安装
版本要求 java 版本:1.8.*(1.8.0_60) 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downl ...
- 使用ASP.NET Core MVC 和 Entity Framework Core 开发一个CRUD(增删改查)的应用程序
使用ASP.NET Core MVC 和 Entity Framework Core 开发一个CRUD(增删改查)的应用程序 不定时更新翻译系列,此系列更新毫无时间规律,文笔菜翻译菜求各位看官老爷们轻 ...
- linux命令详解(一)netstat
今天在使用linux的时候,要查看端口号,但是不知道要使用哪一个命令所以就学习了一下,原来是使用netstat,接下来给大家一起来学习. 一.netstat介绍 1.1.简介 Netstat 命令用于 ...
- 工具类:关于解决数据库中的日期格式,经过response.getWriter().write(json)打到前台日期格式混乱的问题的总结
经过response.getWriter().write(json)打到前台日期格式混乱的问题的总结 import java.text.SimpleDateFormat;import net.sf.j ...
- 201521123088《JAVA程序设计》第8周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4 ...
- 201521123089《Java程序设计》第6周学习总结
1. 本周学习总结 2. 书面作业 clone方法1.1 Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? ...
- 201521123111《Java程序设计》第13周学习总结
本次作业参考文件 正则表达式参考资料 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1. 网络基础 1.1 比较ping www.bai ...
- Java十二周总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- 201521123106 《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...