spoj 274
离散化 枚举行 扫描横坐标
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inf 0x7fffffff
using namespace std; struct cc
{
int x,y,val;
};
cc pp[1010];
int k,line[1010],x[1010],cur;
int _max,_min; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d%d",&n,&k);
_max = -1;
_min = inf;
for(int i = 0; i < n; i++)
{
scanf("%d%d%d",&pp[i].x,&pp[i].y,&pp[i].val);
line[i] = pp[i].y;
_max = max(pp[i].x, _max);
_min = min(pp[i].x, _min);
}
sort(line, line+n);
int q = unique(line, line+n) - line;
// if(q == 1)
// {
// puts("0");
// continue;
// }
int ans = inf;
for(int i = 0; i < q; i++)
{
for(int j = i; j < q; j++)
{
memset(x, 0, sizeof(x));
for(int v = 0; v < n; v++)
{
if(pp[v].y >= line[i] && pp[v].y <= line[j])
x[pp[v].x] += pp[v].val;
}
int l,r;
l = r = _min;
cur = x[_min];
while(r <= _max)
{
if(cur >= k)
{
ans = min(ans, (line[j]-line[i])*(r-l));
cur -= x[l++];
}
else
{
cur += x[++r];
}
}
}
}
printf("%d\n",ans);
}
return 0;
}
spoj 274的更多相关文章
- SPOJ 274 Johnny and the Watermelon Plantation(TLE)
O(n^3)的时间复杂度,改了半天交了二三十遍,TLE到死,实在没办法了…… 跪求指点!!! #include <cstdio> #include <cstdlib> #inc ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
- 【SPOJ 1812】Longest Common Substring II
http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...
- 【SPOJ 8222】Substrings
http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...
随机推荐
- template_12特化与重载
1,重载函数模板f<int*>((int*)pi);//1f<int>((int*)pi);//2上面用int*替换第一个模板的T,用int来替换第二个模板的T.那么将得到两个 ...
- How to use For loop in CruiseControl.net
Looping through parameter values in Cruisecontrol.net Example >>>>>>>>>&g ...
- C++ 中的 const 详解
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4235721.html 1.为什么使用 const int 而不使用 #define 在使用# ...
- git 的使用(4)-git暂缓区工作区原理和修改删除等命令
文章转载自:http://blog.csdn.net/think2me/article/details/39056379 博主说未经本人允许,不得转载,那就不贴了,拷贝关键部分作备忘 1. 暂存区是G ...
- Linux上iptables防火墙的基本应用
1.安装iptables防火墙 yum install iptables -y 2. 清除已有的iptables规则 iptables -F iptables -X iptables -Z 3.显示i ...
- 自定义视图(继承View)
前言 Android提供了丰富的控件,但是有时候还是不能满足自己的需求,这时候就需要自定义视图了,自定义视图分为几种,一种为继承为View的,一种为继承于ViewGroup的.继承于View的需要我们 ...
- [转]AIX下调整分区大小
AIX下调整文件系统大小 - [work] 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://wangsuiri.blogbus.com/logs/35448074.htm ...
- CSS content内容生成技术以及应用
content属性早在CSS2.1的时候就被引入了,可以使用:before以及:after伪元素生成内容.此特性目前已被大部分的浏览器支持:(Firefox 1.5+, Safari 3.5+, IE ...
- (转载)delphi文件流
delphi文件流 [复制链接] 在Delphi中,所有流对象的基类为TStream类,其中定义了所有流的共同属性和方法. TStream类中定义的属性介绍如下: 1.Size: 此属性以字节返回流中 ...
- 【python】 开始第一个项目
根据这篇文章开始上手 http://www.oschina.net/translate/the-flask-mega-tutorial-part-i-hello-world 再加点东西 如果你的环境是 ...