TopCoder - SRM521 div1 500 RangeSquaredSubsets

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>s x and y such that the coordinates of point i are (x[i],y[i]). Return the number of subsets of the input set described by x and y that are n-squared for some n between nlow and nhigh, inclusive.

Definition

 
Class:RangeSquaredSubsets
Method:countSubsets
Parameters:int, int, vector <int>, vector <int>
Returns:long long
Method 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.000
Memory limit (MB):64

Constraints

-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: 5
The 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: 5
The 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: 21
4) 
 
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);
    }


};


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目:使用 JavaScript 编写的杀死幽灵游戏(附源代码) 杀死鬼魂游戏是使用 Vanilla JavaScript、CSS 和 HTML 画布开发的简单项目。这款游戏很有趣。玩家必须触摸/杀死游荡的鬼魂才能得分。您必须将鼠标悬停在鬼魂上 - 尽量得分。鬼魂在眨眼间不断从一个地方移动到另一个地方。您必须在 1 分钟内尽可能多地杀死鬼魂。 游戏制作 这个游戏项目只是用 HTML 画布、CSS 和 JavaScript 编写的。说到这个游戏的特点,用户必须触摸/杀死游荡的幽灵才能得分。游戏会根据你杀死的幽灵数量来记录你的总分。你必须将鼠标悬停在幽灵上——尽量得分。你必须在 1 分钟内尽可能多地杀死幽灵。游戏还会显示最高排名分数,如果你成功击败它,该分数会在游戏结束屏幕上更新。 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox。要玩游戏,首先,单击 index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值