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. js 字符串截取 substring() 方法、 substr() 方法、slice() 方法、split() 、join();

    三种 js 截取字符串的方法: substring() 方法: substr() 方法: slice() 方法: 1.:substring() 方法:string.substring(from, to ...

  2. 网新恩普(W 笔试)

    选择题 1.一桶有黄色,绿色,红色三种,闭上眼睛抓取同种颜色的两个.抓取多少个就可以确定你肯定有两个同一颜色的球? 答案: 4次 1.最坏打算抓3次都是不同颜色的黄.绿.红,此时,三种颜色的球各抓了一 ...

  3. k8s 重要概念[转]

    在实践之前,必须先学习 Kubernetes 的几个重要概念,它们是组成 Kubernetes 集群的基石. Cluster Cluster 是计算.存储和网络资源的集合,Kubernetes 利用这 ...

  4. Android项目源码分享

    http://blog.csdn.net/gao_chun/article/details/47263063 Android项目源码分享 给大家分享几个Android开发项目源码,大部分功能相信可以在 ...

  5. python爬虫---实现项目(一) Requests爬取HTML信息

    上面的博客把基本的HTML解析库已经说完了,这次我们来给予几个实战的项目. 这次主要用Requests库+正则表达式来解析HTML. 项目一:爬取猫眼电影TOP100信息 代码地址:https://g ...

  6. Archive for required library: 'D:/Program Files/Apache/maven-repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar'

    今天导入一个项目工程,发现报错:Archive for required library: 'D:/Program Files/Apache/maven-repository/dom4j/dom4j/ ...

  7. process data

    # version 1.0def connect_mysql(sql, oper_type="select", data_l=None): conn = pymysql.conne ...

  8. android开发链接

    http://blog.csdn.net/zz2043191420/article/details/47338591

  9. git命令使用(一)

    作为程序员怎么能不了解git命令呢,但是由于本人不常用到git命令,现在的软件上也都一体化了,能够简化命令,直接运行都可以了,完全能够去实现git上的命令,导致输入git命令完全不会,git命令能够让 ...

  10. LeetCode(42)Trapping Rain Water

    题目 Given n non-negative integers representing an elevation map where the width of each bar is 1, com ...