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 都有一定的难度值来评估 ...
随机推荐
- 【Aizu 2305】Beautiful Currency
题 题意 给你n个货币价格,然后通过调整一些货币的大小,使得所有比自己小的货币都是该货币的约数,调整前第 i 货币为a,调整后为b 那么变化率为 ri=|a-b|/a ,总变化率为max(ri).求最 ...
- 【Gym 100610A】Alien Communication Masterclass
题 Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The mos ...
- Codeforces Round #342 (Div 2) 解题报告
除夕夜之有生之年CF第一场 下午从奶奶家回到姥姥家,一看还有些时间,先吃点水果陪姥姥姥爷聊了会儿,再一看表,5:20....woc已经开场20分钟了...于是抓紧时间乱搞.. **A. Guest F ...
- spring全注解项目
项目结构如下: spring配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&q ...
- MVC模式的学生信息增删改查
准备:建一个名为 userdb的数据库.建一个student表,有stuid,stuname,gender三个字段.其中stuid为主键.j加入相应的驱动包,相应的JSTL标签 先看目录结构 代码: ...
- Spring学习8-用MyEclipse搭建SSH框架 Struts Spring Hibernate
1.new一个web project. 2.右键项目,为项目添加Struts支持. 点击Finish.src目录下多了struts.xml配置文件. 3.使用MyEclipse DataBase Ex ...
- iptables 工具
iptables 工具 参考文档: https://www.frozentux.net/iptables-tutorial/cn/iptables-tutorial-cn-1.1.19.html ...
- nginx负载均衡器处理session共享的几种方法(转)
1) 不使用session,换作cookie 能把session改成cookie,就能避开session的一些弊端,在从前看的一本J2EE的书上,也指明在集群系统中不能用session,否则惹出祸端来 ...
- ashx 获取ajax Post到后台json数据
前台页面代码: var json = [{ "Name": "Pavan Kumar Pabothu", "Age": 27, " ...
- (转) 新的开始之Win7、CentOS 6.4 双系统 硬盘安装
http://blog.csdn.net/cnclenovo/article/details/11358447