Redian新闻
>
推荐个做knockout小鼠的公司
avatar
推荐个做knockout小鼠的公司# Biology - 生物学
p*2
1
前两天有人问DP和Greedy的区别,今天做了一道题不错。我先用DP解,当时感觉有点别
扭,因为觉得好像有条件没有用上,结果超时。后来才意识到这题是Greedy. 想感觉一
下DP和Greedy的可以练练。
Sergey attends lessons of the N-ish language. Each lesson he receives a
hometask. This time the task is to translate some sentence to the N-ish
language. Sentences of the N-ish language can be represented as strings
consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot about the task until half an hour before the next
lesson and hastily scribbled something down. But then he recollected that in
the last lesson he learned the grammar of N-ish. The spelling rules state
that N-ish contains some "forbidden" pairs of letters: such letters can
never occur in a sentence next to each other. Also, the order of the letters
doesn't matter (for example, if the pair of letters "ab" is forbidden, then
any occurrences of substrings "ab" and "ba" are also forbidden). Also, each
pair has different letters and each letter occurs in no more than one
forbidden pair.
Now Sergey wants to correct his sentence so that it doesn't contain any "
forbidden" pairs of letters that stand next to each other. However, he is
running out of time, so he decided to simply cross out some letters from the
sentence. What smallest number of letters will he have to cross out? When a
letter is crossed out, it is "removed" so that the letters to its left and
right (if they existed), become neighboring. For example, if we cross out
the first letter from the string "aba", we get the string "ba", and if we
cross out the second letter, we get "aa".
Input
The first line contains a non-empty string s, consisting of lowercase Latin
letters — that's the initial sentence in N-ish, written by Sergey. The
length of string s doesn't exceed 105.
The next line contains integer k (0 ≤ k ≤ 13) —
the number of forbidden pairs of letters.
Next k lines contain descriptions of forbidden pairs of letters. Each line
contains exactly two different lowercase Latin letters without separators
that represent the forbidden pairs. It is guaranteed that each letter is
included in no more than one pair.
Output
Print the single number — the smallest number of letters that need to be
removed to get a string without any forbidden pairs of neighboring letters.
Please note that the answer always exists as it is always possible to remove
all letters.
Sample test(s)
input
ababa
1
ab
output
2
input
codeforces
2
do
cs
output
1
avatar
w*e
2
一年前refer过别人,一直没收到5000点bonus,今天终于打了个电话。客服问了refer
的大概时间,应收到多少bonus,然后立马加上了,很爽快。估计我说多少她就给加多
少。
avatar
j*z
3
想做个conditional knockout小鼠,请大家推荐一个公司吧。
最重要的是可靠和快捷,价钱考虑次要
先谢谢了
avatar
r*k
4
背景是算法高手啊。

★ 发自iPhone App: ChineseWeb - 中文网站浏览器

【在 p*****2 的大作中提到】
: 前两天有人问DP和Greedy的区别,今天做了一道题不错。我先用DP解,当时感觉有点别
: 扭,因为觉得好像有条件没有用上,结果超时。后来才意识到这题是Greedy. 想感觉一
: 下DP和Greedy的可以练练。
: Sergey attends lessons of the N-ish language. Each lesson he receives a
: hometask. This time the task is to translate some sentence to the N-ish
: language. Sentences of the N-ish language can be represented as strings
: consisting of lowercase Latin letters without spaces or punctuation marks.
: Sergey totally forgot about the task until half an hour before the next
: lesson and hastily scribbled something down. But then he recollected that in
: the last lesson he learned the grammar of N-ish. The spelling rules state

avatar
i*0
5
国内还是国外?国内的有一堆这样的公司。南模、赛页、赛图都可以。
avatar
l*a
6
都不懂的先顶后看

in

【在 p*****2 的大作中提到】
: 前两天有人问DP和Greedy的区别,今天做了一道题不错。我先用DP解,当时感觉有点别
: 扭,因为觉得好像有条件没有用上,结果超时。后来才意识到这题是Greedy. 想感觉一
: 下DP和Greedy的可以练练。
: Sergey attends lessons of the N-ish language. Each lesson he receives a
: hometask. This time the task is to translate some sentence to the N-ish
: language. Sentences of the N-ish language can be represented as strings
: consisting of lowercase Latin letters without spaces or punctuation marks.
: Sergey totally forgot about the task until half an hour before the next
: lesson and hastily scribbled something down. But then he recollected that in
: the last lesson he learned the grammar of N-ish. The spelling rules state

avatar
Z*5
7
赛图听说不错,但是没有合作过。
赛业名声已经臭大街了。谈合作的时候说先交首款,做出来交尾款,做不出来退首款。
结果做不出来钱也不退。重要的是我们单位好几个找赛业做的都没搞出来。
avatar
p*2
8

大牛又来装嫩了?

【在 l*****a 的大作中提到】
: 都不懂的先顶后看
:
: in

