当前位置:网站首页>22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
2022-08-01 07:28:00 【Cherry blossoms with two petals Qilixiang】
The gist of the title: A two-dimensional plane has a screen from 1 to m on the y-axis, the plane class has a matrix from (1,1) to (n,m), and the matrix hask seats are already seated, q times of inquiries, each time modifying the coordinates of one person, to find a seat where the screen line of sight is not blocked
Thinking: For the case of y = 1 and m, it will only block the person behind it, i.e. to the right of the x coordinate, and a special judgment can be made
In general, it can be regarded as two rays from (0, 1), (0, m) to this point, the range behind the rays is the blocking range, and the left boundary of the entire area can be regarded as a line graph, just calculate the abscissa of each line of the line chart, we can calculate separately
Looking at the ray from (0, 1) first, the red area is the occluded area. It can be found that the point with a small slope below will be covered. Because it is a point below, the slope must be less than, andIt is not difficult to observe that the slope is monotonic
Similarly from (0, m), just reverse it, the final answer is actually the union of the two, that is, the minimum value can be updated each time
The code is as follows:
#include using namespace std;stringstream ss;#define endl "\n"typedef long long ll;typedef pair PII;typedef pair, 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 record the coordinates of each numberll x1[N], minx[N]; // x1 records the leftmost abscissa of each line (the greatest impact), minx records the impactvoid 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 my/mx update slope if current slope is greaterll 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; // Calculate the abscissa of the intersection -1 means that the intersection may also be blockedelse res = n; // The first line does not need to be calculated, and it is directly judged to only affect the following peopleminx[i] = min(res, minx[i]);}// Invert the ray of (0, m) calculated according to the (0, 0) ray codereverse(x1, x1+m);mx = n+1, my = 0;for(int i = 0; i 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>T;// while(T -- )// {// solve();// }}
边栏推荐
猜你喜欢
随机推荐
套接字选项
阿里三面:MQ 消息丢失、重复、积压问题,该如何解决?
案例实践 --- Resnet经典卷积神经网络(Mindspore)
电磁兼容简明教程(6)测试项目
zip打包目录所有文件(含隐藏文件/夹)
配置我的kitty
【MySQL】操作表DML相关语句
Golang:go获取url和表单属性值
「面经分享」西北大学 | 字节 生活服务 | 一面二面三面 HR 面
VoLTE基础学习系列 | 企业语音网简述
The use of Golang: go template engine
mysql中添加字段的相关问题
Dart 异常详解
我的创作纪念日
如何使用Photoshop合成星轨照片,夜空星轨照片后期处理方法
VoLTE基础学习系列 | 什么是SIP和IMS中的Forking
2022杭电多校第二场1011 DOS Card(线段树)
拳头游戏免版权音乐下载,英雄联盟无版权音乐,可用于视频创作、直播
Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
Go 支持 OOP: 用 struct 代替 class