题目链接:upc2525: Twinkle Twinkle Little Star

Twinkle Twinkle Little Star

Twinkle, twinkle, little star, how I wonder what you are.

Up above the world so high, like a diamond in the sky.

Twinkle, twinkle, little star, how I wonder what you are.

When the blazing sun is gone, when he nothing shines upon.

The you show your little light, Twinkle, twinkle, little star

Twinkle, twinkle, little star, How I wonder what you are.

Twinkle, twinkle, little star, how I wonder what you are.

----<Twinkle, twinkle, little star.>

Well, this song may take us back to our childhood. When we were young, we often looked up at the stars. How amazing they were! But, unfortunately, as we are becoming older and older, what used to be interesting can not interest us now. So what we can do is to find something more interesting!

Here is one, maybe. Assume that all the stars are so far from us that we can treat them as points in a plane. You are given N stars in the plane, and a number K (0≤K≤N). What you need to do is to find the minimum square covering at least K stars, whose edges are all parallel to the axis. The stars which are on the edges of the square are also covered.

Input

The input will consist of multiple cases. Your program should process to the end of the input file.In the first line of one case, there are two integer N and K, 0<N≤1500, 0≤K≤N.

The next N lines are the description of the stars, one star per line. The ith line consists of two integers Xi and Yi, |Xi|<1000000, |Yi|<1000000.

Output

The output will consist of one line for each case, in the format of “Case X: Y”, while X is the case number counting from 1, and Y is the edge length of the minimum square. X and Y are all integers.

Sample Input

4 4
0 0
0 1
1 0
2 2
4 2
0 0
1 1
2 2
3 3

Sample Output

Case 1: 2
Case 2: 1

HINT

Huge input, scanf is recommended.

