Monitor CodeForces - 846D
题意:有一个n*m的显示屏,有q个坏点先后出现,已知第i个坏点位置为(xi,yi),在ti时间出现。显示屏上出现一个k*k的矩阵全都是坏点时显示屏就是坏的。输出显示屏坏的时间,如果不会坏就输出-1。
所以说,O(nmq)到底是怎么过的?
//b[i][j]表示第i行第j个开始的向右延伸的坏条长度
#include<cstdio>
#include<algorithm>
using namespace std;
struct Point
{
int x,y,t;
bool operator<(const Point& b) const
{
return t<b.t;
}
}p[];
int b[][];
bool c[][];
int n,m,k,q;
bool judge(int x,int y)
{
int i,ans=;
for(i=x;i<=n;i++)
{
if(b[i][y]<k)
break;
ans++;
if(ans>=k) break;
}
for(i=x-;i>=;i--)
{
if(b[i][y]<k)
break;
ans++;
if(ans>=k) break;
}
if(ans>=k)
return true;
else
return false;
}
int main()
{
int i,j;
bool boo;
scanf("%d%d%d%d",&n,&m,&k,&q);
for(i=;i<=q;i++)
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].t);
sort(p+,p+q+);
for(i=;i<=q;i++)
{
int& x=p[i].x;
int& y=p[i].y;
c[x][y]=true;
for(j=y;j>=;j--)
{
if(!c[x][j]) break;
b[x][j]=b[x][j+]+;
if(b[x][j]>=k)
{
boo=judge(x,j);
if(boo==true)
{
printf("%d",p[i].t);
return ;
}
}
}
}
printf("-1");
return ;
}
所以,以下才是正解...
正解1:二分时间,把当前时间的显示屏状态求出来并放入二维线段树/树状数组(坏点为1,好点为0),暴力枚举k*k矩阵的右下角端点,看是否某个矩阵的所有点的和为k*k,如果这样就说明这一块全坏了。
正解2:每个格子记录变坏的时间(不坏的就给个大值),放进二维线段树,然后暴力查询每个k*k的矩阵中变坏时间的最大值,再取所有最大值的最小值,就是答案(如果为那个大值就是-1)
Monitor CodeForces - 846D的更多相关文章
- C - Monitor CodeForces - 846D (二维前缀和 + 二分)
Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started ...
- Codeforces 846D Monitor(简单二分+二维BIT)
D. Monitor time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Beta Round #16 div 2 C.Monitor最大公约数
C. Monitor time limit per test 0.5 second memory limit per test 64 megabytes input standard input ou ...
- D. Monitor Educational Codeforces Round 28
http://codeforces.com/contest/846/problem/D 二分答案 适合于: 判断在t时候第一次成立 哪个状态是最小代价 #include <cstdio> ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- Educational Codeforces Round 28
A. Curriculum Vitae 题目链接:http://codeforces.com/contest/846/problem/A 题目意思:给你一个只包含0-1的数组,现在要求去可以去掉一些元 ...
- C#各种同步方法 lock, Monitor,Mutex, Semaphore, Interlocked, ReaderWriterLock,AutoResetEvent, ManualResetEvent
看下组织结构: System.Object System.MarshalByRefObject System.Threading.WaitHandle System.Threading.Mutex S ...
- API Monitor简介(API监控工具)
API Monitor是一个免费软件,可以让你监视和控制应用程序和服务,取得了API调用. 它是一个强大的工具,看到的应用程序和服务是如何工作的,或跟踪,你在自己的应用程序的问题. 64位支持 API ...
- 创建 Monitor 并测试 - 每天5分钟玩转 OpenStack(124)
前面我们创建了 Pool,VIP 并添加了 Member.今天将创建 Monitor,然后测试 LBaaS 是否能够正常工作. 创建 Monitor LBaaS 可以创建 monitor,用于监控 P ...
随机推荐
- 杭电1596find the safest road(spfa)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 6138 Fleet of the Eternal Throne 后缀数组 + 二分
Fleet of the Eternal Throne Problem Description > The Eternal Fleet was built many centuries ago ...
- 3531: [Sdoi2014]旅行
3531: [Sdoi2014]旅行 Time Limit: 20 Sec Memory Limit: 512 MB Submit: 1731 Solved: 772 [Submit][Statu ...
- configuration类详解
hadoop中,组件配置是由Hadoop的Configuration的一个实例实现.(在源码包的org.apache.hadoop.conf中可以找到)先上个类图:这只是部分的,Configuraat ...
- http协议的队首阻塞
1 队首阻塞 就是需要排队,队首的事情没有处理完的时候,后面的人都要等着. 2 http1.0的队首阻塞 对于同一个tcp连接,所有的http1.0请求放入队列中,只有前一个请求的响应收到了,然后才能 ...
- 在C++中使用Libmd5计算字符串或文件的MD5值
CppMD5Demo.cpp #include <iostream> #include <fstream> #include <chrono> #include & ...
- springboot实现定时任务的两种方式
方式一:在springboot启动类上添加@EnableScheduling注解,然后创建具体的任务类,在方法上添加@Scheduled注解,并指明执行频率即可.如下: @Componentpubli ...
- Fastreport生成WEB报表
开发WEB应用系统通常都会遇到报表打印问题.简单应用可利用IE的页面打印功能,利用HTML标签控制格式来实现.但复杂的业务型应用系统,报表不仅是组成应用的 重要部分,还常常是相当复杂的.现在很多应用系 ...
- download file by python in google colab
https://stackoverflow.com/questions/15352668/download-and-decompress-gzipped-file-in-memory You need ...
- 织梦系统如何设置URL绝对路径及绝对路径的好处
今天,和大家分享下织梦系统如何设置URL绝对路径及绝对路径的好处,我的一些就是用的织梦系统,感觉织梦在SEO优化方面做的还是非常好的,至少在CMS系统中应该是做的最出色的吧!下面,我就先来讲下这个织梦 ...