日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Monitor CodeForces - 846D ——二维前缀和

發布時間:2023/11/27 生活经验 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Monitor CodeForces - 846D ——二维前缀和 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Recently Luba bought a monitor. Mon

itor is a rectangular matrix of size?n?×?m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square?k?×?kconsisting entirely of broken pixels. She knows that?q?pixels are already broken, and for each of them she knows the moment when it stopped working. Help Luba to determine when the monitor became broken (or tell that it's still not broken even after all?q?pixels stopped working).

Input

The first line contains four integer numbers?n,?m,?k,?q?(1?≤?n,?m?≤?500,?1?≤?k?≤?min(n,?m),?0?≤?q?≤?n·m)?— the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels.

Each of next?q?lines contain three integer numbers?xi,?yi,?ti?(1?≤?xi?≤?n,?1?≤?yi?≤?m,?0?≤?t?≤?109)?— coordinates of?i-th broken pixel (its row and column in matrix) and the moment it stopped working. Each pixel is listed at most once.

We consider that pixel is already broken at moment?ti.

Output

Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these?q?pixels stopped working.

意思是求m*n中某k*k塊的顯示屏全部都壞了的話該顯示屏就壞了,求屏幕壞的t。

求k*k壞了可以用二位前綴和類似求面積的方法來

二維前綴和?https://blog.csdn.net/yzyyylx/article/details/78298318

因為時間是一直增加,可以二分時間求最小時間

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=505;
struct node
{int x,y,t;
}s[500005];
int a[maxn][maxn],b[maxn][maxn];
int n,m,k,q;
bool cmp(node a,node b)
{return a.t<b.t;
}
int check(int t)//這里就表示二分的時間t時刻
{memset(a,0,sizeof(a));memset(b,0,sizeof(b));for(int i=1;i<=t;i++)a[s[i].x][s[i].y]=1;for(int i=1;i<=n;i++)//二位前綴和處理for(int j=1;j<=m;j++){b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j];}for(int i=k;i<=n;i++)//遍歷看是否成立for(int j=k;j<=m;j++){if(b[i][j]+b[i-k][j-k]-b[i-k][j]-b[i][j-k]==k*k)return 1;}return 0;
}
int main()
{int i,j;while(cin>>n>>m>>k>>q){for(i=1;i<=q;i++)cin>>s[i].x>>s[i].y>>s[i].t;sort(s+1,s+1+q,cmp);int l=1,r=q;int ans=-1;while(l<=r){int mid=(l+r)/2;if(check(mid)){ans=s[mid].t;r=mid-1;}elsel=mid+1;}printf("%d\n",ans);}return 0;
}

總結

以上是生活随笔為你收集整理的Monitor CodeForces - 846D ——二维前缀和的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。