2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-A banana·
2017-09-09 16:41:28
writer:pprp
题意很好理解就不说了,实现比较清晰,选择邻接表来做
但是我用的是链表来实现的,所以导致出现了很多问题,最后卡的最长时间的一个问题是
应该从1开始而不是从0开始,读题应该自习一点;
题目如下:
Bananas are the favoured food of monkeys.
In the forest, there is a Banana Company that provides bananas from different places.
The company has two lists.
The first list records the types of bananas preferred by different monkeys, and the second one records the types of bananas from different places.
Now, the supplier wants to know, whether a monkey can accept at least one type of bananas from a place.
Remenber that, there could be more than one types of bananas from a place, and there also could be more than one types of bananas of a monkey's preference.
Input Format
The first line contains an integer TT, indicating that there are TT test cases.
For each test case, the first line contains two integers NN and MM, representing the length of the first and the second lists respectively.
In the each line of following NN lines, two positive integers i, ji,j indicate that the ii-th monkey favours the jj-th type of banana.
In the each line of following MM lines, two positive integers j, kj,k indicate that the jj-th type of banana could be find in the kk-th place.
All integers of the input are less than or equal to 5050.
Output Format
For each test case, output all the pairs x, yx,y that the xx-the monkey can accept at least one type of bananas from the yy-th place.
These pairs should be outputted as ascending order. That is say that a pair of x, yx,y which owns a smaller xxshould be output first.
If two pairs own the same xx, output the one who has a smaller yy first.
And there should be an empty line after each test case.
样例输入
1
6 4
1 1
1 2
2 1
2 3
3 3
4 1
1 1
1 3
2 2
3 3
样例输出
1 1
1 2
1 3
2 1
2 3
3 3
4 1
4 3
代码如下;
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
const int maxn = ;
int N, M; struct node
{
int val;
node * next;
}; node* head1[maxn];
node* head2[maxn]; bool ans[maxn][maxn]; void create()
{
memset(ans,,sizeof(ans));
for(int i = ; i < maxn ; i++)
head1[i] = NULL,head2[i] = NULL;
int st, ed;
for(int i = ; i <= N ; i++)
{
cin >> st >> ed;
node *tmp = new node();
tmp->next = NULL;
if(head1[st] == NULL)
{
head1[st] = tmp;
tmp->val = ed;
}
else
{
node * p = head1[st];
while(p->next != NULL)
p = p->next;
p->next = tmp;
tmp->val = ed;
}
}
for(int i = ; i <= M ; i++)
{
cin >> st >> ed;
node * tmp = new node();
tmp->next = NULL;
if(head2[st] == NULL)
{
head2[st] = tmp;
tmp->val = ed;
}
else
{
node * p = head2[st];
while(p->next != NULL)
{
p = p->next;
}
p->next = tmp;
tmp->val = ed;
}
}
} void fun()
{
node * p, * q;
int rec_st, rec_ed;
for(int i = ; i <= N ; i++)
{
p = head1[i];
while(p != NULL)
{
rec_st = p->val;
q = head2[rec_st];
while(q != NULL)
{
rec_ed = q->val;
ans[i][rec_ed] = true;
q = q->next;
}
p = p->next;
}
}
} int main()
{
//freopen("in.txt","r",stdin);
int cas;
cin >> cas;
while(cas--)
{
cin >> N >> M;
create();
fun();
for(int i = ; i < maxn ; i++)
{
for(int j = ; j < maxn ; j++)
{
if(ans[i][j] == true)
cout << i << " " << j << endl;
}
}
cout << endl;
} return ;
}
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛-A banana·的更多相关文章
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)
参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- 【2017 ACM/ICPC 乌鲁木齐赛区网络赛环境测试赛 E】蒜头君的排序
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 莫队算法+树状数组. 区间增加1或减少1. 对逆序对的影响是固定的. (用冒泡排序变成升序的交换次数,就是逆序对的个数) [错的次数] 0 [ ...
- 2017 乌鲁木齐赛区网络赛 J Our Journey of Dalian Ends 费用流
题目描述: Life is a journey, and the road we travel has twists and turns, which sometimes lead us to une ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!
鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS Memory Limit:262144KB 64bit IO Fo ...
随机推荐
- Apache Kafka源码分析 – Broker Server
1. Kafka.scala 在Kafka的main入口中startup KafkaServerStartable, 而KafkaServerStartable这是对KafkaServer的封装 1: ...
- echarts容器动态设置高度
测试提了bug,柱状图数据多的情况下,都叠到了一起,效果如下图. 要解决这个bug,首先想到的是让柱状图的容器自适应高度.于是,把原本div上写固定的高度去掉. <div id="my ...
- Tr A--hdu1575(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 算是模板吧 #include <iostream> #include <std ...
- sql server中使用xp_cmdshell
关键词:sql server开启高级配置,使用Bat,cmdshell 1.sql server中使用xp_cmdshell --允许配置高级选项 GO RECONFIGURE GO . --开启xp ...
- python学习笔记(十七)网络编程之urllib模块
如何用python打开一个网站或者请求一个接口呢,我们在这篇博客介绍一下. 首先我们得导入一个urllib模块,这个模块是python自带的标准模块,直接导入就能使用,但是用起来不方便,先看个简单的打 ...
- Spark日志级别修改
摘要 在学习使用Spark的过程中,总是想对内部运行过程作深入的了解,其中DEBUG和TRACE级别的日志可以为我们提供详细和有用的信息,那么如何进行合理设置呢,不复杂但也绝不是将一个INFO换为TR ...
- DOM简介
什么是DOM? DOM 是 Document Object Model(文档对象模型)的缩写. W3C 文档对象模型 (DOM) 是中立于平台和语言的接口,它允许程序和脚本动态地访问和更新文档的内容. ...
- TensorFlow学习笔记(六)循环神经网络
一.循环神经网络简介 循环神经网络的主要用途是处理和预测序列数据.循环神经网络刻画了一个序列当前的输出与之前信息的关系.从网络结构上,循环神经网络会记忆之前的信息,并利用之前的信息影响后面节点的输出. ...
- 在MFC中使用一个单独的类实现数据在各个类之间的传递
第一步:使用VS2010创建一个基于MFC的单文档程序,然后 编译 运行 确定没有问题. 第二步:添加一个名叫CGszCommonData 类. 第三步:在应用程序类的头文件里 添加#includ ...
- 聊一聊python的单例模式
单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ...