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. jq获取设置选中值

    var standard = $('input[name="standard"]:checked').val(); $("input[name='advertByid'] ...

  2. 手把手教你免费把网站IP换成1.1.1.1/1.0.0.1

    近日,Cloudflare官方发文,与APNIC官方合作打算用IP1.1.1.1推出速度更快.私密性更强的DNS Cloudflare 运行全球规模最大.速度最快的网络之一. APNIC 是一个非营利 ...

  3. SpringBoot集成FastDFS+Nginx整合基于Token的防盗链

    为什么要用SpringBoot? SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人 ...

  4. faster rcnn训练过程讲解

    http://blog.csdn.net/u014696921/article/details/60321425

  5. 普通用户切换到root用户

    普通用户切换到root用户首先按组合键 CTRL+ALT+T 进入终端界面,一般终端界面默认为普通用户权限模式,如何从普通用户进入root用户首先重置root密码输入 sudo passwd root ...

  6. Java任务执行计时

    Long startTime = System.currentTimeMillis(); Long endTime = System.currentTimeMillis(); endTime-star ...

  7. 【2019.6.2】python:json操作、函数、集合、random()等

    一.json操作: json就是一个字符串,从文件中读取json,必须是json格式.j'son串中必须是双引号,不能有单引号,单引号不能转换 1.1使用: import json #使用json先引 ...

  8. 拖拽功能-jquery

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. uncategorized SQLException for SQL []; SQL state [99999]; error code [17004]; 无效的列类型: 1111; nested exception is java.sql.SQLException: 无效的列类型: 1111

    WHERE 的条件取值时添加上jdbcType=NUMBER这样的配置 参考[1]:https://blog.csdn.net/fyhjuyol/article/details/45483167

  10. json_decode 解析带BOM头文件错误

    //取前三个字符 并转化为ASCII 判断是否为BOM文件 $charset[1] = substr($result, 0, 1); $charset[2] = substr($result, 1, ...