惯例,比赛的时候没思路。。。
大致意思就是在一个1000000*1000000的平面中有N<1500个点,要求用一个正方形来围住至少K个点,求这个正方形的最小边长。
首先想到应该是对X和有分别离散化,然后得到一个1500*1500的平面,然后枚举这个平面中的所有点作为正方形右下顶点(由于点不一定在最小的正方形顶点上 也可以在边上),然后二分枚举答案,只要能够在O(1)的复杂度来判断是否有K个,可以用dp对离散化后的平面进行处理。
渣渣代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define repd(i,j,n) for(int i=j;i>n;i--)
#define N 1505
using namespace std;
struct node
{int x,y;
} digt[N];
int indexx[N];
int indey[N];
int lx,ly;
int n,k;
int getx(int x)
{return int(lower_bound(indexx,indexx+lx,x)-indexx);
}
int gety(int y)
{return int(lower_bound(indey,indey+ly,y)-indey);
}
int dp[N][N];
void init()
{memset(dp,0,sizeof(dp));for(int i=0; i<n; i++)//将点对应到离散化后的平面上{int x1=getx(digt[i].x);int y1=gety(digt[i].y);dp[x1][y1]++;}for(int i=1; i<ly; i++)dp[0][i]=dp[0][i-1]+dp[0][i];for(int i=1; i<lx; i++)dp[i][0]=dp[i-1][0]+dp[i][0];for(int i=1; i<lx; i++)for(int j=1; j<ly; j++)dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+dp[i][j]; //dp[i][j]表示0,0到i,j矩阵中点的个数}
int nextx[N],nexty[N];//nextx[i]表示x轴上离散化第i个点在加上实际Len的值后在离散化平面上的位置
bool solve(int len)
{
//--------------------------------------------------------int t=0;for(int i=0; i<lx; i++){for(; t<lx; t++)if(indexx[i]+len<indexx[t])break;nextx[i]=t-1;}t=0;for(int i=0; i<lx; i++){for(; t<lx; t++)if(indey[i]+len<indey[t])break;nexty[i]=t-1;} //这里求出实际边长对应在离散化后的x,y的差,
//-----------------------------------------------------------int x1,y1;for(int i=0; i<lx; i++)for(int j=0; j<ly; j++){x1=nextx[i];y1=nexty[j];int ll=0,rr=0,lr=0;//分别表示这个矩阵的左边,右边,和左下面积上的点数目if(i>0)ll=dp[i-1][y1];if(j>0)rr=dp[x1][j-1];if(i>0&&j>0)lr=dp[i-1][j-1];if(dp[x1][y1]-ll-rr+lr>=k)return true;}return false;
}
int main()
{//freopen("test.txt","r",stdin);int test=1;while(scanf("%d%d",&n,&k)!=EOF){for(int i=0; i<n; i++){scanf("%d%d",&digt[i].x,&digt[i].y);indexx[i]=digt[i].x; indey[i]=digt[i].y;}sort(indexx,indexx+n); //对X轴离散化sort(indey,indey+n);//对Y轴离散化lx=unique(indexx,indexx+n)-indexx;ly=unique(indey,indey+n)-indey;init();//预处理 int l=0,r=2000005;while(l<r)//二分枚举边长{int  mid=(l+r)>>1;if(solve(mid))r=mid;else l=mid+1;}printf("Case %d: %d\n",test++,l);}return 0;
}/**************************************************************Problem: 2525User: 11072215Language: C++Result: AcceptedTime:176 msMemory:10156 kb
****************************************************************/

upcoj 2525 Twinkle Twinkle Little Star 题解相关推荐

  1. java正则表达式课程_通过此免费课程学习正则表达式

    java正则表达式课程 by Beau Carnes 通过博卡恩斯 通过此免费课程学习正则表达式 (Learn Regular Expressions with this free course) & ...

  2. NeHe教程Qt实现——lesson09

    NeHe 系列教程之九: 在3D空间中移动位图 英文教程地址:lesson09 本课基于第一课的代码, 利用颜色混合的方法,将一个黑白纹理与随机颜色进行混合,产生绚丽的效果. 首先是定义相关变量和数据 ...

  3. 开源项目 | 五分钟搭建BERT服务,实现1000+QPS

    作者丨刘欣 单位丨香侬科技算法架构负责人 研究方向丨NLP工程化.算法平台架构 深度学习模型在训练和测试时,通常使用小批量(mini-batch)的方式将样本组装在一起,这样能充分利用 GPU 的并行 ...

  4. NEFU 635(二分+枚举)

    题目:Twinkle Twinkle Little Star 题意:就是给n个点的坐标,然后在这个图形中找出一个边长最小的正方形,要求正方形的边平行于坐标轴且覆盖的点大于等于k个. #include ...

  5. JAVA面试题集收藏大放送

    1.C++或Java中的异常处理机制的简单原理和应用. 当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常.违反语义规则包括2种情况.一种是JAVA类库内置的语义检 ...

  6. 最简单的c语言的编程题目,编程列入考题

    ① 简单的C语言考试题目!(不需要编程) 写入数据的时候,写入的是123,作为一个数处理的. 将printf("%d%d\n",k,n); 改成printf("%d %d ...

  7. 升级浏览器_星愿浏览器升级至6.3.2000.2001

    玩懂手机网资讯,星愿浏览器升级至6.3.2000.2001,可能很多玩友都不熟悉这款浏览器,星愿浏览器(Twinkstar Browser)是一款使用chromium内核来自一首英文歌曲< Tw ...

  8. python中如何将字典直接变成二维数组_python基础知识(列表、字典、二维数组)...

    记得改参数!!! (1)简述列表(list)结构的特点. List(列表) List的元素以线性方式存储,可以存放重复对象,List主要有以下两个实现类: ArrayList : 长度可变的数组,可以 ...

  9. linux 基础训练,Linux 基础训练习题

    1.从当前目录切换到/usr/local                                                          cd /usr/local 2.使用绝对路径 ...

最新文章

  1. php 语言文件操作,php中目录文件操作详谈
  2. Dalvik/ART(ANDROID)中的多线程机制(2)
  3. [系统集成] CI持续集成项目简介
  4. python3单例-python3如何运行文件夹python单例模式
  5. flask的janja模板
  6. 如何控制修改UIWebView中的UIScrollView
  7. 高精度事件计时器怎么关闭_Node.js 事件循环
  8. 【Oracle】-【LRU和DBWR】-LRU算法与DBWR中的应用
  9. Mac终端文件类型显示不同颜色
  10. 1.Tow Sum(两数和)
  11. android投影到创维电视,创维Miracast,手机怎么投屏到创维电视,
  12. [AHK]--显示器输入源快速切换
  13. Ice helloworld
  14. 计算机图形学-二维图形的裁剪
  15. 对抗生成网络(Generative Adversarial Network)
  16. 【大咖来了】---中国HBase技术社区MeetUp
  17. 利用composer安装依赖
  18. C#大文件上传支持切片上传
  19. python 图片对比文件夹_使用python进行文件夹对比
  20. java协程_在Java中使用协程(Coroutine)

热门文章

  1. C++还在用printf/cout进行Debug?学习一下如何自己写日志库吧(上篇)
  2. 【LEDE】x86软路由之路-04-哑巴?alsa了解一下?
  3. 解决IDEA占用C盘空间过大的问题
  4. 女工程师独家揭秘:双11秘密武器阿里云数据库团队故事
  5. python matplotlib 双y轴图像实现
  6. 黑客动态播报 | 一封假offer,盗取6.25亿美元
  7. 大雪花U盘启动盘制作工具怎么样
  8. 2020秋招——万字面经分享,这一篇超级走心
  9. 计算机上可用内存不足无法打开图,Windows照片查看器无法显示此图片因为计算机上的可用内存可能不足解决方法...
  10. 商汤科技2018年校招