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


}


}

相关文章
|
机器学习/深度学习 人工智能 Java
新手入门 acm 输入输出练习
A + B Problem(1000) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 355051    Accept...
24409 2
|
1天前
|
数据采集 人工智能 安全
|
10天前
|
云安全 监控 安全
|
2天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
932 150
|
2天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话
|
16天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1662 8
|
7天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
616 152
|
9天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
586 15