【stl学习笔记】set的使用方法指南

编程入门 行业动态 更新时间:2024-10-11 17:25:55

【stl学习笔记】set的<a href=https://www.elefans.com/category/jswz/34/1769874.html style=使用方法指南"/>

【stl学习笔记】set的使用方法指南

周作人有曰:“人类的最大弱点之一是自命不凡的幻想。”

一、定义:(其实就是排序的小结)所以直接上例题吧!

二、例题:

1.Qualifying Contest:

Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.

The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.

Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2m) — the number of participants of the qualifying contest and the number of regions in Berland.

Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).

It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.

Output

Print m lines. On the i-th line print the team of the i-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.

Examples

Input

5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503

Output

Sidorov Ivanov
Andreev Semenov

Input

5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503

Output

?
Andreev Semenov

Note

In the first sample region teams are uniquely determined.

In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.

(1)解题思路:用sort函数对结构体里元素进行排序,然后用数组找出前分数最大的个数是否只有两个,得出结果输出。

(2)AC代码:

#include <iostream>
#include<algorithm>using namespace std;struct spoter
{char name[15];int num;int score;
}sp[110000];
struct number
{int a[1000];
}st[11000];bool cmp(spoter a,spoter b)
{if(a.num==b.num) return a.score>b.score;else     return a.num<b.num;
}//重点int main()
{long long int i,n,j;int m;scanf("%lld%d",&n,&m);for(i=0;i<n;++i){scanf("%s",sp[i].name);scanf("%d",&sp[i].num);scanf("%d",&sp[i].score);}sort(sp,sp+n,cmp);//重点for(i=0;i<n;++i){st[sp[i].num].a[sp[i].score]++;}for(i=1;i<=m;++i){for(j=0;j<n;++j){if(i!=sp[j].num) continue;if(st[i].a[sp[j].score]==2) {cout<<sp[j].name<<' '<<sp[j+1].name<<endl;break;}else if(st[i].a[sp[j].score]==1&&st[i].a[sp[j+1].score]==1) {cout<<sp[j].name<<' '<<sp[j+1].name<<endl;break;}else {cout<<'?'<<endl;break;}}}return 0;
}

2.Sabotage

It is the seventh year of the terrible harmful Galaxy War... Leo Hao is one of the first defenders of his planet. He is lucky! He has gone through many troubles. For example, he stayed alive after the close combat with a meklon warrior – a perfect killing machine. He lost his left leg, right eye and spent five long months in hospital. After that incident, he had to leave the army and return to the Earth.

But Leo is lucky twice! He was able to find a good job after all these terrible incidents. Now he is a leading programmer in “U.S. Robots”. He was involved into the creation of software for zero level defense system. However, even there he was faced with interplanetary intervention! Just a few days ago it was found out that one of his co-workers is not a human! No! Physically he was a human of course, but parasitical Darloxian – agent of the most odious race in the Galaxy, captured his mind.

Obviously, mind corrupted by Darlok agent was not able to write high-quality code. That why Leo is now reviewing his code. It’s terrible!!! It is not effective, slow, dirty and tangled. It must be rewritten!

However, Leo faced trouble during the exploration of the following function: input is the array of positive integer numbers. First, function prints quantity of numbers in the array onto a sheet of paper. Then quantity of numbers in the array greater than 1 is printed. Then quantity of numbers greater than 2 and so on, until the function encounters zero (zero is never printed out). After that, special mechanical manipulator puts this sheet of paper into scanner, which reads this set of numbers into memory and the described operation repeats again. After that the new paper with numbers comes out from the printer. The scanner reads these new numbers, and stores them into the array. This array is the result of the function.

Example. 

Input: 4 1 6. 
After first stage printer prints 3 2 2 2 1 1 
After second stage the result of the function will be 6 4 1

Leo feels that it can be done more effectively. Your goal is to write a program, which will be able to replace the function written by Darlok agent, and will be much faster.

Input

First line of input contains the number N (0 ≤ N ≤ 25000). The next N lines contain integers pi (1 ≤ pi ≤ 25000) one per line. It is the input for the described function.

Output

Output should contain the result of the function, written by Darlok Agent.

Example

 

input

output
3
4
1
6
6
4
1
解题思路:( 最小割最大流定理 )

最小割,就是在所有割中,容量之和最小的割,最小割的值即最大流的值,因为从源点s到汇点t的最大流必然会经过割边,那么就有最大流f<=c(割边的值),即当c=f的时候,就是c为小割,即最大流=最小割

之后,残余网络会分成两个部分,和源点相连的是一个集合,和汇点相连的是另一个集合,然后用a表示从源点到其他各点的最大流,在求出最大流之后,a>0 的就在源点集合中,反之为0的就在汇点集合中

割:设Ci为网络N中一些弧的集合,若从N中删去Ci中的所有弧能使得从源点Vs到汇点Vt的路集为空集时,称Ci为Vs和Vt间的一个割。通俗理解,一个图或网络的割,表示一个切面或切线,将图或网络分为分别包含源点和汇点的两个子集,该切线或切面与网络相交的楞或边的集合,称为图像的割。(选自  )
AC代码:

更多推荐

【stl学习笔记】set的使用方法指南

本文发布于:2024-02-24 14:27:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1695610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:使用方法   学习笔记   指南   stl   set

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!