题目链接:http://codeforces.com/problemset/problem/373/B

题目意思:给出w,m和k,需要找出从m开始,可以有多少个连续的数(m+1,m+2,...)(在添加(m+i)这个数到序列时,需要付出s(m+i) * k的代价,i = 1,2,...)满足不超过总代价w的长度。

可以列一个这样的方程:

  一位数的个数*1*k + 两位数的个数*2*k + 三位数的个数*2*k + ... + n位数的个数*n*k = w

化简后得到:

  一位数的个数*1 + 两位数的个数*2 + 三位数的个数*2 + ... + n位数的个数*n = w / k

思路就是:得出m是一个几位数(假设为len)——> m要到达len+1位数时还需要多少个len位数 ——> 代价 w 更新。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std; int main()
{
__int64 w, m, k, i, res, tmp, num; while (scanf("%I64d%I64d%I64d", &w, &m, &k) != EOF)
{
w /= k;
int len = ;
// 判断m是几位数(len)
for (tmp = m; tmp; tmp /= )
len++;
// 赋予num最大的len位数(10,100,1000, ...)
num = ;
for (i = ; i <= len; i++)
num *= ;
for (res = , i = len; ;i++)
{
if (w - (num-m) * i >= ) // i位数里有多少个k
{
w -= i * (num-m);
res += num - m;
m = num;
num *= ;
}
else // w 不足num-m
{
res += w/i;
break;
}
}
printf("%I64d\n", res);
}
return ;
}

codeforces B. Making Sequences is Fun 解题报告的更多相关文章

  1. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  2. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  3. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  4. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  5. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  6. codeforces 505A. Mr. Kitayuta's Gift 解题报告

    题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...

  7. codeforces 499A.Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...

  8. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

  9. codeforces 471B. MUH and Important Things 解题报告

    题目链接:http://codeforces.com/problemset/problem/471/B 题目意思:有 n 个 tasks,编号依次为 1 - n,每个 task 都有一定的难度值来评估 ...

随机推荐

  1. Android4.4中不能发送SD卡就绪广播

    当在Android上进行图片的扫描功能开发时一般会使用:sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(“file:// ...

  2. BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式

    1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3662 Solved: 1910 [Subm ...

  3. myEclipse中新建的项目导入到Eclipse之后项目出现一个红色的叉叉

    1.在eclipse中打开Problems,然后看看报哪些错,

  4. BZOJ1202 狡猾的商人

    HNOI2005 Day1 T4 Description 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1, ...

  5. UVa 1347 Tour

    Tour Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description   Joh ...

  6. sourceinsight安装记录

    sourceinsight安装记录 此文章为本人使用sourceinsight一个星期之后的相关设置步骤记录和经验记录,以备以后查验,网上的相关资料都也较为完善,但是对于新手还是有一定困难的,所以在这 ...

  7. Support Vector Machines for classification

    Support Vector Machines for classification To whet your appetite for support vector machines, here’s ...

  8. hdu 2041 超级楼梯

    斐波那契数列,看清题意,当前为第一阶,给出M(每次只能跨1阶或2阶) 从第一阶到M,若M=1,从1-1不用走,0种方法 若M=2 从1-2  一种方法  -> 1.走一次一阶 若M=3 从1-3 ...

  9. WPF 显示gif

    using System; using System.IO; using System.Collections.Generic; using System.Windows; using System. ...

  10. Caused by: java.lang.NoSuchFieldError: TRACE

    Caused by: java.lang.NoSuchFieldError: TRACE at org.slf4j.impl.Log4jLoggerAdapter.trace(Log4jLoggerA ...