poj-1314 Finding Rectangles
题目地址: http://poj.org/problem?id=1314
题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出。
因为这道题的用处很大, 最近接触的cv 中的Rectangle Detection 中就有方法使用到了这个算法。 但实际中使用的算法还是暴力。
不过因为数据点较少,可以直接快排之后,再来个迭代,就得到答案了
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 30; struct Node{
string label;
int x,y;
}nd[maxn]; int n; int cmp(const void *a, const void *b){
Node* aa = (Node *)a;
Node* bb = (Node *)b;
if(aa->x == bb->x){
return aa->y - bb->y;
}else{
return aa->x - bb->x;
}
} int main(){
freopen("in.txt", "r", stdin); int i,j,k, l, cnt = 1;
char word[4];
while( cin>>n && n!=0){
for(i=0; i<n; i++){
cin>>nd[i].label>>nd[i].x>>nd[i].y;
}
qsort(nd, n, sizeof(nd[0]), cmp);
vector<string> vt;
for(i=0; i<n; i++){
for(j=i+1; j<n && nd[j].x == nd[i].x; j++){
for(k=j+1; k<n; k++){
if(nd[k].y == nd[i].y){
for(l=k+1; l<n && nd[l].x == nd[k].x; l++){
if(nd[l].y == nd[j].y){
string tmp = "";
tmp += nd[j].label; tmp += nd[l].label;
tmp += nd[k].label; tmp += nd[i].label;
vt.push_back(tmp);
}
}
}
}
}
}
if(vt.size() == 0){
printf("Point set %d: No rectangles\n", cnt++);
}else{
printf("Point set %d:\n", cnt++);
sort(vt.begin(), vt.end());
for(i=0; i<vt.size(); i++){
if((i+1)%10 == 0){
cout<<" "<<vt[i]<<endl;
}else{
cout<<" "<<vt[i];
}
}
if(i%10 != 0){
printf("\n");
}
}
}
return 0;
}
poj-1314 Finding Rectangles的更多相关文章
- POJ 2049— Finding Nemo(三维BFS)10/200
		版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ... 
- poj 3376 Finding Palindromes
		Finding Palindromes http://poj.org/problem?id=3376 Time Limit: 10000MS Memory Limit: 262144K ... 
- poj 2049 Finding Nemo(优先队列+bfs)
		题目:http://poj.org/problem?id=2049 题意: 有一个迷宫,在迷宫中有墙与门 有m道墙,每一道墙表示为(x,y,d,t)x,y表示墙的起始坐标d为0即向右t个单位,都是墙d ... 
- POJ 2049 Finding Nemo  bfs  建图很难。。
		Finding Nemo Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 6952 Accepted: 1584 Desc ... 
- POJ 2049 Finding Nemo
		Finding Nemo Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 8631 Accepted: 2019 Desc ... 
- POJ 3376 Finding Palindromes(扩展kmp+trie)
		题目链接:http://poj.org/problem?id=3376 题意:给你n个字符串m1.m2.m3...mn 求S = mimj(1=<i,j<=n)是回文串的数量 思路:我们考 ... 
- POJ 3376 Finding Palindromes(manacher求前后缀回文串+trie)
		题目链接:http://poj.org/problem?id=3376 题目大意:给你n个字符串,这n个字符串可以两两组合形成n*n个字符串,求这些字符串中有几个是回文串. 解题思路:思路参考了这里: ... 
- POJ 3376 Finding Palindromes EX-KMP+字典树
		题意: 给你n个串串,每个串串可以选择和n个字符串拼接(可以自己和自己拼接),问有多少个拼接后的字符串是回文. 所有的串串长度不超过2e6: 题解: 这题由于是在POJ上,所以string也用不了,会 ... 
- POJ - 3376 Finding Palindromes(拓展kmp+trie)
		传送门:POJ - 3376 题意:给你n个字符串,两两结合,问有多少个是回文的: 题解:这个题真的恶心,我直接经历了5种错误类型 : ) ... 因为卡内存,所以又把字典树改成了指针版本的. 字符串 ... 
随机推荐
- 理解linux and inode
			inode是一个重要概念,是理解Unix/Linux文件系统和硬盘储存的基础. 我觉得,理解inode,不仅有助于提高系统操作水平,还有助于体会Unix设计哲学,即如何把底层的复杂性抽象成一个简单概念 ... 
- 009.CentOS 6.7安装运行netmap
			一.netmap简介: 1.netmap是一个高性能收发原始数据包的框架,由Luigi Rizzo等人开发完成,其包含了内核模块以及用户态库函数.其目标是,不修改现有操作系统软件以及不需要特殊硬件支持 ... 
- cookie和session详解
			cookie和session的区别 二者的定义: 当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cookie 会帮你在网站上所打的文字或是一些选择,都纪录下来.当下次你再光临同 ... 
- Linux aclocal
			一.简介 二.安装 三.常用指令 1)安装m4 aclocal -I m4 2)查看aclocal的路径 aclocal --print-ac-dir 四.常见问题 1) LIBTOOL is und ... 
- ARM学习篇一             点亮LED
			要点亮LED,先决条件是什么,当然得有相应的硬件设施.板子的整个电路图比较大,我就直接取相关部分. 给发光二级管加上3.3v电压后,通过1k电阻,直接与S3C2440连接.至于为什么要加电阻,大家应该 ... 
- Unity4.3 bug GetChild顺序错乱
			历史原因,目前有个项目还在使用unity4.3版本,比较过不同Unity版本,发现unity4.3的 transform.GetChild 获取的child顺序并不是想要的. 测试代码 using U ... 
- json注入
- 给ros安装arbotix simulator仿真环境
			首先下载程序包.编译.安装. cd ~/catkin_ws/src git clone https://github.com/pirobot/rbx1.git cd rbx1 git checkout ... 
- linux安装jdk 不成功,找不到版本问题
			http://www.linuxidc.com/Linux/2015-01/112030.htm 配置文件 export JAVA_HOMEexport JRE_HOMEexport CLASSPAT ... 
- http协议(九)响应首部字段
			响应首部字段: 服务器向客户端返回响应报文中所使用的字段,用于补充的附加信息.服务器信息.以及对客户端的附加要求等 1.Accept-Ranges 告知客户端服务器能否处理范围请求,以指定获取服务器的 ... 
