2013 ACM/ICPC Asia Regional Nanjing Online( hdu 4749)
来源:互联网 发布:淘宝网广告形式 编辑:程序博客网 时间:2024/06/01 16:00
Parade Show
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 633 Accepted Submission(s): 269
Problem Description
2013 is the 60 anniversary of Nanjing University of Science and Technology, and today happens to be the anniversary date. On this happy festival, school authority hopes that the new students to be trained for the parade show. You should plan a better solution to arrange the students by choosing some queues from them preparing the parade show. (one student only in one queue or not be chosen)
Every student has its own number, from 1 to n. (1<=n<=10^5), and they are standing from 1 to n in the increasing order the same with their number order. According to requirement of school authority, every queue is consisted of exactly m students. Because students who stand adjacent in training are assigned consecutive number, for better arrangement, you will choose in students with in consecutive numbers. When you choose these m students, you will rearrange their numbers from 1 to m, in the same order with their initial one.
If we divide our students’ heights into k (1<=k<=25) level, experience says that there will exist an best viewing module, represented by an array a[]. a[i] (1<=i<=m)stands for the student’s height with number i. In fact, inside a queue, for every number pair i, j (1<=i,j<=m), if the relative bigger or smaller or equal to relationship between the height of student number i and the height of student number j is the same with that between a[i] and a[j], then the queue is well designed. Given n students’ height array x[] (1<=x[i]<=k), and the best viewing module array a[], how many well designed queues can we make at most?
Input
Multiple cases, end with EOF.
First line, 3 integers, n (1<=n<=10^5) m (1<=m<=n) k(1<=k<=25),
Second line, n students’ height array x[] (1<=x[i]<=k,1<=i<=n);
Third line, m integers, best viewing module array a[] (1<=a[i]<=k,1<=i<=m);
First line, 3 integers, n (1<=n<=10^5) m (1<=m<=n) k(1<=k<=25),
Second line, n students’ height array x[] (1<=x[i]<=k,1<=i<=n);
Third line, m integers, best viewing module array a[] (1<=a[i]<=k,1<=i<=m);
Output
One integer, the maximal amount of well designed queues.
Sample Input
10 5 102 4 2 4 2 4 2 4 2 41 2 1 2 1
Sample Output
1
Source
2013 ACM/ICPC Asia Regional Nanjing Online
Recommend
liuyiding
这个题目比赛的时候没有作出来,比较遗憾。
注意两点:
1.使用贪心来遍历,即如果 i开始的队列check成功,则直接跳转到 i+m开始check。无须继续判断i+1的队伍。
2.判断一个队列是否合法,可以是O(m)的复杂度,窍门就是,把所有1~k中出现的位置,都用vector 存储,即v[k] 代表 模式串中身高为k的出现位置。
那么对于目标串,遍历每一个身高p,看看对应的那几个位置是否相等,并存储那个对应值 data[p]。
最后扫一遍data,看是否为递增序列即可。
核心思想就是(该相等的地方,都去给我相等,然后只需要再扫一遍判断递增即可!)
代码如下:
- 2013 ACM/ICPC Asia Regional Nanjing Online( hdu 4749)
- 2013 ACM/ICPC Asia Regional Nanjing Online
- 2013 ACM/ICPC Asia Regional Nanjing Online(更新中)
- hdu 4751 Divide Groups bfs (2013 ACM/ICPC Asia Regional Nanjing Online 1004)
- hdu 4751 Divide Groups bfs (2013 ACM/ICPC Asia Regional Nanjing Online 1004)
- hdu 4750 2013 ACM/ICPC Asia Regional Nanjing Online 1003 并查集+离线操作
- hdu 4751 Divide Groups 2013 ACM/ICPC Asia Regional Nanjing Online
- hdu 4750 Count The Pairs 并查集+递推(2013 ACM/ICPC Asia Regional Nanjing Online 1003)
- hdu 4750 Count The Pairs 并查集+递推(2013 ACM/ICPC Asia Regional Nanjing Online 1003)
- hdu 4750 Count The Pairs 并查集+二分+递推(2013 ACM/ICPC Asia Regional Nanjing Online 1003)
- Count The Pairs (2013 ACM/ICPC Asia Regional Nanjing Online)
- 2013 ACM/ICPC Asia Regional Changchun Online hdu Theme Section
- 2013 ACM/ICPC Asia Regional Hangzhou Online
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 2013 ACM/ICPC Asia Regional Changsha Online
- 2013 ACM/ICPC Asia Regional Changchun Online
- 2013 ACM/ICPC Asia Regional Changchun Online
- 2013 ACM/ICPC Asia Regional Chengdu Online
- 判断字符串是否为布尔型、浮点型、整型...
- Scanner vs. StringTokenizer vs. String.Split
- LCD-驱动基础
- 单例模式
- php分页类
- 2013 ACM/ICPC Asia Regional Nanjing Online( hdu 4749)
- PHP写入txt文件换行
- JBOSS中配置JNDI数据源
- php数据库操作类
- YII 框架 第八天(4) 显示sql语句执行时间
- HBase提供了Java Api的访问接口
- View和其subview的半透明问题
- centos 6.2 编译cowpatty-4.6遇到的问题
- ISF 视频下载地址(持续更新)