TopCoder - SRM521 div1 500 RangeSquaredSubsets
来源:互联网 发布:怀化学院教务网络 编辑:程序博客网 时间:2024/06/02 02:22
Problem Statement
Given a real number n, a set of points P in the XY plane is called n-squared if it is not empty and there exists a square of side n in the XY plane with its sides parallel to the axes such that a point from the given set of points is in P if and only if it is contained within the square. A point lying on a side or a vertex of the square is considered to be contained in it.
You will be given two ints nlow and nhigh. You will also be given two vector <int>sx and y such that the coordinates of point i are (x[i],y[i]). Return the number of subsets of the input set described byx and y that are n-squared for some n between nlow and nhigh, inclusive.
Definition
Class:RangeSquaredSubsetsMethod:countSubsetsParameters:int, int, vector <int>, vector <int>Returns:long longMethod signature:long long countSubsets(int nlow, int nhigh, vector <int> x, vector <int> y)(be sure your method is public)Limits
Time limit (s):2.000Memory limit (MB):64Constraints
-nlow will be between 1 and 100000000 (10^8), inclusive.-nhigh will be between nlow and 100000000 (10^8), inclusive.-x and y will contain between 1 and 40 elements, inclusive.-x and y will contain the same number of elements.-Each element of x and y will be between -100000000 (-10^8) and 100000000 (10^8), inclusive.-All described points will be different.Examples
0)5
5
{-5,0,5}
{0,0,0}
Returns: 5The following subsets are 5-squared: {(-5,0)}, {(0,0)}, {(5,0)}, {(-5,0),(0,0)}, {(0,0),(5,0)}.1)
10
10
{-5,0,5}
{0,0,0}
Returns: 5The following subsets are 10-squared: {(-5,0)}, {(5,0)}, {(0,0),(5,0)}, {(-5,0),(0,0)}, {(-5,0),(0,0),(5,0)}.2)
1
100
{-5,0,5}
{0,0,0}
Returns: 6{(-5,0),(5,0)} is not x-squared for any x. From the previous 2 examples you can infer that all other non-empty subsets are 5-squared or 10-squared.3)
3
100000000
{-1,-1,-1,0,1,1,1}
{-1,0,1,1,-1,0,1}
Returns: 214)
64
108
{-56,-234,12,324,-12,53,0,234,1,12,72}
{6,34,2,235,234,234,342,324,234,234,234}
Returns: 26
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
离散化枚举, 注意细节
#include <iostream>#include <vector>#include <set>#include <algorithm>#include "limits.h"using namespace std;class RangeSquaredSubsets{public: struct point{ int x, y; point(int X, int Y) : x(X), y(Y) {} }; int INF = 1e9; long long countSubsets(int nlow, int nhigh, vector <int> x, vector <int> y){ int n = x.size(); set<long long> ans; vector<point> points; for(int i = 0; i < n; ++i){ points.push_back(point(x[i], y[i])); } x.push_back(INF); x.push_back(-INF); y.push_back(INF); y.push_back(-INF); sort(x.begin(), x.end()); sort(y.begin(), y.end()); x.erase(unique(x.begin(), x.end()), x.end()); y.erase(unique(y.begin(), y.end()), y.end()); int nx = x.size(); int ny = y.size(); for(int i = 1; i < nx - 1; ++i) for(int j = i; j < nx - 1; ++j) for(int k = 1; k < ny - 1; ++k) for(int l = k; l < ny - 1; ++l){ if(fit(nlow, nhigh, x[j] - x[i], y[l] - y[k], x[j + 1] - x[i - 1], y[l + 1] - y[k - 1])){ long long mask = 0; for(int a = 0; a < n; ++a){ if(inSquare(points[a], x[i], x[j], y[k], y[l])){ mask |= 1ll << a; } } if(mask) ans.insert(mask); } } return ans.size(); } bool fit(int nlow, int nhigh, int sx, int sy, int lx, int ly){ int w = max(nlow, max(sx, sy)); return (w <= nhigh) && (lx > w) && (ly > w); } bool inSquare(point p, int left, int right, int down, int up){ return (p.x >= left) && (p.x <= right) && (p.y >= down) && (p.y <= up); }};
- TopCoder - SRM521 div1 500 RangeSquaredSubsets
- Topcoder SRM552 Div1 500
- TopCoder SRM687 div1 500
- topcoder SRM500 DIV1 level2 500分
- Topcoder SRM630,DIV1,500,后缀数组
- Topcoder SRM 503 DIV1 500 KingdomXCitiesandVillages
- Topcoder.SRM527.Div1.T2
- topcoder SRM500 div1 Level3
- topcoder SRM495 div1 level2
- topcoder SRM495 div1 level3
- TopCoder SRM480 DIV1 Practise
- Topcoder--SRM144 div1
- topcoder SRM598 div1
- topcoder srm609 div1
- TOPCODER--SRM615 div1 AmebaDiv1
- Topcoder Srm 648 DIV1
- Topcoder Srm 649 DIV1
- topcoder SRM500 div1 Level3
- Delphi XE7中蓝牙 Bluetooth例子的使用
- android studio功能键
- iOS 崩溃信息捕获不成功
- 83 js 如何正确传递DOM元素的指针 选择器内参数为变量 论js函数的简化 seajs用法
- Tomcat集群之Session复制配置
- TopCoder - SRM521 div1 500 RangeSquaredSubsets
- HDU 5157 Harry and magic string(Manacher)
- 欢迎使用CSDN-markdown编辑器
- 在django中使用ueditor插件
- 继承和协议的关系
- C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区
- solr4.7新建core
- java - mysql连接
- 图的深度优先搜索(DFS)