poj 3349(重载比较操作符+排序)
来源:互联网 发布:淘宝网男士时尚毛线衣 编辑:程序博客网 时间:2024/04/29 07:45
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
刚开始用set存储每一个雪片。结果tle了。。。
直接用数组存放,然后排序,排序后只需要与相邻元素比对就可以判断是否存在相同雪花。
这里的技巧是,对6个雪片进行预处理:从最大的角开始,顺时针来一遍,逆时针来一遍,获得两个序列。然后选择“值”较大的那个序列放入数组。这里直接重载了<操作符和==操作符。
这样保证了数组中的元素不会超过100000。
提交记录:
1.TLE, 使用set失败。。。
2.Accepted。使用数组,然后排序。
使用set后超时的代码:
AC的代码:
- poj 3349(重载比较操作符+排序)
- STL--重载操作符与qsort排序
- 比较全面的 C++ 操作符重载 (operator)
- C++ 自定义比较:仿函数、函数与重载操作符
- C++比较符重载
- ACM:一种排序(操作符重载、vector排重)
- POJ 3193 字符串排序+比较
- 重载运算符排序
- 比较运算符的重载
- 优先队列比较符重载
- c++重载操作符
- C++ 操作符重载
- 操作符重载浅析
- 操作符重载
- 10.8 操作符重载
- 操作符重载
- 操作符重载手册
- C#操作符重载
- 动态hash表一
- linux一些常用命令
- windows的MAX_PATH
- 7.磁盘基本概念
- MySQL中进行树状所有子节点的查询(MYSQL综合)
- poj 3349(重载比较操作符+排序)
- poj 3274(sum矩阵+sort)
- IT外企那点儿事(3):奇怪的面试
- 归并排序
- POJ-2892 Tunnel Warfare 树状数组
- poj 2151(概率dp)
- 黑马程序员—数据库的连接与命令操作
- poj 1840(移动几项到等式另外一边减少循环深度)
- poj 2002(全等三角形计算正方形另外两个点坐标)