2017 Wuhan University Programming Contest 现场赛G. Room(set+思路)

题目G: Room要求根据给定的起点和终点划分矩形区域,并确定最少需要建立多少个服务点。通过判断点与直线的关系,使用set去重计算最少服务点数量。解决方案包括利用两点式求直线方程,判断点在直线上方或下方,并将关系转化为字符串存入set中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题 G: Room

时间限制: 1 Sec   内存限制: 64 MB
提交: 11   解决: 8
[ 提交][ 状态][ 讨论版]

题目描述

The ACM / ICPC team has a large room, the length and width of which is 10^6 . However, the guys in ACM / ICPC teams are too lazy to make their study room tidy. So there are wires everywhere and divide the room into several parts. A team in a part of the room cannot move out of it or they might touch the wires and the network will down. To make every team can compete in the contest, they have to set up some facilities such as toilet since the teams should do anything in their parts. Now, we will give you the map of our study room and the position of the teams, your task is to calculate how many facilities is required to let every team can access a facilities to finish the contest without move out of their part. You should note that two or more teams can share a facility. 

输入

输出

Output one integer, the minimal facilities required.

样例输入

3
0 200000 1000000 600000
600000 0 300000 1000000
0 800000 1000000 400000
9
200000 900000
200000 400000
300000 600000
600000 500000
700000 700000
800000 300000
300000 200000
800000 100000
600000 200000

样例输出

6

提示

[ 提交][ 状态]
题意:给出n个起始点和终止点,保证每个点都在边上,每两个点连成一条线,把矩形分成若干个区域,现在有t个点有人,在有人的区域内建设服务点
,一个区域只建一个就够了,问最少建多少个,也就是问有多少个有人的区域
思路:判断每个点与所有直线的关系,分上下两种关系,分别用1,0标记,把每个点与所有直线的关系都存到字母串里,然后插入到set,这样重复的排列,也就是相同区域的点不重复插入,也就是最小,判断与直线的关系可以用两点式求出方程,然后将点带入判断正负
#include <iostream>
#include <cstdio>
#include <cstring>
#include<string.h>
#include <algorithm>
#include<set>
#define ll long long
#define wtf printf("wtf");
using namespace std;
struct node
{
    int x1,y1,x2,y2;
}e[100005];
struct xx
{
    int x,y;
}p[105];
set<string>s;

ll check(node a,xx b)
{
    ll A=a.y2-a.y1;
    ll B=a.x1-a.x2;
    ll C=(-B*a.y1-A*a.x1);
    return A*b.x+B*b.y+C>0;
}
ll solve(ll n,ll t)
{
    for(ll i=1;i<=t;i++)
    {
             string str="";
        for(ll j=1;j<=n;j++)
        str+=check(e[j],p[i])+'0';

         s.insert(str);
    }
    return s.size();
}
int main()
{
    ll n,t;
    cin>>n;
    for(ll i=1;i<=n;i++)
        scanf("%lld%lld%lld%lld",&e[i].x1,&e[i].y1,&e[i].x2,&e[i].y2);
    cin>>t;
    for(ll i=1;i<=t;i++)
    scanf("%lld%lld",&p[i].x,&p[i].y);
   printf("%lld\n",solve(n,t));
   return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值