2017 ACM-ICPC 亚洲区(乌鲁木齐赛区) A. Banana

原创 2017年09月09日 14:13:21
/*
	本题收获:
	1. map<int, vector<int> > 的插入
	格式如下:
	typedef map<vector<string>,int>  mymap;  
	mymap m; 
	m.insert(pair<vector<string>,int>(vs,100)); //pair<vector<string>,int>可简写为 make_pair
	
	有关博客:
	http://blog.csdn.net/jiejinquanil/article/details/51204974
	
	2. vector的排序和去重
	去重之前需要先排序!因为unique和erase一起用的作用,仅仅是删除相邻的重复元素,所以必须先进行排序
	
	核心代码:
	vector<int>v;
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	
	------------------------------------------
	同时,之前学过的坐标离散化,也用到了vector的排序和去重
	http://blog.csdn.net/mofushaohua_ln/article/details/77795409
	
*/


A. Banana


/*
	题目链接:https://www.jisuanke.com/contest/870/43626
  	2017 ACM-ICPC 亚洲区(乌鲁木齐赛区) A. Banana
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 xx should 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 <map>
#include <vector>
#include <algorithm>
using namespace std;
map<int, vector<int> > banana; // key: number of monkeys, value: type of bananas;
map<int, vector<int> > location; // key: type of bananas; value: location of bananas;


int main()
{
	int t, n, m, x, y;
	cin >> t;
	while (t--)
	{
		banana.clear();
		location.clear();
		cin >> n >> m;
		for (int i = 0; i < n; i++)
		{
			cin >> x >> y;
			if (banana.count(x) == 0)
			{
				vector<int> tp;
				tp.push_back(y);
				banana.insert(make_pair(x, tp));
			}
			else
			{
				vector<int> tp = banana[x];
				tp.push_back(y);
				banana[x] = tp;
			}			
		}
		
		for (int i = 0; i < m; i++)
		{
			cin >> x >> y;
			if (location.count(x) == 0)
			{
				vector<int> tp;
				tp.push_back(y);
				location.insert(make_pair(x, tp));
			}
			else
			{
				vector<int> tp = location[x];
				tp.push_back(y);
				location[x] = tp;
			}
		}
		
	
		for (int i = 1; i <= n; i++)
		{
			vector<int>v;
			for (int j = 0; j < banana[i].size(); j++)
			{
				int tp = banana[i][j];
				if (location.count(tp) != 0)
				{
					vector<int> a = location[tp];
					for (int ii = 0; ii < a.size(); ii++)
					v.push_back(a[ii]);
										
				}
			}
			sort(v.begin(), v.end());
			v.erase(unique(v.begin(), v.end()), v.end());
			for (int k = 0; k < v.size(); k++)
					cout << i << " " << v[k] << endl;
		}
		cout << endl;
		
	}
}


版权声明:欢迎大家转载,转载请注明出处: ( http://blog.csdn.net/mofushaohua_ln )

17西安网络赛 规律题 Maximum Flow

https://nanti.jisuanke.com/t/17118在第一组中,只有一个2; 第二组中,每2个数出现一个5; 第三组中,每2个数出现一个5,每4个数出现一个17; 第四组中...

Out-out-control cars

新疆网络赛的几何题,当时没做出来,分别将两个三角形看成不动,只有一个三角形在动,那么问题就转变为求一个射线与线段是否有交点,我们可以在求两条直线交点的基础上再做处理: 1.要求交点在线段范围内(横纵...

2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 HDU 6206 1001 Apple(三角形外接圆圆心和半径)

题意:给你三个点,保证不再同一条直线上,再给你一点,问你是否在这三个点形成的圆外。 思路:就是求出三个点外接圆的圆心和半径判断下。精度问题需要用Java大数。 已知三点坐标,求外接圆圆心坐标与半径...
  • CillyB
  • CillyB
  • 2017年09月17日 18:12
  • 1178

2017 ACM-ICPC 亚洲区(西安赛区)网络赛 Xor

题意: 给出树的u,v节点询问每隔K个取一个数字异或。 思路: 是卡过去的。。竟然没TLE。 找U点和V点的LCA,之后从U点先向上用ST算法找到第K个祖先,依次类推。 之后再V点再重新处理向上找。注...

2014ACM/ICPC亚洲区鞍山赛区现场赛 题解

【题目链接】http://acm.hdu.edu.cn/search.php?field=problem&key=2014+Asia+AnShan+Regional+Contest&source=1&...

hdu 5512 (Pagodas) 2015 ACM/ICPC 亚洲区沈阳赛区 (题目编号1004)

Problem Description n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and th...
  • kavu1
  • kavu1
  • 2015年10月31日 21:32
  • 1629

2014ACM/ICPC亚洲区鞍山赛区现场赛D Galaxy(hdu 5073)

Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total...

2014ACM/ICPC亚洲区鞍山赛区现场赛题解报告

2014ACM/ICPC亚洲区鞍山赛区现场赛题解报告

2017ACM/ICPC亚洲区沈阳站

A.BBP Formula 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6217 开始不太会啊?后来看了看dalao的博客,发现,这个给的公式很奇...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:2017 ACM-ICPC 亚洲区(乌鲁木齐赛区) A. Banana
举报原因:
原因补充:

(最多只允许输入30个字)