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 ...
随机推荐
- File类常用方法
File类是IO中常用的类 先介绍几个常用的方法: public boolean canRead(),public boolean canWrite() 测试当前文件是否可读可写,若是则返回true ...
- oracle数据库存储过程中NO_DATA_FOUND不起作用?
1.首先创建一个表lengzijiantest,表中只有一个字段f_id CREATE TABLE LENGZIJIANTEST ( F_ID NUMBER NOT NULL ) 2.插入一条数据 i ...
- Just another Robbery(背包)
1079 - Just another Robbery PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 3 ...
- 记载abp中Dbcontext的疑问
q:abp中httpcontext如何在一次请求中保证获取的是相同的实例. 大牛的原话: LifestylePerWebRequest does not works good with async. ...
- 使用超链接跳转页面(GridView)
1. the html markup <div> <asp:GridView ID=" OnPageIndexChanging="GridView1_PageIn ...
- TextView实现多个TextView对象的走马灯效果
1:自定义一个控件继承TextView,重写isFocused方法,返回值为true; package com.example.helloandroid; import android.R.bool; ...
- HDU 1465 不容易系列之排错
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 大家常常感 ...
- [Linux命令]查看Linux系统相关命令
#查看系统内核/操作系统/CPU信息 uname -a #返回:内核名 主机名 Linux内核版本 内核编译日期 操作系统版本 CPU型号 硬件平台 GNU/Linux#查看系统是32位还是64位un ...
- Java学习02
Java学习02 1.导入内部的包 一.在包的下面加入下面一句话: import java.util.Scanner; 二.在类中 Scanner input=new Sanner(Sy ...
- PHP 字符串处理 总结
PHP 字符串处理 PHP 字符串处理 PHP 的字符串处理功能非常强大,主要包括: 字符串输出 echo():输出一个或多个字符串 print():输出一个字符串 printf():输出格式化字符串 ...