Description

给一个n*n的地图,每个格子有一个价格,找一个矩形区域,使其价格总和位于[k,2k]

Input

输入k n(n<2000)和一个n*n的地图

Output

输出矩形的左上和右下的列-行坐标或NIE

Sample Input

inputdata1
4 3
1 1 1
1 9 1
1 1 1
inputdata2
8 4
1 2 1 3
25 1 2 1
4 20 3 3
3 30 12 2

Sample Output

outputdata1
NIE
outputdata2
2 1 4 2

题解:

http://blog.csdn.net/popoqqq/article/details/44625423

code:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long int64;
char ch;
bool ok;
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
const int maxn=;
int k,n,a[maxn][maxn],head,tail,last,h[maxn],top,l[maxn],r[maxn];
int64 sum[maxn][maxn];
int64 calc(int x,int y,int xx,int yy){return sum[xx][yy]-sum[xx][y-]-sum[x-][yy]+sum[x-][y-];}
struct Data{
int val,id;
}que[maxn],stack[maxn];
void output(int x,int y,int xx,int yy){
while (calc(x,y,xx,yy)>k*){
if (x==xx) y++;
else if (calc(x+,y,xx,yy)>=k) x++;
else xx--;
}
printf("%d %d %d %d\n",y,x,yy,xx);
exit();
}
void work(int x){
/*head=1,tail=0,last=1;
for (int i=1;i<=n;i++){
while (head<=tail&&que[tail].val>=h[i]) tail--;
que[++tail]=(Data){h[i],i};
while (head<=tail&&que[head].val==0) last=que[head++].id+1;
if (head<=tail&&calc(x-que[head].val+1,last,x,i)>=k) output(x-que[head].val+1,last,x,i);
}*/
top=;
for (int i=;i<=n+;i++){
while (top&&stack[top].val>h[i]) r[stack[top--].id]=i-;
stack[++top]=(Data){h[i],i};
}
top=;
for (int i=n;i>=;i--){
while (top&&stack[top].val>h[i]) l[stack[top--].id]=i+;
stack[++top]=(Data){h[i],i};
}
for (int i=;i<=n;i++)
if (h[i]) if (calc(x-h[i]+,l[i],x,r[i])>=k) output(x-h[i]+,l[i],x,r[i]);
}
int main(){
read(k),read(n);
for (int i=;i<=n;i++) for (int j=;j<=n;j++){
read(a[i][j]),sum[i][j]=sum[i][j-]+a[i][j];
if (k<=a[i][j]&&a[i][j]<=k*){printf("%d %d %d %d\n",j,i,j,i);return ;}
}
for (int i=;i<=n;i++) for (int j=;j<=n;j++) sum[i][j]+=sum[i-][j];
for (int i=;i<=n;i++){
for (int j=;j<=n;j++) h[j]=a[i][j]>k*?:h[j]+;
work(i);
}
puts("NIE");
return ;
}

bzoj1127: [POI2008]KUP的更多相关文章

  1. [BZOJ1127][POI2008] KUP子矩阵

    Description 给一个n*n的地图,每个格子有一个价格,找一个矩形区域,使其价格总和位于[k,2k] Input 输入k n(n<2000)和一个n*n的地图 Output 输出矩形的左 ...

  2. bzoj1127[POI2008]KUP 悬线法

    Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 485  Solved: 174[Submit][Status][D ...

  3. 【BZOJ-1127】KUP 悬线法 + 贪心

    1127: [POI2008]KUP Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 317  Solved: 11 ...

  4. 1127: [POI2008]KUP

    1127: [POI2008]KUP https://lydsy.com/JudgeOnline/problem.php?id=1127 分析: 如果存在一个点大于等于k,小于等于2k的话,直接输出. ...

  5. [BZOJ] 1127: [POI2008]KUP

    似曾相识的感觉 考虑另一个判断问题,给定一个k,问这个k是否可行 存在矩形和\(sum>2k\),则该矩阵不对判定做出贡献 存在矩形和\(sum\in [k,2k]\),则我们找到了一个解 于是 ...

  6. bzoj 1127 [POI2008]KUP——思路(悬线法)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1127 大于2*K的视为不能选的“坏点”.有单个格子满足的就直接输出. 剩下的都是<K的 ...

  7. [POI2008]KUP

    Description 给一个\(n\times n\)的地图,每个格子有一个价格,找一个矩形区域,使其价格总和位于[k,2k] Input 输入k n(n<2000)和一个\(n\times ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. [BZOJ1112][POI2008]砖块Klo

    [BZOJ1112][POI2008]砖块Klo 试题描述 N柱砖,希望有连续K柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出一块砖,放到另 ...

随机推荐

  1. java.lang.RuntimeException: Missing type parameter

    程序中用到了gson的new typeToken,结果打包成apk发布时,发现抛出异常,但不通过打包apk时发现一切正常,百思不得其解,最初怀疑没有将gson-1.7.1.JAR打包进去,后来经过测试 ...

  2. C# 自动登录网页,浏览页面【转载】

    需求:客户的数据同时存在在另外一个不可控的系统中,需要和当前系统同步. 思路:自动登录另外一个系统,然后抓取数据,同步到本系统中. 技术点:模拟用户登录:保存登录状态:抓取数据 /// <sum ...

  3. .net web 开发平台- 表单设计器 一(web版)

    如今为了适应需求的不断变化,动态表单设计器应运而生.它主要是为了满足界面的不断变化和提高开发速度.比如:一些页面客户可能也无法确定页面的终于布局,控件的位置,在哪种情况下显示或不显示等可能须要随时改动 ...

  4. (hdu step 6.3.1)Strategic Game(求用最少顶点数把全部边都覆盖,使用的是邻接表)

    题目: Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  5. HTML5事件——contextmenu 隐藏鼠标右键菜单

    在window中单击右键或在Mac中Ctrl+单击时会触发contextmenu事件,通过取消其默认动作能够提供自己定义菜单. 首先先写一个自己的菜单: <style> ul, li { ...

  6. sqlserver 数据行统计,秒查语句

    1.传统统计方式                                                                                             ...

  7. HDU 1025 Constructing Roads In JGShining&#39;s Kingdom (DP)

    Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which ...

  8. TCP洪水攻击(SYN Flood)的诊断和处理

    TCP洪水攻击(SYN Flood)的诊断和处理   SYN Flood介绍 前段时间网站被攻击多次,其中最猛烈的就是TCP洪水攻击,即SYN Flood. SYN Flood是当前最流行的DoS(拒 ...

  9. 如何为 setTimeout() 方法传参

    现有如下JavaScript代码: function printApple(apple){ console.log(apple, "is a kind of healthy fruit&qu ...

  10. python----------进程、线程、协程

    进程与线程 什么是进程(process)? An executing instance of a program is called a process. Each process provides ...