九野的博客,转载请注明出处: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. Hello China操作系统STM32移植指南(二)

    移植步骤详解 下面就以MDK 4.72为开发环境,详细说明Hello China内核向STM32的移植过程.MDK 4.72评估版只支持32K代码的编译,这对Hello China的内核来说,裁剪掉一 ...

  2. 从Xib文件加载UIView的5种方式

    在不同的Xib文件中最容易维护的是定义的视图,因此对于从Xib文件中加载UIView来说一个方便的流程是非常重要. 在过去的几年里我发现唯一易于管理创建和维护视图(或者任何界面元素,通常会更多)方式就 ...

  3. CodeForces 448

    A:Rewards: 题目链接:http://codeforces.com/problemset/problem/448/A 题意:Bizon有a1个一等奖奖杯,a2个二等奖奖杯,a3个三等奖奖杯,b ...

  4. Struts2 API的chm格式帮助文档制作教程

    Struts2 API的chm格式帮助文档制作教程 在SSH三个框架中,Struts2的API文档是最难做的,这里所说的格式是chm格式的,chm的格式很方便,Hibernate API文档和Spri ...

  5. 在C#中使用 Win32 和其他库

    C# 用户经常提出两个问题:“我为什么要另外编写代码来使用内置于 Windows® 中的功能?在框架中为什么没有相应的内容可以为我完成这一任务?”当框架小组构建他们的 .NET 部分时,他们评估了为使 ...

  6. jQuery的AJAX方法简介及与其他文件$符号冲突的解决办法

    一.重要的jQuery AJAX方法简介 $.load(url) 从服务器载入数据 $.get(url,callback) 从服务器请求数据,并执行回调函数 $.post(url,data,callb ...

  7. Linux下载文件时报错 To connect to ohse.de insecurely, use ‘--no-check-certificate’.

    远程调用下载文件直接用wget就可以,一般文件路径类型是http.如果有遇到是https就会下载出错. 错误如下: [root@vmu010226-node1 tmp]# wget https://w ...

  8. matlab实现协同过滤之pdist、squareform

    实现协同过滤算法的第一步是:计算用户或项目之间的相似度.接下来介绍pdist和squareform 用法: D = pdist(X) D = pdist(X,distance)   D = pdist ...

  9. [LeetCode]题解(python):026-Remove Duplicates from Sorted Array

    题目来源: https://leetcode.com/problems/remove-duplicates-from-sorted-array/ 题意分析: 给定一个排好序的数组,去除重复的数,返回新 ...

  10. Oracle逐行累加求和

    最近遇到一个比较常见的问题,每行记录需要累加求和.这些问题倒不是有多难,主要是在工作的过程中会经常遇到,特别是Oracle自带的一些函数也能够很好地解决这样一些通用的查询计算,在此记录一下. 问题描述 ...