当前位置:网站首页>22牛客多校1 C.Grab the Seat (几何 + 暴力)
22牛客多校1 C.Grab the Seat (几何 + 暴力)
2022-08-01 07:25:00 【樱落二瓣七里香】
题目大意 : 二维平面, 在y轴上有一1到m的屏幕, 平面类, 有以(1,1) 到 (n,m)的矩阵, 矩阵中有k位座位已经就坐, q次询问, 每次修改一个人的坐标, 求到屏幕视线不被人挡住的座位
思路 : 对于y = 1 和 m 的情况, 只会挡住它身后即x坐标右方的人, 特判一下即可
一般情况, 可看作从(0, 1), (0, m)到该点的两条射线, 射线后的范围即为挡住范围, 整个区域的左边界可以看做为一个折线图, 只需计算折线图每行的横坐标即可, 我们可以分开计算
先看(0, 1)出发的射线, 红色区域即为被遮挡区域, 可以发现位于下面斜率小的点, 会被覆盖, 因为是位于下面的点, 所以斜率一定是小于的, 且观察不难发现 斜率具有单调性
同理从(0, m)一样, 反转一下就行, 最终答案其实就是二者并集, 即每次更新最小值即可
代码如下:
#include <bits/stdc++.h>
using namespace std;
stringstream ss;
#define endl "\n"
typedef long long ll;
typedef pair<ll, ll> PII;
typedef pair<pair<int, int>, int> PIII;
const int N = 2e5+10, M = 30, mod = 1e9+7;
const int INF = 0x3f3f3f3f;
int n,m,k,q;
ll x[N], y[N]; // x, y记录每个编号的坐标
ll x1[N], minx[N]; // x1记录每行最靠左的横坐标(影响最大), minx记录影响
void solve()
{
cin>>n>>m>>k>>q;
for(int i = 1; i<=k; i++) cin>>x[i]>>y[i];
while(q -- )
{
int id;
cin>>id;
cin>>x[id]>>y[id];
for(int i = 0; i<m; i++) x1[i] = n+1; // 每次修改时初始化
for(int i = 1; i<=k; i++) x1[y[i]-1] = min(x1[y[i]-1], x[i]); // 寻找每行影响范围更大的点(横坐标更靠前的), 纵坐标-1方便从(0, 0)点计算斜率
for(int i = 0; i<m; i++) minx[i] = x1[i] - 1; // 初始化答案为每行坐人最小的横坐标
// 先计算由(0, 0)到人的射线
ll mx = n+1, my = 0; // 记录最大斜率
for(int i = 0; i<m; i++)
{
// cy/cx > my/mx 若当前斜率更大则更新斜率
ll cx = x1[i], cy = i;
if(cy*mx > cx*my) mx = cx, my = cy;
ll res;
if(my) res = ceil(mx*i*1.0 / my) - 1; // 计算交点的横坐标 -1表示该交点可能也会被挡
else res = n; // 第一行不用计算, 直接特判为只会影响后面的人
minx[i] = min(res, minx[i]);
}
// 反转依照(0, 0)射线代码来计算(0, m)的射线
reverse(x1, x1+m);
mx = n+1, my = 0;
for(int i = 0; i<m; i++)
{
ll cx = x1[i], cy = i;
if(cy*mx > cx*my) mx = cx, my = cy;
ll res;
if(my) res = ceil(mx*i*1.0 / my) - 1;
else res = n;
minx[m - i - 1] = min(res, minx[m - i - 1]);
}
ll ans = 0;
for(int i = 0; i<m; i++) ans += minx[i];
cout<<ans<<endl;
}
}
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
solve();
// int T;
// cin>>T;
// while(T -- )
// {
// solve();
// }
}
边栏推荐
猜你喜欢
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]
rhcsa 第三次
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
Practical training Navicat Chinese and English mode switching
LabVIEW RT中的用户界面更新速度
Golang:go获取url和表单属性值
数据分析5
特别数的和
VSCode 快捷键及通用插件推荐
Golang: go get url and form attribute value
随机推荐
"By sharing" northwestern university life service | | bytes a second interview on three sides by HR
POJ1251丛林之路题解
图片无损压缩软件哪个好用:试试完全免费的JPG-C 图片批量修整压缩减肥工具吧 | 最新jpg批量修整工具下载
2022杭电多校第二场1011 DOS Card(线段树)
爬虫框架 Scrapy 详解
rhcsa 第三次
配置我的kitty
Introduction to the basic principles, implementation and problem solving of crawler
pytest接口自动化测试框架 | 执行失败跳转pdb
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图可视化股票月收益率数据、使用百分比显示Y轴坐标数据、使用不同的色彩表征正负收益率
Generate pictures based on the content of the specified area and share them with a summary
图像基本操作的其他内容
NIO programming
LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
数据分析6
电磁兼容简明教程(6)测试项目
数据机构----线性表之单向链表
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
Self-made a remote control software - VeryControl
VoLTE基础学习系列 | 什么是SIP和IMS中的Forking