HDU 4739 求正方形个数
九野的博客,转载请注明出处: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 求正方形个数的更多相关文章
- m*n 矩阵中求正方形个数
<?php /** * Notes: * User: liubing17 * DateTime: 2019-10-17 17:10 */ function get($m, $n){ /* * 获 ...
- hdu6055(求正方形个数)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6055 题意: 给出 n 组坐标 x, y, 输出其中的正多边形个数 . 其中 x, y 均为整数. ...
- HDU 1019 (多个数的最小公倍数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (J ...
- C语言辗转相除法求2个数的最小公约数
辗转相除法最大的用途就是用来求两个数的最大公约数. 用(a,b)来表示a和b的最大公约数. 有定理: 已知a,b,c为正整数,若a除以b余c,则(a,b)=(b,c). (证明过程请参考其它资料) 例 ...
- 求N个数的最大公约数和最小公倍数(转)
除了分解质因数,还有另一种适用于求几个较小数的最大公约数.最小公倍数的方法 下面是数学证明及算法实现 令[a1,a2,..,an] 表示a1,a2,..,an的最小公倍数,(a1,a2,..,an)表 ...
- 75 int类型数组中除了一个数出现一次或两次以外,其他数都出现三次,求这个数。[2行核心代码]
[本文链接] http://www.cnblogs.com/hellogiser/p/single-number-of-array-with-other-three-times.html [题目] i ...
- LightOj 1024 - Eid (求n个数的最小公约数+高精度)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1024 题意:给你n(2<=n<=1000)个数, 然后求n个数的最小公倍数 ...
- wikioi 1202 求和(求n个数的和)
/*============================================================= 1202 求和 题目描述 Description 求n个数的和 输入描述 ...
- 求n个数中的最大或最小k个数
//求n个数中的最小k个数 public static void TestMin(int k, int n) { Random rd = new Ra ...
随机推荐
- QT全局热键(用nativeKeycode封装API,不跨平台)
在网上找了很长时间,大家都提到了一个QT全局热键库(qxtglobalshortcut),支持跨平台.在这篇文章中,我将只展示出windows平台下全局热键的设置. 这里提供的方法是在MyGlobal ...
- ubutun 下webalizer 分析Apache日志
http://www.webalizer.org/ 配置Webalizer 我们可以通过命令行配置Webalizer,也可以通过配置文件进行配置.下面将重点介绍使用配置文件进行配置,该方法使用形式比 ...
- kinect for windows - 手势识别之一,kinect手势识别框架
何为手势识别,就是电脑认识人手的自然动作.自然动作包括摆手,握拳,双手合十等等.如果电脑能认识我们这些手势,将来的人机交互将会变得简单而有趣.这里手势不等同于某些规定的动作,比如按鼠标左键,则不属于手 ...
- VC编程中如何设置对话框的背景颜色和静态文本颜色
晚上编一个小程序,涉及到如何设置对话框的背景颜色和静态文本颜色.这在VC6.0中本来是一句话就搞定的事.在应用程序类中的InitInstance()函数添加: //设置对话框背景和文本颜色 SetDi ...
- Android JNI入门第二篇——Java参数类型与本地参数类型对照
前面一篇通过简单的例子介绍了android中JNI的使用.这一篇从基础上了解一些Java参数类型与本地参数类型区别. 1) java中的返回值void和JNI中的void是完全对应的哦! ...
- IOS开发之格式化日期时间的使用 && 编程中常见问题
今天在做一个有关时间的一些开发的时候,遇见了一写问题,反正来说既是很简单的问题,但毕竟用了我一些时间去调错误,遂记录之. 本来是想用 NSDateFormat 来转换一下服务器返回的时间,然后在客户端 ...
- js 精美倒计时
精美倒计时*{ padding:0; margin:0;}.colockbox{width:250px;height:30px;background:url(/jscss/demoimg/201312 ...
- java结构与算法之冒泡排序
一.什么是冒泡排序:冒泡排序是在从相邻两个数之间进行比较,这里将前面一个值定义为before,后面一个值定义为after:当before>after时i,交换他们的值,如果before<a ...
- centos5.5 安装git
查看centos版本 # cat /etc/redhat-release CentOS release 5.5 (Final) 安装git 下载: 如果有老版本的git: #git clone git ...
- BZOJ 1880: [Sdoi2009]Elaxia的路线( 最短路 + dp )
找出同时在他们最短路上的边(dijkstra + dfs), 组成新图, 新图DAG的最长路就是答案...因为两人走同一条路但是不同方向也可以, 所以要把一种一个的s,t换一下再更新一次答案 ---- ...