PAT (Advanced Level) 1039. Course List for Student (25)
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)的更多相关文章
- 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 ...
- 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 ...
- PAT (Advanced Level) 1102. Invert a Binary Tree (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1098. Insertion or Heap Sort (25)
简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...
- PAT (Advanced Level) 1067. Sort with Swap(0,*) (25)
只对没有归位的数进行交换. 分两种情况: 如果0在最前面,那么随便拿一个没有归位的数和0交换位置. 如果0不在最前面,那么必然可以归位一个数字,将那个数字归位. 这样模拟一下即可. #include& ...
- PAT (Advanced Level) 1066. Root of AVL Tree (25)
AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<c ...
- PAT (Advanced Level) 1055. The World's Richest (25)
排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<alg ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1002. A+B for Polynomials (25)
为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...
随机推荐
- 杨辉三角python的最佳实现方式,牛的不能再牛了
def triangles(): N = [1] while True: yield N N.append(0) N = [N[i-1] + N[i] for i in range(len(N))] ...
- Selenium私房菜系列2 -- XPath的使用【ZZ】
在编写Selenium案例时,少不免是要用到XPath的,现在外面关于XPath使用的参考资料很多,下面我直接转一篇关于XPath使用的文档.如果对XPath不熟悉请参考下文,你不需要去百度/Goog ...
- socket是什么?协议栈操作的抽象
http://www.cnblogs.com/airtcp/p/5230161.html TCP/IP只是一个协议栈,就像操作系统的运行机制一样,必须要具体实现,同时还要提供对外的操作接口.就像操作系 ...
- vue >>> 编译失败问题 loader 待解决( iview vue脚手架生成)
vue >>> 编译失败问题 loader 待解决 用vue iview 脚手架 来一次试试~
- 关于sigleton模式
单例模式的要点有三个:一是某个类只能有一个实例:二是它必须自行创建这个实例:三是它必须自行向整个系统提供这个实例. 从具体实现角度来说,就是以下三点:一是单例模式的类只提供私有的构造函数,二是类定义中 ...
- 关于mysql服务突然运行不了的问题-“本地计算机上的mysql服务启动后停止,某些...”
1.将mysql数据库的安装目录bin文件路径添加到环境的path中,为了让cmd可以直接输入下面的相关命令,不然cd到mysql的bin下也可以 2.cmd输入mysqld --initialize ...
- SQL Prompt 格式化SQL会自动插入分号的问题
一.问题 安装新版SQL Prompt,格式化SQL都会自动在SQL末端插入分号 格式化前 格式化后 二.解决方法 选择SQL Prompt下的Options... 选择左侧的Format下Style ...
- 2018美赛准备之路——Matlab基础——命令行功能函数
clc 清屏(只清除显示内容) clear 清除所有变量(运算结果) who 显示workspace的所有变量 whos 详细显示workspace的所有变量 help sin 显示sin函数 ...
- 不同子系统采用不同MySQL编码LATIN1和UTF8的兼容
程序处理 这是一个历史遗留系统, 旧的系统是C++开发的, 插入数据的时候, 没有统一MYSQL各个层次(服务器, 数据库, 表, 列)的编码, 这个情况基本上是MYSQL的默认安装导致的, 实际的数 ...
- svn基本使用详情
1.增加(Add)先提到变更列表中,再commit到配置库中,选择新增文件,右键SVN菜单执行“Add“操作提交到”变更列表中”,然后右键SVN菜单执行”SVNCommit”提交到版本库中. 2.删除 ...