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 ...
随机推荐
- wordcount(C语言)
写在前面 上传的作业代码与测试代码放在GitHub上了 https://github.com/IHHHH/gitforwork 本次作业用的是C语言来完成,因为个人能力与时间关系,只完成了基本功能,扩 ...
- php 安装yaf扩展和yaf框架
一.安装yaf扩展(windows安装) 1.查看你电脑安装的开发环境(phpinfo()的信息),查找 "Zend Extension Build"和"PHP Exte ...
- Windows上安装zabbix客户端
1.下载解压 https://www.zabbix.com/downloads/3.4.0/zabbix_agents_3.4.0.win.zip conf目录下放有agent配置文件 bin目录下有 ...
- MapReduce分析流量汇总
一.MapReduce编程规范 一.MapReduce编程规范 用户编写mr程序主要分为三个部分:Mapper,Reducer,Driver 1.Mapper阶段 (1)用户自定义Mapper类 要继 ...
- redisTemplate写哈希表遇到的坑
本文系原创,如有转载,请注明出处 在使用spring的redisTemplate进行redis哈希表的相关操作时,遇到了下面比较奇怪的情况: 1.删掉哈希表所属的key之后,重新get这个key的值, ...
- Ubuntu安装Python3 和卸载
Python2中文的解决 在py文件第一行添加 #coding=utf-8 1 规范的应该这么写 #-*- coding:utf-8 -*- 1 安装python 系统默认安装Python2 安装Py ...
- explain(desc)命令的使用
获取 type:查询类型 1.可以判断出,全表扫描还是索引扫描(ALL就是全表扫描,其他就是索引扫描) 2.对于索引扫描来讲,可以西划分,可以判断是哪一种扫描 type的具体类型介绍: ALL:全表扫 ...
- Newman语法参数
npm install -g newman npm install -g newman-reporter-html newman run XXX.json -k -r html --reporter- ...
- 产品固件(系统)升级——curl/wget
1.文件下载指令应用 支持断点续传 curl -C - -O "https://curl.haxx.se/download/archeology/curl-7.58.0.tar.gz&quo ...
- vim文本编辑操作
文本选择操作 为了方便地选取文本块,Vim编辑器引入了可视模式(Visual Mode).要选取一段文本块,操作步骤如下: ▶ 将光标移动到要复制文本块的开始处.要注意的是 ...