题目地址: 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. JS MD5

    1 /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as ...

  2. Eclipse里面代码上下文变量点击后不一起变色

    使用eclipse的时候,点击变量发现该类里面的变量颜色不变,经百度得知这个功能没有打开,下面打开方法: 1.使用“Alt+Shift+O”对该提示功能的开/关切换2.可以在以下设置选中后的文本提示颜 ...

  3. file_get_contents模仿浏览器头(user_agent)获取数据

    本篇文章是对file_get_contents模仿浏览器头(user_agent)获取数据进行了详细的分析介绍,需要的朋友参考下     什么是user agentUser Agent中文名为用户代理 ...

  4. UDP模式聊天

    //client (前台) import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAd ...

  5. AC日记——组合数问题 落谷 P2822 noip2016day2T1

    题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...

  6. AC日记——将字符串中的小写字母换成大写字母 openjudge 1.7 13

    13:将字符串中的小写字母转换成大写字母 总时间限制:  1000ms 内存限制:  65536kB 描述 给定一个字符串,将其中所有的小写字母转换成大写字母. 输入 输入一行,包含一个字符串(长度不 ...

  7. Application中的路径

    前提条件 项目工程目录:E:/Work/cosmosbox/cb-client/ 我电脑当前的用户名:qingqing PersistentDataPath Application.persisten ...

  8. 渗透攻防工具篇-后渗透阶段的Meterpreter

    作者:坏蛋链接:https://zhuanlan.zhihu.com/p/23677530来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 前言 熟悉Metasploit ...

  9. NOIP模拟赛 隔壁

    问题描述: 隔壁学校地形图可以通过一个高度矩阵表示,矩阵中每一个位置都有一个数0<=hij<=10^5表示这个坐标的海拔,我们姑且将其称为海拔图,容易发现,我们可以通过这个矩阵轻松算出隔壁 ...

  10. hashmap先按照value从大到小排序,value相等时按照key从小到大排序

    hashmap先按照value从大到小排序,value相等时按照key从小到大排序. [2]是从小到大排序,在[2]代码基础上交换o1,o2位置即可. 代码中用到[1]中提到的在value相等时再比较 ...