九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707

求所有可能围成的正方形,借个代码

#include <queue>
#include <vector>
#include <stack>
#include <string>
#include <cstdio>
#include <math.h>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define FRE freopen("c:\\users\\nitlian\\desktop\\input.txt","r",stdin)
#define FF freopen("c:\\users\\nitlian\\desktop\\output.txt", "w", stdout)
#define N 5100
#define M 1148576
#define inf 1000000000 struct node {
int a, b, c, d;
void set (int _a, int _b, int _c, int _d) {
a = _a; b = _b; c = _c; d = _d;
}
}pe[N];
struct point {
int x, y;
void set () {
scanf ("%d%d", &x, &y);
}
}p[30];
int cnt;
int cmp (point a, point b) {
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
int dp[M];
int dfs (int s) {
if (dp[s] != -1) return dp[s];
int Max = 0;
for (int i = 0; i < cnt; ++i) {
if ((s&(1<<pe[i].a)) + (s&(1<<pe[i].b))+(s&(1<<pe[i].c)) + (s&(1<<pe[i].d)) == 0) {
int si = s + (1<<pe[i].a) + (1<<pe[i].b) + (1<<pe[i].c) + (1<<pe[i].d);
Max = max (Max, dfs (si) + 4);
}
}
return dp[s]= Max;
}
int main () {
int n;
while (scanf ("%d", &n), n != -1) {
for (int i = 0; i < n; ++i) {
p[i].set();
}
cnt = 0;
sort (p, p + n, cmp);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (p[i].x != p[j].x) break;
for (int ii = j + 1; ii < n; ++ii) {
for (int jj = ii + 1; jj < n; ++jj) {
if (p[ii].x != p[jj].x) continue;
if (p[i].y == p[ii].y && p[j].y == p[jj].y && p[j].y - p[i].y == p[ii].x - p[i].x) {
pe[cnt].set (i, j, ii, jj);
// cout << i << ' ' << j << ' ' << ii << ' ' << jj << endl;
cnt++;
}
}
}
}
}
memset (dp, -1, sizeof (dp));
printf ("%d\n", dfs (0));
}
}

HDU 4739 求正方形个数的更多相关文章

  1. m*n 矩阵中求正方形个数

    <?php /** * Notes: * User: liubing17 * DateTime: 2019-10-17 17:10 */ function get($m, $n){ /* * 获 ...

  2. hdu6055(求正方形个数)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6055 题意: 给出 n 组坐标 x, y, 输出其中的正多边形个数 . 其中 x, y 均为整数. ...

  3. HDU 1019 (多个数的最小公倍数)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (J ...

  4. C语言辗转相除法求2个数的最小公约数

    辗转相除法最大的用途就是用来求两个数的最大公约数. 用(a,b)来表示a和b的最大公约数. 有定理: 已知a,b,c为正整数,若a除以b余c,则(a,b)=(b,c). (证明过程请参考其它资料) 例 ...

  5. 求N个数的最大公约数和最小公倍数(转)

    除了分解质因数,还有另一种适用于求几个较小数的最大公约数.最小公倍数的方法 下面是数学证明及算法实现 令[a1,a2,..,an] 表示a1,a2,..,an的最小公倍数,(a1,a2,..,an)表 ...

  6. 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]

    [本文链接] http://www.cnblogs.com/hellogiser/p/single-number-of-array-with-other-three-times.html [题目] i ...

  7. LightOj 1024 - Eid (求n个数的最小公约数+高精度)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1024 题意:给你n(2<=n<=1000)个数, 然后求n个数的最小公倍数 ...

  8. wikioi 1202 求和(求n个数的和)

    /*============================================================= 1202 求和 题目描述 Description 求n个数的和 输入描述 ...

  9. 求n个数中的最大或最小k个数

    //求n个数中的最小k个数        public static void TestMin(int k, int n)        {            Random rd = new Ra ...

随机推荐

  1. Windows Azure 网站上的 WordPress 3.8

     编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Sunitha Muthukrishna 和 Windows Azure 网站开发人员体验合作伙伴共同撰写. WordPr ...

  2. JavaScript闭包理解的关键 - 作用域链

    阮一峰的一篇文章已经对闭包的用途.概念讲解地相对清晰了. 闭包就是能够读取其他函数内部变量的函数. 但我认为里面对于作用域链的解释还不够清晰,这里作一些补充. 闭包之所以可以读取外部函数的内部变量,即 ...

  3. 用Jetty和redis实现接入服务器adapter

    传统的服务器端为若干个客户端提供服务,一般需要开启多个服务器端进程.为了进一步提升服务器端的处理能力,可以如下图所示将服务解耦为两部分(adapter与workers),它们之间通过消息队列传输数据, ...

  4. 介绍一个python的新的web framework——karloop框架

    karloop是一款轻型的web framework,和tornado.webpy类似.mvc分层设计,眼下已经公布早期版本号了,使用方便, 下载地址例如以下:https://github.com/k ...

  5. js静态方法和实例方法

    js静态方法 function foo(){} // 声明类 foo.method = function(){} // 方法体 使用:foo.method() js实例方法 function foo( ...

  6. Java Web学习笔记(1)

    1.项目名称用小写,类名用大小写骆驼式,对象名用骆驼式但是第一个字母是小写: 2.写对象属性时要空行,第一个方法也要空行,一般要加注释: 3.new 新的对象时等号左右要空格,if语句左右摇有空格: ...

  7. 【转】OCR识别引擎tesseract使用方法——安装leptonica和libtiff

    原文来自:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c4224 ...

  8. js求指定时间的周一和周日

    /*计算指定时间的的周一和周日 return=>{mondy:Date,sundy:Date} parms:{ date:指定时间,如果不指定则取当前时间 } */ function getWe ...

  9. 枚举子集的3种方式 -- C++描述

    要求: 给定一个集合,枚举所有可能的子集.此处的集合是不包含重复元素的. Method0: 增量构造法 思路:每次选取一个元素至集合中,为了避免枚举重复的集合,此处要采用定序技巧 -- 除了第一个元素 ...

  10. objective-III 窗口应用程序

    objective-III 一.创建窗口应用程序  打开xcode->create->在iso目录下选择empty-null->创建 在打开的项目文件名上右击NEW FILE,在io ...