Codeforces Round #256 (Div. 2) Multiplication Table
C题,
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 5005
using namespace std; int num[maxn]; int rmq(int l,int r)
{
int ans=<<,tmp=l;
for(int i=l;i<=r;i++)
{
if(ans>num[i])
{
ans=num[i];
tmp=i;
}
}
return tmp;
} int get(int l,int r,int h)
{
if(l>r)
return ;
if(l==r)
{
if(num[l]==h)
return ;
else return ;
}
int tmp=rmq(l,r);
int ans=;
ans=min(r-l+,get(l,tmp-,num[tmp])+get(tmp+,r,num[tmp])+num[tmp]-h);
return ans;
} int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&num[i]);
int ans=get(,n-,);
printf("%d\n",ans);
}
刚刚开始想到一种很暴力但还行的方法,不过在和TK讨论的过程中引出了一个更好的算法
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
long long n,m,k;
long long check(long long x)
{
long long ans=;
for(int i=;i<=n;i++)
{
ans+=min(x/i,m);
if(min(x/i,m)*i==x)
ans--;
}
return ans;
}
int main()
{ scanf("%I64d%I64d%I64d",&n,&m,&k);
long long l=,r=n*m+;
long long ans=;
while(l<r)
{
long long mid=(l+r)>>;
long long a=check(mid);
long long b=check(mid+);
if(a<k&&b>=k)
{
ans=mid;
break;
}
else if(b<k)l=mid;
else if(a>=k)r=mid;
}
cout<<ans<<endl;
}
Codeforces Round #256 (Div. 2) Multiplication Table的更多相关文章
- Codeforces Round #256 (Div. 2)——Multiplication Table
题目链接 题意: n*m的一个乘法表,从小到大排序后,输出第k个数 (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m) 分析: 对于k之前的数,排名小于k:k之后的数大于,那么就能够採用 ...
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table 很有想法的一个二分
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #256 (Div. 2)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table
主题链接:http://codeforces.com/contest/448/problem/D 思路:用二分法 code: #include<cstdio> #include<cm ...
- CF Codeforces Round #256 (Div. 2) D (448D) Multiplication Table
二分!!! AC代码例如以下: #include<iostream> #include<cstring> #include<cstdio> #define ll l ...
随机推荐
- python基础:三层循环
三层循环基本演示: break_flag = False #标记1 break_flag2 = False #标记2 break_flag3 = False #标记3 while not break_ ...
- think in java 第四版读书笔记 第一章对象导论
很久没有碰过java了,为了项目需要以及以后找工作,还是有必要将think in java通读一遍.欢迎大家一起讨论学习 1.1抽象过程 面向对象语言的5个特性: 1.万物皆对象 任何事物都可以抽象为 ...
- 《JavaScript高级程序设计》心得笔记-----第三篇章
第十章 1. DOM1级定义了一个Node接口,以Node类型实现(除IE以外),为了确保跨浏览器兼容,最好用nodeType属性与数字数值进行比较(someNode. nodeType==1) ...
- Netfilter深度解剖
在网络上发现这个Netfilter写的很好的系列文章,为了便于后期寻找,特此标注下博客地址,感谢大大神提供. ---------------------------分割线开始---- ...
- jquery获取html元素的绝对位置和相对位置
jquery获取html元素的绝对位置坐标和相对父元素的位置坐标方法:绝对位置坐标:$("#elem").offset().top$("#elem").offs ...
- mount.nfs: access denied by server while mounting localhost:/home/xuwq/minilinux/system
在执行命令如下: mount -t nfs localhost:/home/xuwq/minilinux/system /mnt 出现的错误: mount.nfs: access denied by ...
- 工作案件1 一切都是有check引起的
HTML中input标签有两个类型,radio和checkbox,一个单选按钮一个复选按钮.jquery可以通过$(":radio")和$(":checkbox" ...
- windbg调试.net程序
1. 解决线上.NET应用程序的如下问题: 崩溃 CPU高 程序异常 程序Hang死 2. 安装WinDbg: http://msdn.microsoft.com/en-us/windows/hard ...
- 利用Apply的参数数组化来提高代码的优雅性,及高效性
利用Apply的参数数组化来提高代码的优雅性,及高效性 Function.apply()在提升程序性能方面的技巧 我们先从Math.max()函数说起,Math.max后面可以接任意个参数,最后返回所 ...
- h5 web模板
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --><html lang="zh-cmn-Hans"> ...