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 ...
随机推荐
- 延迟实例化 Lazy<T>
之前写的设计模式 单例模式中,推荐了使用Lazy<T>来达到线程安全和减少系统资源消耗的作用. 作用及优点: 创建某一个对象需要很大的消耗,而这个对象在运行过程中又不一定用到,为了避免每次 ...
- JQ在线引用地址
1.7.2版本 百度的引用地址: <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js">< ...
- [js高手之路]javascript腾讯面试题学习封装一个简易的异步队列
这道js的面试题,是这样的,页面上有一个按钮,一个ul,点击按钮的时候,每隔1秒钟向ul的后面追加一个li, 一共追加10个,li的内容从0开始技术( 0, 1, 2, ....9 ),首先我们用闭包 ...
- 定时调度框架:Quartz.net
Quartz.net相关概念 经常出现场景:定时轮询数据库同步,定时邮件通知,定时处理数据等 Scheduler (计划者或调度器) Job (工作对象):将要定时执行的任务代码写到实现Ijob接口的 ...
- 团队作业8——第二次项目冲刺(Beta阶段)Day6——5.25
1.提供当天会议照片: 2.会议的内容: (1)讨论已经完成的功能,讨论存在的问题 (2)对于界面,谈谈各自的看法 (3)讨论接下来的任务和改进的地方 3.工作安排: 队员 今日任务 明日任务 贡献比 ...
- 201521123055 《Java程序设计》第7周学习总结
1. 本章学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 1.2 解释E remove(int index)源代码 1.3 结合1.1 ...
- 《Java程序设计》第5周学习总结
1. 本章学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 2. 书面作业 1. 代码阅读:Child压缩包内源代码 1.1 com.par ...
- Git与码云(Git@OSC)入门-如何在实验室和宿舍同步你的代码(1)
0.几个基本概念 本地仓库:本机上某个存放代码的仓库. 远程仓库:码云服务器上的代码仓库. 重要提醒:当我们在本地操作(新增.删除.修改)文件.目录时,并将其提交(commit),就是提交到了本地仓库 ...
- Java 课程设计 "Give it up"小游戏(团队)
JAVA课程设计 "永不言弃"小游戏(From :Niverse) 通过Swing技术创建游戏的登陆注册界面,使用mySQL数据库技术完成用户的各项信息保存和游戏完成后的成绩保存. ...
- 201521123011《Java程序设计》 第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...