数长方形有多少个?POJ(1693)
题目链接: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)的更多相关文章
- 暴力枚举-数长方形(hdu5258)
数长方形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 5258 数长方形 离散化
数长方形 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5258 Des ...
- HDU 5258 数长方形【离散化+暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others) Me ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- COJ 0036 数数happy有多少个?
数数happy有多少个? 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 图图是个爱动脑子.观察能力很强的好学生.近期他正学英语 ...
- 数集合有多少个TOJ(2469)
题目链接:http://acm.tju.edu.cn/toj/showp2469.html 感觉这个题目有点问题,算了不管他了,反正A了. 这里要注意的是求这个集合有多少种,那么就是要剔除重复数后,再 ...
- 数黑格有多少个,模拟题,POJ(1656)
题目链接:http://poj.org/problem?id=1656 #include <stdio.h> #include <iostream> #include < ...
- POJ 1693
题意:就是给你n条直线,求这n条直线最多可以构成多少个矩形. 思路:把直线分类,分成水平的和竖直的,然后两两组合,看是否能构成矩形.枚举 Memory: 692K Time: 0MS Language ...
- 【POJ】【1704】Georgia and Bob
组合游戏 Nim游戏的一个变形 题解请看金海峰的博客 以下为引用: 分析:我们把棋子按位置升序排列后,从后往前把他们两两绑定成一对.如果总个数是奇数,就把最前面一个和边界(位置为0)绑定. 在同一对棋 ...
随机推荐
- js遍历table和gridview
//遍历table var tableObj = document.getElementById("tableName");var str = "";for(v ...
- 阿里插件检查 lombok报错---方法缺少 '@Override' 注解
问题: Eclipse里,阿里编码规约插件扫描代码出现,但是idea却没有. 解决: 将以上注解改成 @Setter @Getter @NoArgsConstructor @AllArgsConstr ...
- 问题:git add 遇到 warning: LF will be replaced by CRLF in 警告(已解决)
问题描述: git add file_name 提交文件时候提示 自动转换 CRLF 标识 如下图: 解决方法: 执行下面代码在命令行中执行: git config --global core.aut ...
- 学习Laravel遇到的问题纪录
1.更换git remote $ git remote rm origin $ git remote add origin git@github.com:your_username/hello_la ...
- 几种IO情况的学习和总结 关于 =====阻塞/非阻塞以及同步/异步区别
同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一下本文的上下文. 背景是Linux环境下的network IO. 在进行解释 ...
- Unity 用JSON库序列化与反序列化类,字典
Unity自己的json序列化是不支持字典格式的,但是 json .net库,功能很强大,还支持序列化字典. 下载地址:https://download.csdn.net/download/qq_15 ...
- 性能测试工具LoadRunner08-LR之Virtual User Generator 检查点
步骤: 1.点击Vuser--->Run-Time Settings 2.点击Preferences--->Enable Image and text check 3.点击Content ...
- CentOS 7 更新软件源和系统
[1] 首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cent ...
- 前端性能优化-Cookie
什么是Cookie Cookie可以理解成为浏览器内部存储数据的一个数据库,并会随请求一起被发送:Cookie以键-值对的形式存在.可以存储网站的一些数据,这部分数据不会随着浏览器关闭而被清除.如下图 ...
- c# 调用matlab
1.返回一个整数 function [ a ] = testReturn( b ) %UNTITLED Summary of this function goes here % Detailed ex ...