程序与技术分享:2017ACM

简介: 程序与技术分享:2017ACM

/


本题收获:


1. map 的插入


格式如下:


typedef map mymap;


mymap m;


m.insert(pair(vs,100)); //pair可简写为 make_pair


有关博客:


2. vector的排序和去重


去重之前需要先排序!因为unique和erase一起用的作用,仅仅是删除相邻的重复元素,所以必须先进行排序


核心代码:


vectorv;


sort(v.begin(), v.end());


v.erase(unique(v.begin(), v.end()), v.end());


------------------------------------------


同时,之前学过的坐标离散化,也用到了vector的排序和去重


/


A. Banana


/


题目链接:


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 //代码效果参考:http://www.lyjsj.net.cn/wz/art_22724.html

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


#include


#include


#include


using namespace std;


map banana; // key: number of monkeys, value: type of bananas;


map 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 tp;


tp.push_back(y);


banana.insert(make_pair(x, tp));


}


else


{


vector 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 tp;


tp.push_back(y);


location.insert(make_pair(x, tp));


}


else


{


vector tp = location【x】;


tp.push_back(y);


location【x】 = tp;


}


}


for (int i = 1; i <= n; i++)


{


vectorv;


for (int j = 0; j < banana【i】.size(); j++)


{


int tp = banana【i】【j】;


if (location.count(tp) != 0)


{


vector 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;


}


}

相关文章
|
弹性计算 运维 安全
阿里云最佳实践workshop实战训练营-6月场完美收官
最佳实践workshop实战训练营是基于角色扮演的场景化沉浸式实操训练,通过现场参加实训帮助客户快速掌握场景的落地技术方案,通过产品组合实战实操来帮助客户快速了解阿里云各产品及方案的优势。
阿里云最佳实践workshop实战训练营-6月场完美收官
|
7月前
|
安全 前端开发 测试技术
蚌埠住了!我把斯坦福大牛的Web安全开发指南给分享出来了!
Web应用程序的安全性至关重要,病毒、DDoS攻击、中间人攻击、安全漏洞等多种威胁无时无刻不在,任何一种安全事故都可能造成灾难性后果。无论是前端开发人员、网页设计师、用户体验设计师,还是开发运营人员、产品经理、软件工程师,都需具备一定的安全技能,承担起保障Web应用程序及其数据安全的责任。 今天给小伙伴们分享的这份手册主要分为5大部分,共 17章,详细介绍了 Web 安全开发的必备知识,涉及从最新的智能手机到老旧的台式计算机等各种设备,并且不限定平台。具体内容包括:制订安全计划,运用成功的编码实践,创建有用及高效的测试策略,实现维护周期,查找安全资源。
|
Java C语言 C++
ACM刷题之路(二)谈谈我对ACM的理解
ACM刷题之路(二)谈谈我对ACM的理解
137 0
ACM刷题之路(十六)Acm程序设计竞赛自制模板(一)
ACM刷题之路(十六)Acm程序设计竞赛自制模板
|
算法
ACM刷题之路(十六)Acm程序设计竞赛自制模板(二)
ACM刷题之路(十六)Acm程序设计竞赛自制模板
101 0
|
Java Android开发
ACM刷题之路(七)字符串处理 记元培ACM院赛
ACM刷题之路(七)字符串处理 记元培ACM院赛
112 0
|
前端开发 数据可视化 架构师
Oasis 开源一周年沙龙来啦,2月26日,直播间不见不散!
Oasis 开源一周年沙龙来啦,2月26日,直播间不见不散!
162 0
|
机器学习/深度学习 搜索推荐 知识图谱
独家下载!《SIGIR 顶会论文解读》电子书重磅发布
高端玩家看过来!阿里云开发者社区联合新零售智能引擎事业群独家推出顶会论文解读系列电子书,本期为《SIGIR 顶会论文解读》,由 7 位阿里巴巴技术专家精心打造,深度解析信息检索新技术,助你了解行业动态,紧跟技术潮流!
13721 0
独家下载!《SIGIR 顶会论文解读》电子书重磅发布
|
算法 .NET 开发框架
|
机器学习/深度学习 人工智能 自然语言处理
AAAI 2020 阿里精选论文抢先看
人工智能领域顶会AAAI 2020刚刚在美国纽约落下帷幕。本届大会,阿里巴巴经济体共60余篇论文被大会收录,同学们以视频和海报的形式远程参与,与全世界同行分享了最新的技术进展。这里小编为你精心挑选了阿里巴巴入选的oral paper Spotlight paper 以及 最佳人工智创新应用奖获奖论文,足不出户,你也能了解阿里巴巴AI技术研究的一线干货。
2402 0