九野的博客,转载请注明出处: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. C++ 用libcurl库进行http 网络通讯编程

      一.LibCurl基本编程框架libcurl是一个跨平台的网络协议库,支持http, https, ftp, gopher, telnet, dict, file, 和ldap 协议.libcur ...

  2. HDU 4716 A Computer Graphics Problem

    A Computer Graphics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  3. js获取来源和当前域名

    参考:http://www.cnblogs.com/zuosong160522/p/5755615.html http://www.oicqzone.com/pc/2014113020362.html

  4. 【转】install intel wireless 3165 driver for ubuntu 14.04.3

    [转]install intel wireless 3165 driver for ubuntu 14.04.3 Ubuntu 14.04.3 with 3.19 kernel can’t drive ...

  5. 远程唤醒、WOL、Magic_Packet

    背景:很多人熟悉远程桌面并经常地利用它所带来的方便,但是前提是服务器(远程电脑)必须是处于开机状态.对于机房里有专人管理的服务器,这点不成问题,但如果是放在家里的电脑,要让它7*24地开机似乎就不好办 ...

  6. 【原】Spring和Dubbo整合案例和过程

    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...

  7. java反射机制入门3

    Method对象的机制与实现 1.Method对象概述 1)java.lang.reflect.Method类是用于表示类中.接口中方法对象的类. 2)可以操作类中私有,以及公有等全部方法. 2.Me ...

  8. Oracle语句优化规则(二)

    21.       用EXISTS替换DISTINCT 当提交一个包含一对多表信息(比如部门表和雇员表)的查询时,避免在SELECT子句中使用DISTINCT. 一般可以考虑用EXIST替换  例如: ...

  9. Python每日一练(3):爬取百度贴吧图片

    import requests,re #先把要访问URL和头部准备好 url = 'http://tieba.baidu.com/p/2166231880' head = { 'Accept': '* ...

  10. 2013 南京邀请赛 C count the carries

    /** 大意: 给定区间(a,b), 将其转化为二进制 计算从a+(a+1)+(a+2)....+(a+b-1),一共有多少次进位 思路: 将(a,b)区间内的数,转化为二进制后,看其每一位一共有多少 ...