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的更多相关文章

  1. Codeforces Round #256 (Div. 2)——Multiplication Table

    题目链接 题意: n*m的一个乘法表,从小到大排序后,输出第k个数  (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m) 分析: 对于k之前的数,排名小于k:k之后的数大于,那么就能够採用 ...

  2. 贪心 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 ...

  3. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #256 (Div. 2) 题解

    Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. Codeforces Round #256 (Div. 2)

    A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...

  8. Codeforces Round #256 (Div. 2) D. Multiplication Table

    主题链接:http://codeforces.com/contest/448/problem/D 思路:用二分法 code: #include<cstdio> #include<cm ...

  9. CF Codeforces Round #256 (Div. 2) D (448D) Multiplication Table

    二分!!! AC代码例如以下: #include<iostream> #include<cstring> #include<cstdio> #define ll l ...

随机推荐

  1. php29号小结(隔行换色······)

    1.给表单加样式,可以用css.php与js.js这三种,其中最好用php与js,现在很推广用这种. css3样式隔行换色(table中) tr:nth-child(even){ background ...

  2. Eclipse+GitHub

    之前一直想研究github的使用,但一直没时间,今天抽空学习了一下,发现真的是非常好用!!! 准备材料 1.你要有最新版的Eclipse(不要问我为什么要最新版的,反正我用的是最新版本) 2.一个gi ...

  3. Jquery 学习二

    一.事件编程 1.基本事件(以方法形式存在的) 基本语法: 原生Javascript代码中的事件绑定方式: DOM对象.事件 = 事件的处理程序   jQuery代码中的事件绑定方式: jQuery对 ...

  4. android 网络_网络源码查看器

    xml设计 <?xml version="1.0"?> -<LinearLayout tools:context=".MainActivity" ...

  5. 模板template

    1.模板就是实现代码重用机制的一种工具,它可以实现类型参数化,即把类型定义为参数,从而实现了真正的代码可重用性.模板可以分为两类,一个是函数模板,另一个是类模板. 2.函数模板的定义一般形式如下: t ...

  6. centos6.5安装flume

    这里安装flume是因为游戏业务日志搜集和分析用的 1.安装java 环境rpm -ivh jdk-8u51-linux-x64.rpm Preparing... ################## ...

  7. WP开发笔记——不同Item显示不同ApplicationBar:适用于Pivot与Panorama

    一.在xaml页面定义两个ApplicationBar: <phone:PhoneApplicationPage.Resources> <shell:ApplicationBar I ...

  8. Silverlight C#动态设置样式

    1.从页面资源中获取样式并应用 btnTest.Style = (Style)this.Resources["BigButtonStyle"] 2.从项目中单独分开的资源字典文件( ...

  9. 常用的php数组排序函数

    分享几个php数组排序函数,每个函数出去sort是排序的意思前缀字母的含义分别代表: a 索引 k 数组键 r 逆向 u 用户自定义 顺序排序函数 sort — 对数组排序  ksort — 对数组按 ...

  10. Nginx启动、停止与平滑重启

    如何启动Nginx:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 停止Nginx:可以发送向通信号给Nginx主进程的 ...