avatar
t*m
9
百奥赛图,版友创业成功的公司。在国内做得很大
avatar
h*6
10
1.each pair has different letters
2.each letter occurs in no more than one forbidden pair.
这两个条件很重要。
avatar
j*z
11
谢谢大家的推荐,不过实验室在美国,想用版友创业的公司有难度啊
美国这里有什么推荐的吗??
avatar
B*1
12
弱问,dp咋做的?
avatar
r*e
13
www.horizondiscovery.com/in-vivo-models/sagespeed-custom-model-creation
avatar
b*u
14
greedy难在不知道greedy可以。用dp绕半天浪费时间。greedy关键要能证明能贪

in

【在 p*****2 的大作中提到】
: 前两天有人问DP和Greedy的区别,今天做了一道题不错。我先用DP解,当时感觉有点别
: 扭,因为觉得好像有条件没有用上,结果超时。后来才意识到这题是Greedy. 想感觉一
: 下DP和Greedy的可以练练。
: Sergey attends lessons of the N-ish language. Each lesson he receives a
: hometask. This time the task is to translate some sentence to the N-ish
: language. Sentences of the N-ish language can be represented as strings
: consisting of lowercase Latin letters without spaces or punctuation marks.
: Sergey totally forgot about the task until half an hour before the next
: lesson and hastily scribbled something down. But then he recollected that in
: the last lesson he learned the grammar of N-ish. The spelling rules state

avatar
l*y
15
www.taconic.com

【在 j***z 的大作中提到】
: 谢谢大家的推荐,不过实验室在美国,想用版友创业的公司有难度啊
: 美国这里有什么推荐的吗??

avatar
p*2
16

是。因为做过很多类似的DP题,上来就往DP那里想了。做的时候才发觉DP帮助不明显。
但是测试用例也都过了,就提交了。这题证明greedy可以也得花一些时间。不是很直观
。如果只是有思路的话,还是会在greedy和dp只见纠缠。感觉比赛的时候很难掌握呀。
另外,上一下greedy的代码。
public class test2 {
static String s;
static int k;
static HashSet pairs = new HashSet();
static boolean isForbidden(char[] arr) {
Arrays.sort(arr);
return pairs.contains(new String(arr));
}
static int Play(String str) {
int count = 0;
int count1 = 0;
int count2 = 0;
int j = 0;
for (int i = 0; i < str.length() - 1; i++) {
if (str.charAt(i) == str.charAt(i + 1))
count1++;
else {
if (isForbidden(str.substring(i, i + 2).toCharArray())) {
for (j = i; j < str.length(); j++) {
if (str.charAt(j) == str.charAt(i))
count1++;
else if (str.charAt(j) == str.charAt(i + 1))
count2++;
else {
break;
}
}
} else {
count1 = 0;
}
}
if (j != 0) {
count += Math.min(count1, count2);
i = j - 1;
count1 = 0;
count2 = 0;
j = 0;
}
}
return count;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
s = in.next();
k = in.nextInt();
if (k == 0) {
System.out.println(0);
return;
}
for (int i = 0; i < k; i++) {
char[] arr = in.next().toCharArray();
Arrays.sort(arr);
pairs.add(new String(arr));
}
System.out.println(Play(s));
}
}

【在 b***u 的大作中提到】
: greedy难在不知道greedy可以。用dp绕半天浪费时间。greedy关键要能证明能贪
:
: in

avatar
i*h
17
有第二个条件的话, 岂不是扫一遍就可以了?
如果要去掉 ab 的话,
只要解决 aaab 和 abbb 的情形就可以了

【在 h**6 的大作中提到】
: 1.each pair has different letters
: 2.each letter occurs in no more than one forbidden pair.
: 这两个条件很重要。

avatar
l*k
18
这个解法不对吧,如果ab是一个forbidden pair, 那么遇到aabbbaa这种情况,应该划
掉bbb,而不是aa。

【在 p*****2 的大作中提到】
:
: 是。因为做过很多类似的DP题,上来就往DP那里想了。做的时候才发觉DP帮助不明显。
: 但是测试用例也都过了,就提交了。这题证明greedy可以也得花一些时间。不是很直观
: 。如果只是有思路的话,还是会在greedy和dp只见纠缠。感觉比赛的时候很难掌握呀。
: 另外,上一下greedy的代码。
: public class test2 {
: static String s;
: static int k;
: static HashSet pairs = new HashSet();
: static boolean isForbidden(char[] arr) {

avatar
i*h
19
对于ab, 找出任何一个 (a*b*)* 的子串,
如果子串里a的数目大于b, 删b, 反之删a

【在 l********k 的大作中提到】
: 这个解法不对吧,如果ab是一个forbidden pair, 那么遇到aabbbaa这种情况,应该划
: 掉bbb,而不是aa。

avatar
p*2
20

我的代码会划掉b的。你再仔细看看。

【在 l********k 的大作中提到】
: 这个解法不对吧,如果ab是一个forbidden pair, 那么遇到aabbbaa这种情况,应该划
: 掉bbb,而不是aa。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。