4428: [Nwerc2015]Debugging调试

Description

Your fancy debugger will not help you in this matter. There are many ways in which code can produce different behavior between debug and release builds, and when this happens, one may have to resort to more primitive forms of debugging.
So you and your printf are now on your own in the search for a line of code that causes the release build to crash. Still you are lucky: adding printf statements to this program affects neither the bug (it still crashes at the same original code line) nor the execution time (at least not notably). So even the naive approach of putting a printf statement before each line, running the program until it crashes, and checking the last printed line, would work.
However, it takes some time to add each printf statement to the code, and the program may have a lot of lines. So perhaps a better plan would involve putting a printf statement in the middle of the program, letting it run, seeing whether it crashes before the added line, and then continuing the search in either the first or second half of the code.
But then again, running the program may take a lot of time, so the most time-efficient strategy might be something in between. Write a program that computes the minimum worst-case time to find the crashing line (no matter where it is), assuming you choose an optimal strategy for placing your printf statements.
We're releasing the new version in five hours, so this issue is escalated and needs to be fixed ASAP.
Input
The input consists of one line with three integers:
n ( 1≤n≤106 ), the number of code lines;
r ( 1≤r≤109 ), the amount of time it takes to compile and run the program until it crashes;
p ( 1≤p≤109 ), the time it takes to add a single printf line.
You have already run the program once and therefore already know that it does crash somewhere.
Output
Output the worst-case time to find the crashing line when using an optimal strategy.
你看中的调试器将不会在这件事上帮助你。有代码可以通过多种方式在调试与正式发布的间隙发生不同的行为,当出现这种情况,我们可能不得不求助于更原始的调试方式。
所以,你和你的printf现在在寻求一行导致该发布版本崩溃的代码。幸运的是:增加printf语句到程序里,既不会制造bug(仍然崩溃在同一原始的代码行),也没有影响执行时间(至少不显著)。 因此,即使在每行前加一个printf语句,运行程序,直到它崩溃,并检查最后打印行。
然而,它需要一些时间来添加每个printf语句到代码,并且该程序可以具有很多行。
因此,把一个printf语句在程序的中间或许是一个更好的计划,让它运行,观察它是否在加入行前崩溃,然后继续在代码的前一或后一半寻找。
不过话又说回来,运行程序可能需要很多时间,所以时效最优的策略可能是介于两者之间。
编写计算最坏情况下的最小时间来寻找崩溃行(无论它在哪里),认为你选择最优的加printf语句策略。
我们在5小时内发布新的版本,所以这个问题十分严重,需要尽快解决。

Input

输入包括一行三个整数:
n(1≤n≤10^6),代码行的数目;
r(1≤r≤10^9),编译和运行程序直到它崩溃的时间量;
p(1≤p≤10^9),增加单个的printf行所花费的时间。
您已经运行一次程序,因此已经知道它崩溃的地方。

Output

输出的最坏情况使用最优策略找到崩溃行的时间。

Sample Input

Sample Input 1
1 100 20
Sample Input 2
10 10 1
Sample Input 3
16 1 10

Sample Output

Sample Output 1
0
Sample Output 2
19
Sample Output 3
44
题解:
这种题目一般都是记忆化搜索。
方程其实是方程简单的,f[i]=min{p*j+f[n/(j+1)]}+r  (1<=j<n) ,n/(j+1) 向上取整。。
什么意思呢??
我们考虑把n行分成j+1段,每段下面加一个printf,由于最后一个可以通过排除法得到,所以只加j个printf,还有题目中说是最坏情况,所以把有问题的一段给最大的。
光是这样已经可以过了,但是我们发现速度还是很慢。
其实在枚举的时候有个小技巧,n/(j+1)取整在一段时间内只是会一样的,而j反而大了,这样的j明显不会更优,可以跳过。
#include<stdio.h>
#include<iostream>
using namespace std;
#define ll long long
int n,r,p;
ll f[];
inline ll dfs(int n)
{
if(n<=) return ;
if(f[n]) return f[n];
ll ans=1e16;
int i=;
while(i<n)
{
ans=min(ans,1LL*i*p+dfs((n-)/(i+)+)+r);
if((n-)/(i+)==) break;
i=(n-)/((n-)/(i+));
}
return f[n]=ans;
}
int main()
{
scanf("%d%d%d",&n,&r,&p);
cout<<dfs(n);
return ;
}

