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 ...
随机推荐
- 用实体框架搭建MVC程序框架(全部)
第一步:1.新建项目 2.新建domain类库 3.新建Data类库 4.为上面的1.2.3添加实体框架nuget包.(可以右键管理nuget包来查找entityframework,当然也可以通过程序 ...
- Session State Pattern会话状态模式
Client Session State 客户会话状态. 在Client端保存会话状态. 运行机制 Client在每次请求时会把所有的会话数据传给Server,Server在响应时把所有的会话状态传给 ...
- 9款让你眼前一亮的HTML5/CSS3示例及源码
1.HTML5 3D点阵列波浪翻滚动画 今天我们要再分享一款基于HTML5 3D的点阵列波浪翻滚动画特效,同样是非常的壮观. 在线演示 源码下载 2.HTML5小球弹跳动画 很不错的3D小球 今天我要 ...
- AD查询1000条限制和解决方案
公司的一个项目要从AD上取数据,为了测试性能,批量在AD上创建了2000多个用户.但是用java程序获取所有用户的时候会报错或者只能取到1000条数据. 条数据. 用org.springfra ...
- Standford CoreNLP
Stanford CoreNLP Stanford CoreNLP提供一组自然语言处理的工具.这些工具可以把原始英语文本作为输入,输出词的基本形式,词的词性标记,判断词是否是公司名.人名等,规格化日期 ...
- struts2中constant参数设置
序号 方法 说明 1 <constant name="struts.i18n.encoding" value="UTF-8"/> 指定web应用默认 ...
- Windows 8.1 序列化与反序列化
/// <summary> /// 对象序列化成 XML String /// </summary> public static void XmlSerialize<T& ...
- 2013-07-29 IT 要闻速记快想
### ========================= ###传动视暴雪82亿美元赎身,腾讯参与投资 ### ========================= ###帮助企业解决打印&邮 ...
- linux 进程控制笔记
进程创建 普通函数调用完成后,最多返回(return)一次,但fork/vfork会返回二次,一次返回给父进程,一次返回给子进程 父进程的返回值为子进程的进程ID,子进程的返回值为0 1.pid_t ...
- DATE,DATETIME,DATETIME2等日期时间数据类型
日期范围广 0001-01-01 到 9999-12-31.时间范围广 00:00:00 到 23:59:59.9999999. -----------------DATE --只存储日期 selec ...