poj 3349(重载比较操作符+排序)

来源:互联网 发布:淘宝网男士时尚毛线衣 编辑:程序博客网 时间:2024/04/29 07:45
SnowflakeSnowSnowflakes
Time Limit: 4000MS Memory Limit: 65536KTotal Submissions: 27955 Accepted: 7393

Description

You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.

Input

The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed byn lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.

Output

If all of the snowflakes are distinct, your program should print the message:
No two snowflakes are alike.
If there is a pair of possibly identical snow akes, your program should print the message:
Twin snowflakes found.

Sample Input

21 2 3 4 5 64 3 2 1 6 5

Sample Output

Twin snowflakes found.

Source

CCC 2007

刚开始用set存储每一个雪片。结果tle了。。。
直接用数组存放,然后排序,排序后只需要与相邻元素比对就可以判断是否存在相同雪花。
这里的技巧是,对6个雪片进行预处理:从最大的角开始,顺时针来一遍,逆时针来一遍,获得两个序列。然后选择“值”较大的那个序列放入数组。这里直接重载了<操作符和==操作符。
这样保证了数组中的元素不会超过100000。

提交记录:
1.TLE, 使用set失败。。。
2.Accepted。使用数组,然后排序。

使用set后超时的代码:

AC的代码:


原创粉丝点击