2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
3 seconds
256 megabytes
standard input
standard output
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 ≤ m ≤ 1000) — the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves — n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
4
a**d
2
abcd
acbd
2
5
lo*er
2
lover
loser
0
3
a*a
2
aaa
aba
1
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
给一个字符串,该字符串中有*,*表示该位置是未知的,其余表示已知的。问你存在多少个字符,使得这种字符一定能转变至少一个*。直接枚举26个字符就可以了啊
#include <bits/stdc++.h>
using namespace std;
string s,a[];
int n,m,vis[],V[];
int main()
{
int ans=;
ios::sync_with_stdio(false);
cin>>n>>s;
for(int i=; s[i]; i++)
vis[s[i]-'a']=;
cin>>m;
for(int i=; i<m; i++)
cin>>a[i];
for(int i=; i<; i++)
{
char c='a'+i;
if(vis[c])continue;
int ff=;
for(int j=; j<m; j++)
{
memset(V,,sizeof(V));
int f=;
for(int k=; k<n; k++)
{
if(s[k]=='*'&&vis[a[j][k]-'a'])
{
f=;
break;
}
if(s[k]=='*')V[a[j][k]-'a']++;
else if(s[k]!=a[j][k])f=;
}
if(f&&V[i]==)ff=;
}
if(ff)ans++;
}
printf("%d\n",ans);
return ;
}
3 seconds
256 megabytes
standard input
standard output
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" "oo" and "h"
"kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
- "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper"
"kuuper" and "kuooper"
"kuuper".
- "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun"
"khoon" and "kkkhoon"
"kkhoon"
"khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
4
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
5
2
alex
alex
1
There are four groups of words in the first example. Words in each group denote same name:
- "mihail", "mikhail"
- "oolyana", "ulyana"
- "kooooper", "koouper"
- "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
- "hariton", "kkkhariton", "khariton"
- "hkariton"
- "buoi", "boooi", "boui"
- "bui"
- "boi"
In the third example the words are equal, so they denote the same name.
可以这样xjb变,u" 变"oo" and "h" 变"kh",有h了就可以无限消k,你给他们变到一种上,问有几种
#include <bits/stdc++.h>
using namespace std;
int n,ans;
char s[];
map<string,bool> vis;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%s",s+);
int m=strlen(s+);
string c="";
for(int j=m; j>; j--)
if(s[j]=='u') c="oo"+c;
else if(s[j]=='h')
{
int l=j-;
while(l&&s[l]=='k') l--;
j=l+;
c='h'+c;
}
else c=s[j]+c;
if(!vis[c]) ans++,vis[c]=;
}
printf("%d\n",ans);
return ;
}
3 seconds
256 megabytes
standard input
standard output
Kolya has a string s of length n consisting of lowercase and uppercase Latin letters and digits.
He wants to rearrange the symbols in s and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forward, such as madam or racecar.
Your task is to help Kolya and determine the minimum number of palindromes of equal lengths to cut s into, if it is allowed to rearrange letters in s before cuttings.
The first line contains an integer n (1 ≤ n ≤ 4·105) — the length of string s.
The second line contains a string s of length n consisting of lowercase and uppercase Latin letters and digits.
Print to the first line an integer k — minimum number of palindromes into which you can cut a given string.
Print to the second line k strings — the palindromes themselves. Separate them by a space. You are allowed to print palindromes in arbitrary order. All of them should have the same length.
6
aabaac
2
aba aca
8
0rTrT022
1
02TrrT20
2
aA
2
a A
给你一个长度为n的字符串,让你把他处理成回文子串,问你最少分成几个串
看成对的字母有多少个,贪心处理下吧,奇数的放中间,偶数扔两边
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+;
char s[N];
int a[N],b[N];
int A,B,n,t[];
int main()
{
scanf("%d",&n);
scanf("%s",s+);
for(int i=; i<=n; i++)
t[s[i]]++;
for(int i=; i<; i++)
{
for(int j=; j<=t[i]/; j++)a[++A]=i;
if(t[i]&)b[++B]=i;
}
if(!B)
{
printf("%d\n",);
for(int i=; i<=A; i++)putchar(a[i]);
for(int i=A; i>=; i--)putchar(a[i]);
return ;
}
for(int i=; i<=n; i++)
if(n%i==)
{
if(n/i%==)continue;
int r=(n/i-)/;
if(A<r*i)continue;
printf("%d\n",i);
for(int j=r*i+; j<=A; j++)
{
b[++B]=a[j];
b[++B]=a[j];
}
for(int j=; j<=i; j++)
{
for(int k=(j-)*r+; k<=j*r; k++)putchar(a[k]);
putchar(b[j]);
for(int k=j*r; k>=(j-)*r+; k--)putchar(a[k]);
putchar(' ');
}
return ;
}
}
3 seconds
256 megabytes
standard input
standard output
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field,
- go around the flag,
- close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (x1, y1) and the coordinates of the point where the flag is situated (x2, y2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (x, y) to any of four points: (x - 1, y), (x + 1, y), (x, y - 1) or (x, y + 1).
Thus the quadcopter path is a closed cycle starting and finishing in (x1, y1) and containing the point (x2, y2) strictly inside.
The picture corresponds to the first example: the starting (and finishing) point is in (1, 5) and the flag is in (5, 2).
What is the minimal length of the quadcopter path?
The first line contains two integer numbers x1 and y1 ( - 100 ≤ x1, y1 ≤ 100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers x2 and y2 ( - 100 ≤ x2, y2 ≤ 100) — coordinates of the flag.
It is guaranteed that the quadcopter starting point and the flag do not coincide.
Print the length of minimal path of the quadcopter to surround the flag and return back.
1 5
5 2
18
0 1
0 0
8
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("%d\n",+max(abs(x1-x2),)*+max(abs(y1-y2),)*);
}
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)的更多相关文章
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- 服务器 未能加载文件或程序集“XXXX”或它的某一个依赖项。试图加载格式不正确的程序。
,本人采用的第一种解决办法解决,已解决 问题2: 在同一个服务器上想要一个IP有两个网址,配置端口号,给新端口号开权限
- 学习typescript(一)
环境 必装软件 node,推荐 node 8.0 npm,推荐 npm 5.0 git, 最新版 vscode, 编绎器 必装包 tsc: npm install -g typescript typi ...
- 在Windows 10删除百度云盘的盘符
1点击微软图标不放,然后点击R 打开运行命令 2输入 Regedit 进入注册表 3找到以下路径:HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows ...
- Asp.net Mvc 表单验证(气泡提示)
将ASP.NET MVC或ASP.NET Core MVC的表单验证改成气泡提示: //新建一个js文件(如:jquery.validate.Bubble.js),在所有要验证的页面引用 (funct ...
- DataModel doesn't have preference values
mahout和hadoop实现简单的智能推荐系统的时候,出现了一下几个方面的错误 DataModel doesn't have preference values 意思是DataModel中没有找到初 ...
- UVALive 4080 Warfare And Logistics (最短路树)
很多的边会被删掉,需要排除一些干扰进行优化. 和UVA - 1279 Asteroid Rangers类似,本题最关键的地方在于,对于一个单源的最短路径来说,如果最短路树上的边没有改变的话,那么最短路 ...
- sort函数的使用
此篇当作自己的笔记(水平太菜,这都一直没搞明白) sort()函数的用法1)sort函数包含在头文件<algroithm>中,还要结合using namespace std2)sort有三 ...
- 关于回顾css发现的一些问题
1.针对于before和after伪元素的用法: <style> .clearfix:before, .clearfix:after{ clear:both; content:" ...
- C语言中函数参数传递
C语言中函数参数传递的三种方式 (1)值传递,就是把你的变量的值传递给函数的形式参数,实际就是用变量的值来新生成一个形式参数,因而在函数里对形参的改变不会影响到函数外的变量的值.(2)地址传递,就是把 ...
- 在行列都排好序的矩阵中找数 【题目】 给定一个有N*M的整型矩阵matrix和一个整数K, matrix的每一行和每一 列都是排好序的。实现一个函数,判断K 是否在matrix中。 例如: 0 1 2 5 2 3 4 7 4 4 4 8 5 7 7 9 如果K为7,返回true;如果K为6,返 回false。 【要求】 时间复杂度为O(N+M),额外空间复杂度为O(1)。
从对角考虑 package my_basic.class_3; /** * 从对角开始 */ public class Code_09_FindNumInSortedMatrix { public s ...