codeforces B. Making Sequences is Fun 解题报告
题目链接: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 解题报告的更多相关文章
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
- codeforces 433C. Ryouko's Memory Note 解题报告
题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...
- codeforces 556B. Case of Fake Numbers 解题报告
题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...
- codeforces 510B. Fox And Two Dots 解题报告
题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...
- codeforces 505A. Mr. Kitayuta's Gift 解题报告
题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...
- codeforces 499A.Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...
- codeforces 374A Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行 m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...
- codeforces 471B. MUH and Important Things 解题报告
题目链接:http://codeforces.com/problemset/problem/471/B 题目意思:有 n 个 tasks,编号依次为 1 - n,每个 task 都有一定的难度值来评估 ...
随机推荐
- 关于MyEclipse对Struts2配置文件较检异常 Invalid result location value/parameter
有时候Struts.xml配置没有错误,完全可以顺利运行,而MyEclipse9以上版本却经常出现一大坨错误标识,错误信息是 Invalid result location value/paramet ...
- Oracle常用sql
Oracle不像Sqlserver,并没有提供l默认约束,但提供了默认值,效果一样.--------------------------- 在建表时设置默认约束-------------------- ...
- 38.Android之ListView简单学习(一)
android中ListView用的很普遍,今天来学习下,本篇主要以本地数据加载到listview,后面会学习从网络获取数据添加到listview. 首先改下布局文件: <?xml versio ...
- opencv笔记1:opencv的基本模块,以及环境搭建
opencv笔记1:opencv的基本模块,以及环境搭建 安装系统 使用fedora22-workstation-x86_64 安装opencv sudo dnf install opencv-dev ...
- BZOJ-1880 Elaxia的路线 SPFA+枚举
1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 921 Solved: 354 [Submit][Sta ...
- HDU2222 Keywords Search [AC自动机模板]
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- spring bean实例化方式
注意:xml配置中bean节点下scope属性默认值为singleton(单例),在需要多例的情况下需要配置成prototype spring提供三种实例化方式:默认构造.静态工厂.实例工厂 一.默认 ...
- 在不借助其他工具的情况下破解Windows开机密码
文章:http://www.cnblogs.com/vforbox/p/4828855.html#!comments. 从该文章我们也可以得到一个快速启动某个程序的方法:将自己常用的程序命名为seth ...
- 使用migrate.exe执行EF code first 迁移
Code First 迁移可用于从 Visual Studio 内部更新数据库,但也可通过命令行工具 migrate.exe 来执行.本页简单介绍如何使用 migrate.exe 对数据库执行迁移. ...
- swift中文文档翻译之--字符串和字符
字符串和字符 A string is an ordered collection of characters, such as "hello, world" or "al ...