题目地址: 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的更多相关文章

  1. POJ 2049— Finding Nemo(三维BFS)10/200

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...

  2. poj 3376 Finding Palindromes

    Finding Palindromes http://poj.org/problem?id=3376 Time Limit: 10000MS   Memory Limit: 262144K       ...

  3. poj 2049 Finding Nemo(优先队列+bfs)

    题目:http://poj.org/problem?id=2049 题意: 有一个迷宫,在迷宫中有墙与门 有m道墙,每一道墙表示为(x,y,d,t)x,y表示墙的起始坐标d为0即向右t个单位,都是墙d ...

  4. POJ 2049 Finding Nemo bfs 建图很难。。

    Finding Nemo Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 6952   Accepted: 1584 Desc ...

  5. POJ 2049 Finding Nemo

    Finding Nemo Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 8631   Accepted: 2019 Desc ...

  6. POJ 3376 Finding Palindromes(扩展kmp+trie)

    题目链接:http://poj.org/problem?id=3376 题意:给你n个字符串m1.m2.m3...mn 求S = mimj(1=<i,j<=n)是回文串的数量 思路:我们考 ...

  7. POJ 3376 Finding Palindromes(manacher求前后缀回文串+trie)

    题目链接:http://poj.org/problem?id=3376 题目大意:给你n个字符串,这n个字符串可以两两组合形成n*n个字符串,求这些字符串中有几个是回文串. 解题思路:思路参考了这里: ...

  8. POJ 3376 Finding Palindromes EX-KMP+字典树

    题意: 给你n个串串,每个串串可以选择和n个字符串拼接(可以自己和自己拼接),问有多少个拼接后的字符串是回文. 所有的串串长度不超过2e6: 题解: 这题由于是在POJ上,所以string也用不了,会 ...

  9. POJ - 3376 Finding Palindromes(拓展kmp+trie)

    传送门:POJ - 3376 题意:给你n个字符串,两两结合,问有多少个是回文的: 题解:这个题真的恶心,我直接经历了5种错误类型 : ) ... 因为卡内存,所以又把字典树改成了指针版本的. 字符串 ...

随机推荐

  1. linux权限补充:rwt rwT rws rwS 特殊权限

    众所周知,Linux的文件权限如: 777:666等,其实只要在相应的文件上加上UID的权限,就可以用到加权限人的身份去运行这个文件.所以我们只需要将bash复制出来到另一个地方,然后用root加上U ...

  2. Mysql中使用find_in_set函数查找字符串

    mysql有个表的字段的存储是以逗号分隔的,如domain字段login.s01.yy.com,s01.yy.com,s02.yy.com.现在要查找s01.yy.com这个.我们用like查找好像不 ...

  3. node js学习(一)

    1.简介 JavaScript是一种运行在浏览器的脚本,它简单,轻巧,易于编辑,这种脚本通常用于浏览器的前端编程,但是一位开发者Ryan有一天发现这种前端式的脚本语言可以运行在服务器上的时候,一场席卷 ...

  4. 301重定向.htaccess规则(含二级目录跳转二级域名)

    301重定向是一种非常重要的"自动转向"技术.网址重定向最为可行的一种办法.当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码 ...

  5. dedecms调用标签总结(二)

    6. 列表调用 首页: {dede:arclist row='10' titlelen='24' typeid='2' orderby='pubdate'} <li> <a href ...

  6. 探索 OpenStack 之(17):计量模块 Ceilometer 中的数据收集机制

    本文将阐述 Ceilometer 中的数据收集机制.Ceilometer 使用三种机制来收集数据: Notifications:Ceilometer 接收 OpenStack 其它服务发出的 noti ...

  7. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)(转)

    使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...

  8. 详细说说 Google Test Certified 的各级——Level 2,3

    转载请联系作者,谢谢!   No releases with red tests基于Level1搭建的持续集成,持续发布选用的CL(changelist)就可以取自CI系统最后跑通的CL,因为持续集成 ...

  9. 转载:JavaSE之反射

    该文章转载自:http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html Java反射详解 本篇文章依旧采用小例子来说明,因为我 ...

  10. TestLink学习二:Windows搭建TestLink环境

    环境准备: 搭建php5.4.39+apache2.2+mysq5.5.28l环境 (可参考http://www.cnblogs.com/yangxia-test/p/4414161.html) (注 ...