BZOJ 2083 Poi2010 Intelligence test 链表
来源:互联网 发布:python编程入门第三版 编辑:程序博客网 时间:2024/05/02 00:47
题目大意:给定序列A,多次询问某个序列B是不是A的子序列
设某个序列B当前需要匹配的元素是x,那么就将所有x相同的B序列存成一个链表放在head[x]上
然后对于A的每个元素x,去head[x]上撸一遍链表,更新这些B序列的当前元素即可
时间复杂度是线性的 不过为毛跑的这么慢= =
#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 1001001using namespace std;struct List{vector<int> seq;int belong;List *next;void* operator new (size_t){static List *mempool,*C;if(mempool==C)mempool=(C=new List[1<<16])+(1<<16);return C++;}}*head[M];int n,m,k;int a[M],b[M];bool ans[M];int main(){int i,j;cin>>n;for(i=1;i<=n;i++)scanf("%d",&a[i]);cin>>m;for(i=1;i<=m;i++){scanf("%d",&k);for(j=1;j<=k;j++)scanf("%d",&b[j]);List *temp=new List;for(j=k;j;j--)temp->seq.push_back(b[j]);temp->belong=i;temp->next=head[temp->seq.back()];head[temp->seq.back()]=temp;}for(i=1;i<=n;i++){List *temp=head[a[i]],*next;head[a[i]]=0x0;for(;temp;temp=next){next=temp->next;temp->seq.pop_back();if(temp->seq.empty())ans[temp->belong]=true;else{temp->next=head[temp->seq.back()];head[temp->seq.back()]=temp;}}}for(i=1;i<=m;i++)puts(ans[i]?"TAK":"NIE");return 0;}
0 0
- BZOJ 2083 Poi2010 Intelligence test 链表
- BZOJ 2083 [Poi2010]Intelligence test
- BZOJ 2083 [Poi2010]Intelligence test 二分查找
- bzoj 2083: [Poi2010]Intelligence test (二分)
- 2083: [Poi2010]Intelligence test
- 【BZOJ】【P2083】【Poi2010】【Intelligence test】【题解】【二分】
- BZOJ2083: [Poi2010]Intelligence test
- BZOJ2083: [Poi2010]Intelligence test
- POI2010 Intelligence Test
- bzoj2083 POI2010 Intelligence Test
- 【bzoj2083】[Poi2010]Intelligence test
- bzoj-2083 Intelligence test
- 【vector】【bzoj 2083】Intelligence test
- [BZOJ2083][Poi2010]Intelligence test(sort+二分)
- [POI2010]TES-Intelligence Test 洛谷3500 二分
- [bzoj2083][Poi2010]Intelligence test(二分)
- [BZOJ 2083] Poi 2010 Intelligence test · 二分
- 题解 BZOJ-2083 || POI 2010 intelligence test 三种解法
- 剑指offer--构建乘积数组
- Android WebView 使用
- 黑马程序员——OCFoundation框架-8:结构体
- Android MP3录音实现
- Vijava 学习笔记之 HostSystem(内存总大小、内存已使用容量和CPU个数)
- BZOJ 2083 Poi2010 Intelligence test 链表
- 分享一个Unity3D点击模型跟随鼠标移动的小脚本(包括屏幕视图到三维空间的坐标转换)
- java学习11--线程创建的两种方式,生命周期以及守护线程
- Android 中获取图片资源的几种方式
- ios,设备标签与设备型号的对应关系(包含6plus)
- Java注释
- Android中解析XML
- iOS——证书那些事
- HTML5 UTF-8 中文乱码