BZOJ2083: [Poi2010]Intelligence test
来源:互联网 发布:广联达计价软件 编辑:程序博客网 时间:2024/05/17 01:04
Description
霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列。Lyx很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练习,所以他希望你写一个程序来快速判断他的答案是否正确。
Input
第一行为一个整数m(1<=m<=1000000)第二行包括m个用空格分开的整数ai(1<=ai<=1000000),组成了最初的序列,第三行为一个整数n(1<=n<=1000000),表示n个Lyx经过一系列删除得到的序列,每个序列两行,第一行给出长度L(1<=L<=m),然后下一行为L个由空格分开的整数bi(1<=bi<=1000000)。
Output
共n行,如果Lyx的序列确实是由最初的序列删除一些数得到,就输出TAK,否则输出NIE。
Sample Input
7
1 5 4 5 7 8 6
4
5
1 5 5 8 6
3
2 2 2
3
5 7 8
4
1 5 7 4
1 5 4 5 7 8 6
4
5
1 5 5 8 6
3
2 2 2
3
5 7 8
4
1 5 7 4
Sample Output
TAK
NIE
TAK
NIE
NIE
TAK
NIE
题解:
题目大意为给定n个数,每次给定一个序列,问这个序列是否为给定的原序列的一个子序列(不要求连续)。
这道题很容易想到二分。按照权值做一个vector,每次来一个新数,判断数在序列的位置并记录下last(因为序列是有顺序的),如果找不到,就返回false
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;const int MAXN=1000001;int a[MAXN];vector <int> S[MAXN];vector <int> ::iterator it;int main(int argc, char *argv[]){int n,i,j,x,m,l,r,mid,len,t,last;bool flag;scanf("%d",&m);for(i=1;i<=m;i++)scanf("%d",&a[i]),S[a[i]].push_back(i);scanf("%d",&n);for(i=1;i<=n;i++){flag=true;scanf("%d",&len);l=0,r=m,last=0;for(j=1;j<=len;j++){scanf("%d",&x);if(flag==false) continue;if(S[x].empty()) {flag=false;continue;}it=upper_bound(S[x].begin(),S[x].end(),last);if(it==S[x].end()) flag=false;last=*it;}if(flag==false) printf("NIE\n");else printf("TAK\n");}return 0;}
0 0
- BZOJ2083: [Poi2010]Intelligence test
- BZOJ2083: [Poi2010]Intelligence test
- bzoj2083 POI2010 Intelligence Test
- 【bzoj2083】[Poi2010]Intelligence test
- [BZOJ2083][Poi2010]Intelligence test(sort+二分)
- [bzoj2083][Poi2010]Intelligence test(二分)
- BZOJ2083:[POI] TES-Intelligence Test
- POI2010 Intelligence Test
- 2083: [Poi2010]Intelligence test
- BZOJ 2083 [Poi2010]Intelligence test
- 【BZOJ】【P2083】【Poi2010】【Intelligence test】【题解】【二分】
- BZOJ 2083 Poi2010 Intelligence test 链表
- BZOJ 2083 [Poi2010]Intelligence test 二分查找
- bzoj 2083: [Poi2010]Intelligence test (二分)
- [POI2010]TES-Intelligence Test 洛谷3500 二分
- 【bzoj2083】 POI2010Intelligence test 乱搞
- bzoj2083
- Intelligence test(test)题解
- Android基础之再回顾
- Android之批量加载图片OOM问题解决方案
- Android alertdialog的自定义添加按钮和添加点击
- Spinner
- The serializable class Myplayer does not declare a static final serialVersionUID field of type long
- BZOJ2083: [Poi2010]Intelligence test
- Android Studio库工程上传maven
- mininet安装与使用,wireshark抓包器, iperf网络性能检测
- 保护模式及其编程——实模式与保护模式的切换
- linux 常用命令 (汇总加转载 二 find / less)
- 计算机网络的三种通讯模式(单播,广播,组播)小结
- sql server的某些表
- h5学习笔记: 下拉菜单
- Java:继承