bzoj 4428: [Nwerc2015]Debugging调试的更多相关文章

  1. 【BZOJ4428】[Nwerc2015]Debugging调试 记忆化搜索+分块

    [BZOJ4428][Nwerc2015]Debugging调试 Description 你看中的调试器将不会在这件事上帮助你.有代码可以通过多种方式在调试与正式发布的间隙发生不同的行为,当出现这种情 ...

  2. BZOJ4428 : [Nwerc2015]Debugging调试

    设$f[i]$为最优策略下调试$i$行代码的时间,则: $f[1]=0$ $f[i]=\min((j-1)\times p+f[\lceil\frac{i}{j}\rceil])+r$ 意义为枚举pr ...

  3. 【bzoj4428】[Nwerc2015]Debugging调试 数论+记忆化搜索

    题目描述 一个 $n$ 行的代码出了bug,每行都可能会产生这个bug.你要通过输出调试,在其中加入printf来判断bug出现的位置.运行一次程序的时间为 $r$ ,加入一条printf的时间为 $ ...

  4. IP路由配置之---------debugging调试

    实验设备:华三设备N台加一个PC 步骤一,打开屏幕输出开关,开启控制台对系统信息的监视功能 <H3C>terminal debugging #<H3C>terminal mon ...

  5. bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼

    4430: [Nwerc2015]Guessing Camels赌骆 Description Jaap, Jan, and Thijs are on a trip to the desert afte ...

  6. Celery-4.1 用户指南: Debugging (调试)

    远程调试任务(pdb) 基础 celery.contrib.rdb 是 pdb 的一个扩展版本,它支持不通过终端访问就可以远程调试进程. 示例: from celery import task fro ...

  7. BZOJ 4425: [Nwerc2015]Assigning Workstations分配工作站

    难度在于读题 #include<cstdio> #include<algorithm> #include<queue> using namespace std; p ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. 极简 Node.js 入门 - 1.3 调试

    极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...

随机推荐

  1. js_如何优化你的代码让它更好看

    1.对于美的东西我们很难拒绝,比如美女.哈哈哈,程序员的梗. 2.所以我希望我写出来的代码也是很美观的,让人看起来会很舒服. 3.要想让你的代码简约美观,就要涉及封装,模块化了,可复用代码.vue可以 ...

  2. 【EverydaySport】健身笔记——背部训练

    背部训练大致可以分为两种. 1 下拉式动作 躯干纵向上下位移的动作 典型代表 这样的下拉类动作 针对的是背阔肌 也就是两边像翅膀一样的部分 2 垂直于躯干的方向作用 向内拉 主要针对的是,背部的中部 ...

  3. chromedriver版本 支持的Chrome版本

    在使用selenium测试时,如果选择chrome浏览器,需要将chrome driver的exe文件放在项目下 错误的driver版本,会导致无法正常打开本机的浏览器 以下为对应关系 来自网络 ch ...

  4. 很重要的处理项目url[www]

    http://www.xdowns.com/soft/10/57/2013/Soft_113319.html https://github.com/TricksterGuy/Morphan http: ...

  5. 2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382 题意:函数lcm(a,b):求两整数a,b的最小公倍数:函数gcd(a,b):求两整数a,b的最 ...

  6. Android端与Android端利用WIFI进行FTP通信

    一.客户端通信工具类: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; im ...

  7. C++智能指针: auto_ptr, shared_ptr, unique_ptr, weak_ptr

    本文参考C++智能指针简单剖析 内存泄露 我们知道一个对象(变量)的生命周期结束的时候, 会自动释放掉其占用的内存(例如局部变量在包含它的第一个括号结束的时候自动释放掉内存) int main () ...

  8. MySQL的七种join

    转载 原文地址 建表 在这里我们先建立两张有外键关联的两张表: CREATE DATABASE db0206; USE db0206; CREATE TABLE `db0206`.`tbl_dept` ...

  9. 用matplotlib绘制漫画风格的图表

    自从有了计算机,便很少有人手工绘制图表了.计算机绘制出的图表横平竖直,可以随意使用各种颜色,也完全不用担心画错需要重来的问题. 但有没有一种感觉,看多了工整的图表,变得有些审美疲劳.在各行各业逐渐过渡 ...

  10. StyleCop setting

    StyleCop下载地址:http://stylecop.codeplex.com/ -Documentation Rules 文档化注释规则 -Element Documentaion 变量的文档化 ...