Content

有 \(n\) 个边长为 \(a_i\) 的正方形,第 \(i\) 个正方形的四个顶点分别是 \((0,0),(0,a_i),(a_i,0),(a_i,a_i)\),我们定义一个点属于一个正方形当且仅当这个点完全在正方形内或者在正方形的边界上。试找到一个属于 \(k\) 个正方形的点,或者这样的点不存在。

数据范围:\(1\leqslant n,k\leqslant 50,1\leqslant a_i\leqslant 10^9\)。

Solution

我们先按边长由小到大给这些正方形排序,然后由于在正方形边界上也算属于这个正方形,那么答案就可以是第 \(n-k+1\) 大的正方形的右下顶点,直接输出就好。

Code

int n, k, a[57];

int main() {
getint(n), getint(k);
_for(i, 1, n) getint(a[i]);
if(k > n) return printf("-1"), 0;
sort(a + 1, a + n + 1);
printf("%d 0", a[n - k + 1]);
return 0;
}

CF263B Squares 题解的更多相关文章

  1. POJ3347:Kadj Squares——题解

    http://poj.org/problem?id=3347 题目大意:给定一些正方形的边长,让他们尽可能向左以45°角排列(不能互相重合),求在上面看只能看到哪几个正方形. ———————————— ...

  2. HHKB Programming Contest 2020 D - Squares 题解(思维)

    题目链接 题目大意 给你一个边长为n的正方形和边长为a和b的正方形,要求把边长为a和b的正方形放在长度为n的正方形内,且没有覆盖(可以相邻)求有多少种放法(mod 1e9+7) 题目思路 这个思路不是 ...

  3. LeetCode 529. Minesweeper

    原题链接在这里:https://leetcode.com/problems/minesweeper/description/ 题目: Let's play the minesweeper game ( ...

  4. 算法与数据结构基础 - 字典树(Trie)

    Trie基础 Trie字典树又叫前缀树(prefix tree),用以较快速地进行单词或前缀查询,Trie节点结构如下: //208. Implement Trie (Prefix Tree)clas ...

  5. LeetCode题解之Squares of a Sorted Array

    1.题目描述 2.问题分析 使用过两个计数器. 3.代码 class Solution { public: vector<int> sortedSquares(vector<int& ...

  6. 题解【洛谷P2730】魔板 Magic Squares

    题面 首先我们可以发现,在每一次 BFS 时按照 \(A→B→C\) 的顺序枚举遍历肯定是字典序最小的. 然后就是普通的 BFS 了. 我们考虑使用 \(\text{STL map}\) 来存储起点状 ...

  7. SP8496 NOSQ - No Squares Numbers 题解

    To SP8496 这道题可以用到前缀和思想,先预处理出所有的结果,然后 \(O(1)\) 查询即可. 注意: 是不能被 \(x^2(x≠1)\) 的数整除的数叫做无平方数. \(d\) 可以为 \( ...

  8. poj-3739. Special Squares(二维前缀和)

    题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...

  9. LeetCode Perfect Squares

    原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the leas ...

随机推荐

  1. 2、使用HashOperations操作redis(Hash哈希表)

    文章来源:https://www.cnblogs.com/shiguotao-com/p/10560458.html 方法 c参数 s说明 Long delete(H key, Object... h ...

  2. 详解Python Streamlit框架,用于构建精美数据可视化web app,练习做个垃圾分类app

    今天详解一个 Python 库 Streamlit,它可以为机器学习和数据分析构建 web app.它的优势是入门容易.纯 Python 编码.开发效率高.UI精美. 上图是用 Streamlit 构 ...

  3. 直接插入100w数据报错

    ### Cause: com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (77,600 ...

  4. Scrapy框架延迟请求之Splash的使用

    Splash是什么,用来做什么 Splash, 就是一个Javascript渲染服务.它是一个实现了HTTP API的轻量级浏览器,Splash是用Python实现的,同时使用Twisted和QT.T ...

  5. dlang 安装

    刷论坛看到TIOBE排行榜,排名靠前的基本是C.C++.java.python之类的语言,常用的R语言近几年排名一路走高,前20基本变化不大. 后面发现第二十九位居然有个叫做D的语言,看了下和C语法很 ...

  6. RabbitMQ消息中介之Python使用

    本文介绍RabbitMQ在python下的基本使用 1. RabbitMQ安装,安装RabbitMQ需要预安装erlang语言,Windows直接下载双击安装即可 RabbitMQ下载地址:http: ...

  7. 2.MaxSubArray-Leetcode

    题目:最大连续子序列和 思路:动态规划 状态转移方程 f[j]=max{f[j-1]+s[j],s[j]}, 其中1<=j<=n target = max{f[j]}, 其中1<=j ...

  8. kubernetes部署kube-scheduler服务

    同样的分非认证授权和认证授权: 非认证授权: cat > /lib/systemd/system/kube-scheduler.service <<EOF [Unit] Descri ...

  9. OAuth2.0实战!使用JWT令牌认证!

    大家好,我是不才陈某~ 这是<Spring Security 进阶>的第3篇文章,往期文章如下: 实战!Spring Boot Security+JWT前后端分离架构登录认证! 妹子始终没 ...

  10. A Child's History of England.25

    It was a September morning, and the sun was rising, when the King was awakened from slumber by the s ...