程序与技术分享: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;


}


}

相关文章
|
25天前
|
存储 安全 测试技术
阿里云轻量应用服务器38元与云服务器99元和199元性能、适用场景区别及选择参考
2026年,阿里云推出的三款入门级云服务器,38元轻量应用服务器、99元经济型e实例及199元通用算力型u1实例,凭借卓越性能和亲民价格,满足个人开发者、小型网站及中小企业的多元需求。轻量服务器以200M峰值带宽和一键部署功能,成为快速建站首选;经济型e实例通过99元续费同价和灵活配置,平衡成本与性能;u1实例则以独享算力和5M固定带宽,为小微企业正式业务提供稳定支撑。本文通过详细对比和测评,助力用户根据实际需求选择最优方案,实现低成本高效上云。
|
3月前
|
JavaScript 前端开发 API
Vue3 从入门到实战
Vue3 从入门到实战,涵盖组合式 API、响应式数据、组件化开发与生命周期等核心内容。提供可直接运行的代码示例,零基础快速上手,助力高效构建现代化前端应用。
|
27天前
|
数据采集 人工智能 监控
大模型微调完全指南:从“通用学霸”到“领域专家”的进化之路
本文是大模型微调的实战指南,详解P-Tuning、LoRA与QLoRA三大轻量化方法原理及应用,覆盖目标定义、数据准备、环境搭建、参数调优、效果评估到部署上线全流程,助你将通用大模型高效定制为懂业务、说行话、可落地的领域专家。(239字)
Elasticsearch【问题记录 02】【不能以root运行es + max virtual memory areas vm.max_map_count [65530] is too low处理】
【4月更文挑战第12天】Elasticsearch【问题记录 02】【不能以root运行es + max virtual memory areas vm.max_map_count [65530] is too low处理】
360 3
|
存储 编解码 监控
NAS设备推荐品牌?
【6月更文挑战第30天】NAS设备推荐品牌?
1091 60
|
安全 Java Android开发
探索安卓应用开发中的Kotlin语言优势
【7月更文挑战第8天】 在安卓开发的广阔天地中,Kotlin以其优雅的语法、现代化的特性和高效的性能成为了开发者的新宠。本文将深入探讨Kotlin在安卓应用开发中所展现的独特魅力,从语言特性到实际应用案例,揭示其如何简化代码编写、提升开发效率,并增强应用性能。通过对比分析,我们将一同见证Kotlin如何在众多编程语言中脱颖而出,成为安卓开发领域的一股清新之风。
531 11
|
机器学习/深度学习 数据采集 人工智能
Python的应用场景
【7月更文挑战第7天】
2776 3
|
机器学习/深度学习 人工智能
论文介绍:AI击败最先进全球洪水预警系统,提前7天预测河流洪水
【5月更文挑战第4天】研究人员开发的AI模型(基于LSTM网络)成功击败全球最先进的洪水预警系统,能在未设测站流域提前7天预测洪水,显著提升预警时间,降低灾害影响。该模型使用公开数据集,减少了对长期观测数据的依赖,降低了预警系统的成本,有望帮助资源有限的地区。然而,模型的性能可能受特定流域条件影响,泛化能力和预测解释性仍有待改进。[论文链接](https://www.nature.com/articles/s41586-024-07145-1)
580 11
|
机器学习/深度学习 存储 测试技术
2024年 最火的Python学习路线
2024年 最火的Python学习路线
443 0

热门文章

最新文章