2020.05.16【省选B组】模拟 比赛总结

题目

6635. 【USACO 2017 US Open Gold】Problem 1. Bovine Genomics1

Time Limits: 1000 ms
Memory Limits: 262144 KB

Description

Farmer John owns N cows with spots and N cows without spots. Having just completed a course in bovine genetics, he is convinced that the spots on his cows are caused by mutations in the bovine genome. At great expense, Farmer John sequences the genomes of his cows. Each genome is a string of length M built from the four characters A, C, G, and T. When he lines up the genomes of his cows, he gets a table like the following, shown here for N=3 and M=8:
Positions: 1 2 3 4 5 6 7 8

Spotty Cow 1: A A T C C C A T
Spotty Cow 2: A C T T G C A A
Spotty Cow 3: G G T C G C A A

Plain Cow 1: A C T C C C A G
Plain Cow 2: A C T C G C A T
Plain Cow 3: A C T T C C A T

Looking carefully at this table, he surmises that the sequence from position 2 through position 5 is sufficient to explain spottiness. That is, by looking at the characters in just these these positions (that is, positions 2 … 5 ), Farmer John can predict which of his cows are spotty and which are not. For example, if he sees the characters GTCG in these locations, he knows the cow must be spotty.
Please help FJ find the length of the shortest sequence of positions that can explain spottiness.

农夫约翰拥有N头带斑点的奶牛和N头没有斑点的奶牛。他刚刚完成了牛遗传学课程,他确信奶牛上的斑点是由牛基因组突变引起的。

农夫约翰花了大钱对他奶牛的基因组进行测序。每个基因组都是一串长度为M的字符串,由四个字符A,C,G和T构成。当他排列奶牛的基因组时,他得到一张如下表,如下所示

对于N = 3和M = 8:

Positions: 1 2 3 4 5 6 7 8

Spotty Cow 1: A A T C C C A T
Spotty Cow 2: A C T T G C A A
Spotty Cow 3: G G T C G C A A

Plain Cow 1: A C T C C C A G
Plain Cow 2: A C T C G C A T
Plain Cow 3: A C T T C C A T

他仔细查看该表,认为从位置2到位置5的顺序足以解释斑点。也就是说,仅通过查看这些位置(即位置2 ……5)中的字符,农夫约翰就可以预测出他的哪些母牛斑点,哪些不是斑点。例如,如果他在这些位置看到字符GTCG,他就知道那头母牛一定是斑点的。
请帮助FJ找到可以解释斑点的最短位置序列的长度。
FJ有一些有斑点和一些没有斑点的牛,他想搞清楚到底什么基因控制这个牛有没有斑点。
于是他找了n有斑点的牛和n头没有斑点的牛这些牛的基因长度为m(基因中之包含ATCG四个字母)求这个序列中的一个子串,可以确定是否有斑点。
子串需要符合要求:有斑点的牛这部分的子串,不能和无斑点的牛的这部分子串相同求最短子串长度。

Input

The first line of input contains N ( 1 ≤ N ≤ 500 ) and M ( 3 ≤ M ≤ 500 ). The next N lines each contain a string of M characters; these describe the genomes of the spotty cows. The final N lines describe the genomes of the plain cows. No spotty cow has the same exact genome as a plain cow.

Output

Please print the length of the shortest sequence of positions that is sufficient to explain spottiness. A sequence of positions explains spottiness if the spottiness trait can be predicted with perfect accuracy among Farmer John’s population of cows by looking at just those locations in the genome.

Sample Input

3 8
AATCCCAT
ACTTGCAA
GGTCGCAA
ACTCCCAG
ACTCGCAT
ACTTCCAT

Sample Output

4


6636. 【USACO 2017 US Open Gold】Problem 2. Modern Art 2

Time Limits: 1000 ms
Memory Limits: 262144 KB

Description

题目背景

小TY的同学HF也想创作艺术
HF只有一块长条状的画布(画条),所以每一次涂色只能涂上连续几个单位的颜料,同样新的颜料可以完全覆盖旧的颜料
由于他的颜料同样非常傲娇,每次涂完要等上1day才能完全干,只有旧颜料干了以后才能用新颜料覆盖
现在小HF用了2017个年头终于画出了一个大作品,自己非常满意
现在他想复制这份作品

