map会超时,二分吧...

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std; int n,m;
int tot; vector<int>v[];
struct X
{
int id;
int num;
char name[][];
}s[]; struct Name
{
char name[];
}op[]; bool cmp2(const Name&a,const Name&b)
{
return strcmp(a.name,b.name)<;
} bool cmp(const X&a,const X&b)
{
return a.id<b.id;
} char quary[][]; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d",&s[i].id);
scanf("%d",&s[i].num);
for(int j=;j<=s[i].num;j++) scanf("%s",s[i].name[j]);
}
for(int i=;i<=n;i++)
{
scanf("%s",op[i].name);
strcpy(quary[i],op[i].name);
}
sort(op+,op++n,cmp2); sort(s+,s++m,cmp); for(int i=;i<=m;i++)
{
for(int j=;j<=s[i].num;j++)
{
int h=;
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(strcmp(op[mid].name,s[i].name[j])<) l=mid+;
else if(strcmp(op[mid].name,s[i].name[j])>) r=mid-;
else
{
h=mid;
break;
}
}
if(h==) continue;
v[h].push_back(s[i].id);
}
} for(int i=;i<=n;i++)
{
int q=;
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(strcmp(op[mid].name,quary[i])<) l=mid+;
else if(strcmp(op[mid].name,quary[i])>) r=mid-;
else
{
q=mid;
break;
}
}
if(q==) continue; printf("%s ",quary[i]);
printf("%d",v[q].size());
for(int j=;j<v[q].size();j++) printf(" %d",v[q][j]);
printf("\n");
} return ;
}

PAT (Advanced Level) 1039. Course List for Student (25)的更多相关文章

  1. PAT (Advanced Level) Practise - 1094. The Largest Generation (25)

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  2. PAT (Advanced Level) Practice 1036 Boys vs Girls (25 分)

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  3. PAT (Advanced Level) 1102. Invert a Binary Tree (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  4. PAT (Advanced Level) 1098. Insertion or Heap Sort (25)

    简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...

  5. PAT (Advanced Level) 1067. Sort with Swap(0,*) (25)

    只对没有归位的数进行交换. 分两种情况: 如果0在最前面,那么随便拿一个没有归位的数和0交换位置. 如果0不在最前面,那么必然可以归位一个数字,将那个数字归位. 这样模拟一下即可. #include& ...

  6. PAT (Advanced Level) 1066. Root of AVL Tree (25)

    AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<c ...

  7. PAT (Advanced Level) 1055. The World's Richest (25)

    排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<alg ...

  8. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. PAT (Advanced Level) 1002. A+B for Polynomials (25)

    为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...

随机推荐

  1. Cognos添加关联字段

    (这是另一个表)

  2. 自定义Jquery 下拉框

    (function ($){ 'use strict'; var g_id = 0; var g_open_id = []; $.fn.select3 = function () { var _id ...

  3. js toString() 方法 Number() 方法 等 类型转换

    1.1 数字类型转字符串 String() 变量.toString() toString() 方法 toString() 方法可把一个逻辑值转换为字符串,并返回结果. 1.2 字符串转数字类型 Num ...

  4. 深度剖析 MySQL 事务隔离

    概述 今天主要分享下MySQL事务隔离级别的实现原理,因为只有InnoDB支持事务,所以这里的事务隔离级别是指InnoDB下的事务隔离级别. 隔离级别 读未提交:一个事务可以读取到另一个事务未提交的修 ...

  5. 中位数II

    该题目与思路分析来自九章算法的文章,仅仅是自己做个笔记! 题目:数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 解答: 这道题是用堆解决的问题.用两个堆,max he ...

  6. C/C++语言:科学计数法

    主要用来表示浮点数,表达方便 浮点数的科学计数,由三个部分组成: a + E + b a:由一个浮点数组成,如果写成整数,编译器会自动转化为浮点数: E:可以大写E,也可以小写e: b:使用一个十进制 ...

  7. C++关键字(保留字)

    C++ 关键字 点击下表以进入具体释义 __abstract 2 __alignof Operator __asm __assume __based __box 2 __cdecl __declspe ...

  8. dinic网络流

    C - A Plug for UNIX POJ - 1087 You are in charge of setting up the press room for the inaugural meet ...

  9. nginx代理yum

    适用场景:有多台服务器,但是只有1台服务器可以出公网,此时即可使用如下方式,进行yum代理,解决内网服务器不能yum的尴尬. 一.首先需要把/etc/yum.repos.d下的文件备份到bak,然后留 ...

  10. webpack 之 缓存处理

    针对 这里 的所提到的观点,如果webpack每次都生成相同名字的bundle.js,会导致问题.这里使用webpack的文件hash功能来解决,简简单单地为输出文件添加一个“[hash]”即可. / ...