http://codeforces.com/contest/846/problem/D

二分答案

适合于:

判断在t时候第一次成立

哪个状态是最小代价

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=5e2+; struct node
{
int x,y,t;
}f[maxn*maxn]; int K,s,t,a[maxn][maxn],tot[maxn][maxn]={}; int cmp(node a,node b)
{
return a.t<b.t;
} bool judge()
{
int i,j;
for (i=K;i<=s;i++)
for (j=K;j<=t;j++)
if (tot[i][j]-tot[i-K][j]-tot[i][j-K]+tot[i-K][j-K]==K*K)
return ;
return ;
} int main()
{
int q,i,j,l,r,m;
scanf("%d%d%d%d",&s,&t,&K,&q);
for (i=;i<=q;i++)
scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].t); sort(f+,f+q+,cmp); l=,r=q;
while (l<=r)
{
memset(a,,sizeof(a));
m=(l+r)>>; for (i=;i<=m;i++)
a[f[i].x][f[i].y]=;
for (i=;i<=s;i++)
for (j=;j<=t;j++)
tot[i][j]=tot[i-][j]+tot[i][j-]-tot[i-][j-]+a[i][j];
if (judge())
r=m-;
else
l=m+;
}
if (l==q+)
printf("-1");
else
printf("%d",f[l].t);
return ;
}
/*
2 2 2 4
1 2 1
1 1 4
2 2 3
2 1 2 2 2 1 4
1 2 1
1 1 4
2 2 3
2 1 2 2 2 2 0
*/

D. Monitor Educational Codeforces Round 28的更多相关文章

  1. Educational Codeforces Round 28

    A. Curriculum Vitae 题目链接:http://codeforces.com/contest/846/problem/A 题目意思:给你一个只包含0-1的数组,现在要求去可以去掉一些元 ...

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  8. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. ansible软件2

    常用软件安装及使用目录  ansible使用1 第1章 copy模块 1.1 创建文件及写入内容 1. [root@m01 scripts]# ansible oldboy -m copy -a &q ...

  2. 随手记录-linux-Shellinabox插件

    Shellinabox 是一个利用 Ajax 技术构建的基于 Web 的远程Terminal 模拟器,也就是说安装了该软件之后,不需要开启 ssh服务,通过 Web 网页就可以对远程主机进行维护操作了 ...

  3. java工程文件路径的问题

    String classpath = this.getClass().getResource("/").getPath().replaceFirst("/WEB-INF/ ...

  4. Node.js中module文件定义的top-level变量为何是私有的

    在Node.js中,module文件里面使用var,const或者let定义的top-level变量为何是私有的,只能在这个模块文件中使用呢? 原因就是,在模块文件中的内容执行之前,node.js会降 ...

  5. Final发布文案+美工

    团队名称:探路者 1蔺依铭:http://www.cnblogs.com/linym762/(组长) 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www ...

  6. Linux第一二章笔记

    第一章 Linux内核简介 1. Unix内核的特点 简洁:仅提供系统调用并有一个非常明确的设计目的 抽象:几乎所有东西都被当做文件 可移植性:使用C语言编写,使得其在各种硬件体系架构面前都具备令人惊 ...

  7. java学习de路线建议

    我想谈一谈我的一些关于网页学习的小感悟吧.之所以是写这个的原因完全是想告诉现在还处在网页学习的初始阶段的同学一些我学习走过的弯路,但我说的也仅是我个人的理解,毕竟我只能是JavaWeb开发的新手,所以 ...

  8. 关于‘1001.A+B Format (20)’的解题报告

    1001.A+B Format(20) 首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们. 小豪的github 问题描述: Calculate a + ...

  9. Docker基础教程

    一.Docker是什么? KVM, Virtualbox, Vmware是虚拟出机器,让每个实例看到一个单独的机器:而Docker是虚拟出操作系统,实现应用之间的隔离,让各个应用觉得自己有一个自己的操 ...

  10. web国际化,在不同的浏览环境,显示不同的语言

    所谓国际化就是支持多种语言,web应用在不同的浏览环境中可以显示出不同的语言.假设我们正在开发一个支持多国语言的Web应用程序,要求系统能够根据客户端的系统的语言类型返回对应的界面:英文的操作系统返回 ...