SGU 532. Building Foundation 暴力
532. Building Foundation
题目连接:
http://acm.sgu.ru/problem.php?contest=0&problem=532
Description
A new office building is to appear in Berland soon. Its construction has just been started, and the first problem builders are facing is to lay the foundation.
The ground at construction site area has already been hardened along n segments. Each segment is given by integer coordinates of its endpoints in the site area coordinate system. Every segment has a positive length and is parallel to either Ox axis or Oy axis. It's important to note that the ground hardening was done in such a way that only perpendicular segments could possibly have common points.
The decision has been made for the foundation to have a rectangular form. The rectangle must have the following properties:
it should have a positive area,
its sides should be parallel to one of the coordinate axes,
its sides should be situated on the hardened ground, i.e. each point of its perimeter should belong to at least one segment out of the n hardened ones.
You are to help estimating the difficulty of choosing such a rectangle. Write a program that finds the number of rectangles that can possibly be used as a foundation.
Input
The first line contains integer n (1 ≤ n ≤ 600) — the number of hardened segments. Each of the following n lines contains four space-separated integers x1, y1, x2, y2 (-109 ≤ x1,y1,x2,y2 ≤ 109) — coordinates of the segments' endpoints. Each segment has positive length and is parallel to either Ox axis or Oy axis. No two horizontal segments have a common point. No two vertical segments have a common point.
Output
Print a single integer — the number of rectangles that can possibly be used as a foundation.
Sample Input
4
0 0 1 0
0 0 0 1
1 1 1 -1
1 1 0 1
Sample Output
1
Hint
题意
在平面上给你n条平行于坐标轴的线段,然后问你能够组成多少个矩形
题解:
直接暴力枚举两条边,然后统计有多少条边同时经过这两条边就好了
然后贡献就是n*(n-1)/2,n表示经过这两条边的边数
代码
#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
int x1[maxn],x2[maxn],yy1[maxn],y2[maxn];
int cross(int k1,int k2)
{
if(x1[k1]==x2[k1]&&x1[k2]==x2[k2])
return 0;
if(yy1[k1]==y2[k1]&&y2[k2]==yy1[k2])
return 0;
if(yy1[k1]==y2[k1])
swap(k1,k2);
if(x1[k1]<=x2[k2]&&x1[k1]>=x1[k2] && yy1[k1]<=yy1[k2]&&y2[k1]>=yy1[k2])
return 1;
return 0;
}
bitset<maxn> s[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&x1[i],&yy1[i],&x2[i],&y2[i]);
if(x1[i]>x2[i])swap(x1[i],x2[i]);
if(yy1[i]>y2[i])swap(yy1[i],y2[i]);
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(cross(i,j))
s[i][j]=1,s[j][i]=1;
long long ans = 0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
bitset<maxn> t = s[i]&s[j];
int p = t.count();
ans+=p*(p-1)/2;
}
cout<<ans/2<<endl;
}
SGU 532. Building Foundation 暴力的更多相关文章
- NEERC Southern Subregional 2011
NEERC Southern Subregional 2011 A - Bonnie and Clyde solution 双指针搞搞就好. 时间复杂度:\(O(n)\) B - Building F ...
- Template Method Design Pattern in Java
Template Method is a behavioral design pattern and it’s used to create a method stub and deferring s ...
- cdoj 04 Complete Building the Houses 暴力
Complete Building the Houses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...
- hdu 5033 Building (单调栈 或 暴力枚举 )
Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...
- SGU 128. Snake --- 暴力枚举+并查集+贪心+计算几何
<传送门> 128. Snake time limit per test: 0.25 sec. memory limit per test: 4096 KB There are N poi ...
- sgu 142. Keyword 暴力,hash 难度:0
142. Keyword time limit per test: 0.5 sec. memory limit per test: 16384 KB Kevin has invented a new ...
- Building OpenCascade on Windows with Visual Studio
Building OpenCascade on Windows with Visual Studio eryar@163.com 摘要Abstract:详细说明OpenCascade的编译配置过程,希 ...
- ACM 暴力搜索题 题目整理
UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...
- 找规律 SGU 107 987654321 problem
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=107 /* 题意:n位数的平方的后面几位为987654321的个数 尼玛,我看描述这 ...
随机推荐
- nginx服务器防sql注入/溢出攻击/spam及禁User-agents
本文章给大家介绍一个nginx服务器防sql注入/溢出攻击/spam及禁User-agents实例代码,有需要了解的朋友可进入参考. 在配置文件添加如下字段即可 代码如下 复制代码 server { ...
- 【剑指offer 面试题47】不用加减乘除做加法
思路: 利用位运算 C++: #include <iostream> using namespace std; int main() { , b = ; int sum, carry; d ...
- selenium python (十二)下拉框的处理
#!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip' #下拉框在web页面上非常常见,对于下拉框的处理采用二次定位的方法进行元 ...
- 使用LabVIEW如何生成应用程序(exe)和安装程序(installer)
主要软件: LabVIEW Development Systems>>LabVIEW Professional Development System主要软件版本: 2012主要软件 ...
- python中函数的总结之三
1. 可变长参数 在函数中可变长参数分为两种:一种是非关键字参数,表示为元组:一种是关键字参数,表示为字典. 具体看下面的例子代码,相当于单元测试: #!/usr/bin/env python #'t ...
- Linux学习--第二波
虽然安装的centos感觉不能上网,权限也不知道怎么设置. 偶然的机会发现了一个好东西,博客:http://www.cnblogs.com/xiaoluo501395377/tag/CentOS/.有 ...
- 32+激发灵感的HTML5/CSS3网页设计教程
HTML5是寄托在HTML4基础上取得了的广泛成就.这不仅意味着你不必完全放弃现有的一些标记,而是可以借鉴,以加强 它. CSS3也以同样的方式在互联网内容的安排下,提供了它的柔韧性.CSS3是开 ...
- bzoj2940: [Poi2000]条纹
2940: [Poi2000]条纹 条纹游戏是一个双人的游戏.所需要的物品有一个棋盘以及三种颜色的长方形条纹,这三种颜色分别是红色.绿色和蓝色.所有的红色条纹的尺寸是c*1,所有的绿色条纹的尺寸是z* ...
- SQL Server数学函数
数学函数 1.计算绝对值ABS ABS函数对一个数值表达式结果计算绝对值(bit数据类型除外),返回整数. 语法结构: ABS(数值表达式) 返回值:与数值表达式类型一致的数据 示例: ) --输出 ...
- 关于Windows Azure 地缘组(Affinity Groups)
最近在和一些客户和朋友的沟通中,发现Windows Azure地缘组概念很少有了解.我的建议是使用地缘组来优化同一区域内的网络访问速度.如果我的说法有误,欢迎大家指正. 关于“地缘组”的概念(摘自MS ...