BUPT OJ189 Draw Bones

本文提供了一种高效方法来计算完成特定任务所需的最少操作数,涉及图形绘制、删除、复制和粘贴。适用于解决生日礼物骨画的编程问题。

题目描述

Miss Cat wants to draw a picture as a present for Mr. Dog's birthday. Knowing bones are dogs' favorite, Miss Cat decides to draw some bones. Since it's Mr. Dog's N-th birthday, N identical bones are needed. To complete this task, Miss Cat can do one of the four following operations every time.

(1) Draw: draw a single bone.

(2) Delete: delete a single bone that has already existed.

(3) Copy: copy all the existing bones to the clipboard.

(4) Paste: paste clipboard contents to current picture.

Please note that the content in clipboard changes only after you perform a copy operation. In the beginning, both the picture and the clipboard are empty.

Now, Miss Cat wants to complete the picture as soon as possible. Please help her to calculate how many operations she needs at least.

输入格式

Input file consists of multiple test cases, ended by EOF. Every case contains only one integer N(0<N2000). The number of test cases will not exceed 2000.

输出格式

Output one line containing the answer for every case.

输入样例

2
4
6

输出样例

2
4
5

数据不大, 显然可以打大小为2000的表来完成.

下面是毫无技术含量的暴力打表.

话说最近single number的AC率提高显著啊233 是什么原因我也很好奇啊



/*
USER_ID: test#birdstorm
PROBLEM: 189
SUBMISSION_TIME: 2014-03-18 02:01:44
*/
#include <stdio.h>
#define For(i,m,n) for(i=(m);i<(n);i++)
#define MIN(x,y) (x)<(y)?(x):(y)
#define MAXN 2005
  
int cnt[MAXN];
  
int calc(int x)
{
    int i, add, mult, smaller, min = x;
    For(i,1,x) {
        add = x - i;
        mult = x % i == 0 ? x / i : ((x / i + 1) * i - x) + (x / i + 1);
        smaller = MIN(mult, add);
        min = MIN(min, smaller + cnt[i]);
    }
    cnt[x] = min;
}
  
main()
{
    int i, j, n, x;
    cnt[1] = 1;
    For(i,2,2001) calc(i);
    while(scanf("%d",&x)!=EOF) printf("%d\n",cnt[x]);
    return 0;
}


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值