「暑期训练」「Brute Force」 Multiplication Table (CFR256D2D)
题意
给定一矩阵M" role="presentation">MM,Mij=ij" role="presentation">Mij=ijMij=ij,求第k大值。
分析
这个题不看题解我是想不到二分的,但是二分当然属于暴力,不爽不要玩;)
实际上,现在做题解的时候,意识到一个有意思的结论:第k大xxx往往都与二分思想有关。我们还会与分治思想再见的。
具体做法:二分第k大值p。求数组中p元素是第几大即可。
代码
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ZERO(x) memset((x), 0, sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define QUICKIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pii = pair<int, pi>;
template<typename T>
T read()
{
T tmp; cin>>tmp;
return tmp;
}
int main()
{
ll n,m,k; cin>>n>>m>>k;
ll l=0,r=(ll)n*m+1;
//cout<<r<<endl;
while(r-l>1)
{
ll mid=l+(r-l)/2;
ll cnt=0;
rep(i,1,n)
{
cnt+=min(ll(ceil(double(mid)/i)-1),(ll)m);
}
if(cnt+1>k)
{
r=mid;
}
else l=mid;
}
cout<<(l+r)/2<<endl;
return 0;
}
「暑期训练」「Brute Force」 Multiplication Table (CFR256D2D)的更多相关文章
- 「暑期训练」「Brute Force」 Restoring Painting (CFR353D2B)
题意 给定一定条件,问符合的矩阵有几种. 分析 见了鬼了,这破题谁加的brute force的标签,素质极差.因为范围是1e5,那你平方(枚举算法)的复杂度必然爆. 然后你就会思考其中奥妙无穷的数学规 ...
- 「暑期训练」「Brute Force」 Bitonix' Patrol (CFR134D1D)
题意 有n" role="presentation">nn个站点,排成圆形,每站间距m" role="presentation"> ...
- 「暑期训练」「Brute Force」 Optimal Point on a Line (Educational Codeforces Round 16, B)
题意 You are given n points on a line with their coordinates $x_i$. Find the point x so the sum of dis ...
- 「暑期训练」「Brute Force」 Money Transfers (CFR353D2C)
题目 分析 这个Rnd353真是神仙题层出不穷啊,大力脑筋急转弯- - 不过问题也在我思维江化上.思考任何一种算法都得有一个“锚点”,就是说最笨的方法怎么办.为什么要这么思考,因为这样思考最符合我们的 ...
- 「暑期训练」「Brute Force」 Far Relative’s Problem (CFR343D2B)
题意 之后补 分析 我哭了,强行增加自己的思考复杂度...明明一道尬写的题- -(往区间贪心方向想了 其实完全没必要,注意到只有366天,直接穷举判断即可. 代码 #include <bits/ ...
- 「暑期训练」「基础DP」 Common Subsequence (POJ-1458)
题意与分析 很简单:求最长公共子序列. 注意子序列与子串的差别:一个不连续一个连续.一份比较好的参考资料见:https://segmentfault.com/a/1190000002641054 状态 ...
- 「暑期训练」「基础DP」免费馅饼(HDU-1176)
题意与分析 中文题就不讲题意了.我是真的菜,菜出声. 不妨思考一下,限制了我们决策的有哪些因素?一,所在的位置:二,所在的时间.还有吗?没有了,所以设dp[i][j]" role=" ...
- 「暑期训练」「基础DP」FATE(HDU-2159)
题意与分析 学习本题的时候遇到了一定的困难.看了题解才知道这是二重背包.本题的实质是二重完全背包.二维费用的背包问题是指:对于每件物品,具有两种不同的费用,选择这件物品必须同时付出这两种代价:对于每种 ...
- 「暑期训练」「基础DP」 Monkey and Banana (HDU-1069)
题意与分析 给定立方体(个数不限),求最多能堆叠(堆叠要求上方的方块严格小于下方方块)的高度. 表面上个数不限,问题是堆叠的要求决定了每个方块最多可以使用三次.然后就是对3n" role=& ...
随机推荐
- 课堂笔记——循环语句-for
一.循环:多次执行某段代码. 二.循环四要素: 1.初始条件 2.循环条件 3.状态改变 4.循环体 三.for循环 1.语法: for(初始条件;循环条件;状态改变) { 循环体 } 2 ...
- CentOS如何部署TinyProxy
TinyProxy是个非常便利,及容易架设的HTTP代理 安装方法 rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release- ...
- POJ 3764 The xor-longest Path 【01字典树&&求路径最大异或和&&YY】
题目传送门:http://poj.org/problem?id=3764 The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K ...
- JavaScript数组实战小练习
1.找出元素在数组中的位置. function indexOf(arr, item) { if(Array.prototype.indexOf){ //判断浏览器是否支持indexOf方法 retur ...
- Struts2学习笔记——Struts2搭建和第一个小程序
1.新建web项目 2.配置Struts2核心过滤器 (1)打开web.xml文件,做以下配置: <?xml version="1.0" encoding="UTF ...
- axis调用cxf的webservice注意事项
需要注意的是: 1.wsdl显示部分内容 <?xml version="1.0" ?> - <wsdl:definitions name="Archiv ...
- Python Notes | Python 备忘笔记
[ File IO ] parameters used in the file IO: 该参数决定了打开文件的模式:只读,写入,追加等.所有可取值见如下的完全列表.这个参数是非强制的,默认文件访问模式 ...
- An Algorithm for Surface Encoding and Reconstruction From 3D Point Cloud Data
An Algorithm for Surface Encoding and Reconstruction From 3D Point Cloud Data https://www.youtube.co ...
- SQL limit
employee 表 id name gender hire_date salary performance manage deparmant 1001 张三 男 2/12/1991 00:00:00 ...
- 一个logstash引发的连环案,关于logstash提示:Reached open files limit: 4095, set by the 'max_open_files' option or default, files yet to open: 375248
不多说,直接上问题.版本logstash-2.4.0,启动后提示错误: !!! Please upgrade your java version, the current version '1.7.0 ...