题目链接:http://poj.org/problem?id=1693

解题报告:

随机选两根横的,再找一下与这两根横线相交的竖线有多少根,m,那么就有(m-1)*m/2个长方形。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h> using namespace std; const int maxn = ; struct line {
int x[];
int y[];
}row[maxn],col[maxn]; int n; int main()
{
int Case;
cin>>Case;
int r,c;
while(Case--)
{
r=c=;
int ans=;
cin>>n;
for(int i=;i<n;i++)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if(y1==y2) ///水平
{
row[r].x[]=min(x1,x2);
row[r].x[]=max(x1,x2); row[r].y[]=y1;
row[r++].y[]=y2;
}
else {
///垂直
col[c].y[]=min(y1,y2);
col[c].y[]=max(y1,y2); col[c].x[]=col[c].x[]=x1;
c++;
}
} int maxr,minr,maxc,minc; int tmp;
for(int i=;i<r-;i++)
{
for(int j=i+;j<r;j++)
{
if(row[i].x[]<row[j].x[]||row[i].y[]==row[j].y[])
continue; tmp=;
minr=max(row[i].x[],row[j].x[]);
maxr=min(row[i].x[],row[j].x[]); maxc=max(row[i].y[],row[j].y[]);
minc=min(row[i].y[],row[j].y[]); for(int k=;k<c;k++)
{
if(col[k].x[]>=minr&&col[k].x[]<=maxr&&col[k].y[]<=minc&&col[k].y[]>=maxc)
tmp++;
}
ans+=(tmp-)*tmp/;
}
}
printf("%d\n",ans);
}
}

数长方形有多少个?POJ(1693)的更多相关文章

  1. 暴力枚举-数长方形(hdu5258)

    数长方形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. hdu 5258 数长方形 离散化

    数长方形 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5258 Des ...

  3. HDU 5258 数长方形【离散化+暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  4. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  5. COJ 0036 数数happy有多少个?

    数数happy有多少个? 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 图图是个爱动脑子.观察能力很强的好学生.近期他正学英语 ...

  6. 数集合有多少个TOJ(2469)

    题目链接:http://acm.tju.edu.cn/toj/showp2469.html 感觉这个题目有点问题,算了不管他了,反正A了. 这里要注意的是求这个集合有多少种,那么就是要剔除重复数后,再 ...

  7. 数黑格有多少个,模拟题,POJ(1656)

    题目链接:http://poj.org/problem?id=1656 #include <stdio.h> #include <iostream> #include < ...

  8. POJ 1693

    题意:就是给你n条直线,求这n条直线最多可以构成多少个矩形. 思路:把直线分类,分成水平的和竖直的,然后两两组合,看是否能构成矩形.枚举 Memory: 692K Time: 0MS Language ...

  9. 【POJ】【1704】Georgia and Bob

    组合游戏 Nim游戏的一个变形 题解请看金海峰的博客 以下为引用: 分析:我们把棋子按位置升序排列后,从后往前把他们两两绑定成一对.如果总个数是奇数,就把最前面一个和边界(位置为0)绑定. 在同一对棋 ...

随机推荐

  1. Ancoda 下的python多版本共存

    Ancoda 下的python多版本共存 virtualenv python 多版本共存 Pip, Virtualenv 和Fabric 被称为python 的三大神器,Pip 是包管理工具,Virt ...

  2. 2.4 Rust Ownership

    What Is Ownership ownership这个单词有些不好翻译,刚开始就直接叫它“ownership”即可.这里简单说一下,我对它的理解, 从“数据结构与算法”的角度来看,ownershi ...

  3. js随机生成[n,m)的数字(不包括m)

    Math.random();//随机生成0到1的数字 Math.floor();//取小整 Math.floor(Math.random()*(最大值 - 最小值) + 最小值) 生成2到8的数:Ma ...

  4. MyCnblog Style

    以下内容添加到页脚HTML代码处 <style> #leftmenu ul { display: none; } .cnblogs-markdown pre code, .cnblogs- ...

  5. 2019.03.22 读书笔记 Linq中的IEnumerable与IQueryable

    Linq主要分为 Linq to object .Linq to XML .Linq to sql(现在都用EF了). 针对object和sql,微软分别设计了两套接口IEnumerable.IQue ...

  6. 彻底理解和解决移动WEB开发中CLICK点透问题

    在移动WEB开发中,有时候可能会出现点透问题,本文将围绕这个TAP点透问题,详细的讲述到底什么是点透,为什么会出现点透,如何避免出现点透,如果不可避免的出现了,如何解决解决移动WEB开发中CLICK点 ...

  7. LeetCode 981.基于时间的键值存储(C++)

    创建一个基于时间的键值存储类 TimeMap,它支持下面两个操作: 1. set(string key, string value, int timestamp) 存储键 key.值 value,以及 ...

  8. DBCP数据连接池

    package com.itheima.utils; import java.io.InputStream; import java.sql.Connection; import java.sql.R ...

  9. Entity Framework Many to Many Relation Mapping(Entity Framework多对多关系映射)

    通常我们在做数据库设计时都会有两张表是多对多关系的时候,在数据库做多对多关系时候我们通常通过中间关联表来处理,那我们现在在EF中是如何处理的呢? 假设我们有如下关系,用户(User)包含多个角色(Ro ...

  10. 三、oracle 表空间

    SQL> --清除屏幕信息 SQL> clear screen SQL> --查看表空间 SQL> select * from v$tablespace; SQL> -- ...