CF263B Squares 题解
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 题解的更多相关文章
- POJ3347:Kadj Squares——题解
http://poj.org/problem?id=3347 题目大意:给定一些正方形的边长,让他们尽可能向左以45°角排列(不能互相重合),求在上面看只能看到哪几个正方形. ———————————— ...
- HHKB Programming Contest 2020 D - Squares 题解(思维)
题目链接 题目大意 给你一个边长为n的正方形和边长为a和b的正方形,要求把边长为a和b的正方形放在长度为n的正方形内,且没有覆盖(可以相邻)求有多少种放法(mod 1e9+7) 题目思路 这个思路不是 ...
- LeetCode 529. Minesweeper
原题链接在这里:https://leetcode.com/problems/minesweeper/description/ 题目: Let's play the minesweeper game ( ...
- 算法与数据结构基础 - 字典树(Trie)
Trie基础 Trie字典树又叫前缀树(prefix tree),用以较快速地进行单词或前缀查询,Trie节点结构如下: //208. Implement Trie (Prefix Tree)clas ...
- LeetCode题解之Squares of a Sorted Array
1.题目描述 2.问题分析 使用过两个计数器. 3.代码 class Solution { public: vector<int> sortedSquares(vector<int& ...
- 题解【洛谷P2730】魔板 Magic Squares
题面 首先我们可以发现,在每一次 BFS 时按照 \(A→B→C\) 的顺序枚举遍历肯定是字典序最小的. 然后就是普通的 BFS 了. 我们考虑使用 \(\text{STL map}\) 来存储起点状 ...
- SP8496 NOSQ - No Squares Numbers 题解
To SP8496 这道题可以用到前缀和思想,先预处理出所有的结果,然后 \(O(1)\) 查询即可. 注意: 是不能被 \(x^2(x≠1)\) 的数整除的数叫做无平方数. \(d\) 可以为 \( ...
- poj-3739. Special Squares(二维前缀和)
题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...
- LeetCode Perfect Squares
原题链接在这里:https://leetcode.com/problems/perfect-squares/ 题目: Given a positive integer n, find the leas ...
随机推荐
- Java设计模式之(八)——适配器模式
1.什么是适配器模式? Convert the interface of a class into another interface clients expect.Adapter lets clas ...
- 微信小程序中途加入云开发之坑
一开始未使用云开发的小程序项目,之后想使用云开发能力时,要先删除对应在开发者工具中的项目(先压缩备份源码!),再用开发者工具重新创建,很多时候都需要用这种方式进行处理
- char *p、char p[]、字符串的几个题目
总结一下遇到的关于char *p.char p[]和字符串的题目: 例一:(指针的指针) 1 void getmemory(char **p) 2 { 3 p = (char *)malloc(100 ...
- 55张图吃透Nacos,妹子都能看懂!
大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第1篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...
- R数据科学-2
R数据科学(R for Data Science) Part 2:数据处理 导入-->整理-->转换 ------------------第7章 使用tibble实现简单数据框------ ...
- web性能测试工具——http_load
http_load是一款基于Linux平台的web服务器性能测试工具,用于测试web服务器的吞吐量与负载,web页面的性能. http_load是基于linux.unix平台的一种性能测工具 它以并行 ...
- [源码解析] PyTorch 分布式 Autograd (6) ---- 引擎(下)
[源码解析] PyTtorch 分布式 Autograd (6) ---- 引擎(下) 目录 [源码解析] PyTtorch 分布式 Autograd (6) ---- 引擎(下) 0x00 摘要 0 ...
- A Child's History of England.43
PART THE SECOND When the King heard how Thomas à Becket had lost his life in Canterbury Cathedral, t ...
- 【swift】Xcode未响应(卡死、卡住、CPU满载、忙碌、转圈圈)
在尝试了网上的方法,依然没能解决问题,尝试如下: 1.去自己项目的路径,找到<你的项目名.xcodeproj>,点击[显示包内容],删除xcuserdata文件夹 2.去Library,把 ...
- C++ 之杂记
今天做了一个题,代码不难,但是编译的时候就恼火,老是报错,也不告诉我错哪了.... 之前的代码是这样的,在main函数中调用这个类的构造函数,就一直报错,但是不知道原因,后来加上了const 就好了. ...