题目地址: 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. [转载]python脚本删除一定时间以外的文件

    import os; import sys; import time; class DeleteLog: def __init__(self,filename,days): self.filename ...

  2. oops call trace 解析

    Call Trace: [  221.634988]  [<ffffffff8103fbc7>] ? kmld_pte_lookup+0x17/0x60 [  221.635016]  [ ...

  3. C++/C#互调步骤

    一.C#调用C++ dll步骤(只能导出方法):  * 1. c++建立空项目->源文件文件夹中添加cpp文件和函数  * 2. c++属性设置中,配置类型设置为动态库dll,公共语言运行时支持 ...

  4. [转]AngularJS fixed header scrollable table directive

    本文转自:http://pointblankdevelopment.com.au/blog/angularjs-fixed-header-scrollable-table-directive This ...

  5. ARM学习篇 中断定时理解

    1. 中断控制器 a. 中断处理流程 P1--摘自S3C2440A手册 P1简要阐述了S3C2440A内置中断控制器处理中断的流程: ●​若某中断有自中断,则先接收子中断请求,否则,直接接受源中断. ...

  6. JustWeEngine - 轻量级游戏框架

    JustWeEngine - 轻量级游戏框架 An easy open source Android game engine. Github地址 引擎核心类流程图 使用方法 引入Engine作为Lib ...

  7. 在嵌入式开发板中运行程序提示-/bin/sh: ./xx: not found的解决办法

    今天拿着我的tiny6410板子,在虚拟机上用 $arm-linux-gcc he.c -o he 编译后放到tiny6410的文件系统中提示 -/bin/sh: ./xx: not found 后来 ...

  8. [No00004D]深度思考好文:软件工程师的困境

    昨天是我一同学结婚的好日子,同学们大家聊各自的工作,有个同学突然问了我一句:我们同学中好像做软件的不多?如果再细分,好像做网络相关的更少? 回想起当时为何读计算机信息管理的专业,是因为那时听说读电脑未 ...

  9. ArrayList的线程安全测试

    public class TestThread implements Runnable{ private List list; CountDownLatch cdl; public TestThrea ...

  10. java 22 - 22 多线程之 匿名内部类的方式实现多线程

    首先回顾下之前的匿名内部类: 匿名内部类的格式: new 接口或者接口名(){ 重写方法 }; 本质:是该类或者接口的子类对象 匿名内部类方式使用多线程 1.new Thread(){代码-}.sta ...