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 ...
随机推荐
- UI1_UIButton
// // AppDelegate.m // UI1_UIButton // // Created by zhangxueming on 15/6/30. // Copyright (c) 2015年 ...
- CTG
服务端:一.修改IP地址AIX上CICS REGION的目录/var/cics_regions/your_region_name/database/LD二.修改文件LD.stanza中的IP地址三. ...
- input中的id和name
name在以下用途是不可替代的: 1. 表单(form)的控件名,提交的数据都用控件的name而不是id来控制.因为有许多name会同时对应多个控件,比如checkbox和radio,而id必须是全文 ...
- GDAL读取tiff文件/C++源码
// gdal_geotiff.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "gdal_priv.h&quo ...
- MySQL高可用之MHA (转)
MySQL高可用之MHA MHA简介 MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案.MHA能够在30秒内实现故障切换,并能在故障 ...
- 配置普通用户可以运行saltstack的模块
client_acl 配置使用 1.概述:开启对系统上非root的系统用户在master上可以执行特殊的模块.这些模块名可以使用正则表达式来表示,不能指定对哪些minion执行命令.执行命令只需要切换 ...
- shell 字符截取
Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.aaa.com/123.htm. # 读sharp 谐音 杀: ${var#*//} 杀掉//左边的,保留右边的 ...
- Atan2
在三角函数中,两个参数的函数atan2是正切函数的 一个变种.对于任意不同时等于0的实参数x和y,atan2(y,x)所表达的意思是坐标原点为起点,指向(x,y)的射线在坐标平面上与x轴正方向之间 的 ...
- Hadoop上路-04_HBase0.98.0入门
以下操作在Hadoop分布式集群基础上进行. 一.分布式环境搭建 下载:)验证 3)修改%HBASE%/conf/hbase-env.sh 4)修改$HBASE_HOME/conf/hbase-sit ...
- js阻止冒泡事件及默认操作
1. 事件目标 现在,事件处理程序中的变量event保存着事件对象.而event.target属性保存着发生事件的目标元素.这个属性是DOM API中规定的,但是没有被所有浏览器实现 .jQuery对 ...