Having become bored with standard 2-dimensional artwork (and also frustrated at others copying her work), the great bovine artist Picowso has decided to switch to a more minimalist, 1-dimensional style.
Although, her paintings can now be described by a 1-dimensional array of colors of length NN( 1 ≤ N ≤ 100 , 0001 ≤ N ≤ 100 , 000 1 \leq N \leq 100,0001≤N≤100,000 1N100,0001N100,000), her painting style remains unchanged: she starts with a blank canvas and layers upon it a sequence of “rectangles” of paint, which in this 1-dimensional case are simply intervals. She uses each of the colors 1 … N 1 \ldots N 1N exactly once, although just as before, some colors might end up being completely covered up by the end.
To Picowso’s great dismay, her competitor Moonet seems to have figured out how to copy even these 1-dimensional paintings, using a similar strategy to the preceding problem: Moonet will paint a set of disjoint intervals, wait for them to dry, then paint another set of disjoint intervals, and so on. Moonet can only paint at most one interval of each color over the entire process. Please compute the number of such rounds needed for Moonet to copy a given 1-dimensional Picowso painting.

现在给你一个长度为N(N≤1e5)的画条上面有若干种颜色,每位的数字表示一种颜色,0表示没有涂色为了快捷,每次涂色可以用一种颜色填充一个区间,同一种颜色只能使用一次每次可以涂色好几次,但是这些区间必须分别连续切两两不能相交
然后等待1day油漆干了后再同样操作,输出创作完成并全干了后的最少时间。

Input

The first line of input contains N, and the next N lines contain an integer in the range 0…N indicating the color of each cell in the 1-dimensional painting (0 for a blank cell).
第一行为N,画条长度

一下N行每行一个数表示颜色

Output

Please output the minimum number of rounds needed to copy this painting, or -1 if this could not have possibly been an authentic work of Picowso (i.e., if she could not have painted it using a layered sequence of intervals, one of each color).
输出一个整数表示最少天数。数据若不合法则输出-1

Sample Input

7
0
1
4
5
1
3
3

Sample Output

2

Hint

样例解释:

第一次可以把1颜色和3颜色填充,变成

0 1 1 1 1 3 3

等待1Day后再填充颜色4和颜色5,变成

0 1 4 5 1 3 3

在等待一Day油漆干了后创作完成

所以答案是2


6637. 【GDOI2020.5.16模拟】Three

Time Limits: 3000 ms
Memory Limits: 1056800 KB

Description

现在有n个数字a[1…n],对于一个长度至少为3的区间[l,r],定义区间的价值为区间中最大的三个数的乘积。求所有区间的价值和。

Input

从文件three.in读入。
第一行一个整数n。第二行n个整数,表示a[1…n]

Output

输出到文件three.out。
一行一个整数,表示所有区间的价值和,答案对10^9+7取模。

Sample Input

5
1 2 3 4 5

Sample Output

234

Data Constraint

对于所有数据,保证 n < = 1 0 6 , 0 < a i < = 1 0 9 n<=10^6,0<ai<=10^9 n<=106,0<ai<=109,所有数字互不相同
对于10%的数据,n<=100
对于30%的数据,n<=1000
对于70%的数据,n<=10^5
对于100%的数据,n<=10^6


总结

今天的题目很简单,但是前两题的题面比较坑,让人读得半懂不懂的。
还好,我蒙对了。
一开始觉得第二题最水,于是先做第二题。
最简单的思路是用一个栈维护每种颜色的先后顺序,答案就是栈的最深层数。
但是若是碰到如 12321144151 12321144151 12321144151这样一个颜色不止出现两次的情况怎么知道当前颜色是否可以退栈呢?我于是预处理出每种颜色最先和最后出现的位置。
接着考虑无解的情况:

  1. 到了一种颜色的最后出现位置时(即这种颜色要退栈),比这种颜色更晚进栈的颜色还没有退栈,如 1212 1212 1212
  2. 填涂顺序比较后的颜色在先填涂的颜色上出现几段,如 122111221 122111221 122111221。这个特判一下就好了。

但是这样子有0出现时比较麻烦,我们只需要把0当成是从0涂到n+1的颜色就好了。

做完T2,读了一下T1,发现读懂了,原来T1也不难。
很容易想到 O ( n 3 ) O(n^3) O(n3)的暴力(枚举长度、起点、字符串,哈希判断),只要用二分枚举长度就能够妥妥地过了。

T3不会,于是打暴力。
考试后发现T3可以用双向链表做。从小到大枚举每一个点(考虑它是第三大的情况),枚举完后删掉它。每次就在链表上找出它左边、左边的左边的点(即是左边比它大的两个点),右边也是如此,统计一下即可。

由于太久没打代码,这次我没有估分。这次比赛我实现代码时思路不太清晰,以后要想清楚再打。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值