codeforces#219_div2_B Making Sequences is Fun
来源:互联网 发布:mac word 勾选 编辑:程序博客网 时间:2024/06/08 15:54
题目地址:cf#219_div2_B
一个很奇怪的数列求和,项数有可能特别多,但是很多相邻的都是一样的,我们一起加上去,这样就不会超时
wa了很多次因为精度,首先取出多少位数就不要用log(k)/log(10); 太容易误差了,用while() 保险。
代码:
#include<iostream>#include<cmath>#include<utility>#include<vector>#include<algorithm>using namespace std;typedef pair<int,int> pii;typedef long long inta;inta mypow(inta a,int n){ inta ans=1; for(int i=0;i<n;i++) { ans*=a; } return ans;}int main(){ inta w,m,k; cin>>w>>m>>k; inta all=w/k; inta ans=0; // int a=floor(log(m)/log(10)); int a=0; while(mypow(10,a)<=m) { a++; } a--; inta b=mypow(10, a+1);; if(all<=(b-m)*(a+1)) { //cout<<"jingqi"<<endl; ans=all/(a+1); } else { ans=b-m; inta cur=(b-m)*(a+1); int t=0; // cout<<ans<<endl; while(cur<all) { //cout<<cur<<endl; if(all-cur<9LL*b*mypow(10,t)*(a+2+t)) { ans+=(all-cur)/(a+2+t); break; } else { ans+=9LL*b*mypow(10,t); cur+=9LL*b*mypow(10,t)*(a+2+t); //cout<<t<<endl; t++; } } } cout<<ans<<endl; }
0 0
- codeforces#219_div2_B Making Sequences is Fun
- CodeForces 373 B. Making Sequences is Fun
- CodeForces 373B Making Sequences is Fun
- CodeForces 373B Making Sequences is Fun
- codeforces#373B.Making Sequences is Fun
- Making Sequences is Fun(简单枚举)
- Making AI Fun: When Good Enough is Good Enough
- codeforces#237_div2_B Marathon
- Codeforces Round #219 (Div. 2) Counting Kangaroos is Fun
- Codeforces Round #219 (Div. 1) A. Counting Kangaroos is Fun
- Codeforces #219 (Div. 2) C. Counting Kangaroos is Fun
- Codeforces #219 (Div. 2) A. Collecting Beats is Fun
- Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun
- Codeforces Round #219 (Div. 2) E. Watching Fireworks is Fun
- Codeforces Round #219 (Div. 2)--C. Counting Kangaroos is Fun
- CodeForces 372 A. Counting Kangaroos is Fun
- CodeForces 372B. Counting Rectangles is Fun
- 【CodeForces】[372A]Counting Kangaroos is Fun
- 究竟什么是敏捷测试
- 第六周项目一-体验常成员函数
- Android Notes(06) - Touch事件分发响应机制
- java组合模式实例
- Ubuntu Unity上修改应用程序图标
- codeforces#219_div2_B Making Sequences is Fun
- 喜欢现在的生活
- Spring学习流程(马士兵笔记)
- C++builder ini 读写
- NYOJ-42 一笔画问题
- 安装Node.js提示NVM Needs curl to process!
- Windows下Cygwin环境的Hadoop安装(1)- Cygwin安装和配置
- Hibernate查询缓存全面分析
- 操作系统概论----文件管理