数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

题目传送门

 1 /*
 2     数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了
 3         另外不足一个区间的直接计算个数就可以了
 4 */
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <iostream>
 8 #include <algorithm>
 9 #include <cstring>
10 using namespace std;
11
12 typedef unsigned long long ull;
13 int get_len(ull x)
14 {
15     int ret = 0;
16     while (x) {
17         x /= 10;    ret++;
18     }
19     return ret;
20 }
21
22
23 int main(void)      //Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
24 {
25     //freopen ("B.in", "r", stdin);
26
27     ull w, m, k;
28     while (cin >> w >> m >> k) {
29         int len = get_len (m);   ull mx = 0;
30         for (int i=1; i<=len; ++i) {
31             mx = mx * 10 + 9;
32         }
33
34         ull ans = 0; ull cost = (mx - m + 1) * k * len;
35         while (cost <= w) {
36             w -= cost;  ans += (mx - m + 1);
37             len++;  m = mx + 1; mx = mx * 10 + 9;
38             cost = (mx - m + 1) * k * len;
39         }
40
41         ans += w / (len * k);
42         cout << ans << endl;
43     }
44
45     return 0;
46 }

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <cstring>
 6 using namespace std;
 7
 8 typedef long long ll;
 9 int get_len(ll x)
10 {
11     int ret = 0;
12     while (x) {
13         x /= 10;    ret++;
14     }
15     return ret;
16 }
17
18
19 int main(void)      //Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
20 {
21     //freopen ("B.in", "r", stdin);
22
23     ll w, m, k;
24     while (scanf ("%I64d%I64d%I64d", &w, &m, &k) == 3) {
25         int len = get_len (m);   ll mx = 0;
26         for (int i=1; i<=len; ++i) {
27             mx = mx * 10 + 9;
28         }
29
30         ll ans = 0, now = 0, tot = 0;
31         while (true) {
32             now = mx - m + 1;   tot = w / (k * len);
33             if (now < tot) {
34                 ans += now; w -= now * k * len;
35                 m = mx + 1; mx = mx * 10 + 9;   len++;
36             }
37             else {
38                 ans += tot; break;
39             }
40         }
41
42         printf ("%I64d\n", ans);
43     }
44
45     return 0;
46 }

按个数比较

时间: 2024-07-28 14:54:36

数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun的相关文章

贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

题目传送门 1 /* 2 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 using namespace std; 8 9 const int MAXN = 11; 10 const int INF = 0x3f3f3f3f; 11 char s[MAXN][MAXN]; 12 1

数学 Codeforces Round #282 (Div. 2) B. Modular Equations

题目传送门 题意:a % x == b,求符合条件的x有几个 数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1,那么24,12, 8, 6, 4, 3, 2都可以,所以只要求出k的约数有几个就可以了,a <= b的情况要特判 /************************************************* Author        :Running_Time* Created Time  

数学 Codeforces Round #308 (Div. 2) B. Vanya and Books

题目传送门 1 /* 2 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <vector> 10 #include <string> 11 #inc

Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)

题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二点 gcd(a[i],a[i-1])>1 也就是说两个数不能互质 找出最长的子序列长度 思路:首先想互质问题,如果两个数互质说明两个数之间没有素因子相同,我们想以每个素因子结尾的最大长度是多少 然后比如样例 2 3 4 6 9 第一个数 2      2结尾 1 第二个数 3      3结尾 1 第三

Codeforces Round #631 (Div. 2) Dreamoon Likes Sequences

题面很短,别的博客也讲了就不说题意了. 做法: 异或是没有进位的加法,所以ai + 1的二进制最高位要大于ai的二进制最高位,才能满足ai递增,bi也递增的条件.呐这样的话,选了4,(5,6,7)就都不能选了,只能选比7大的数. 这样分析下来a数组最长也只有30,(2^30>1e9) 直接按照数字大小dp会TLE 思路角度1:换一个角度,我们把二进制最高位相同的看作一组,因为这一组内只能选一个数. 有点像分组背包.但是我们现在只看分组背包的方案数,所以就不用枚举每一组内的物品了. dpij表示考

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)

题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是所有最大值是xi的情况数/总情况数一共是m^n种,掷n次,所有最大值是xi的情况数应该是xi^n,但是这里边却包含着最大值非xi且不超过xi的种数,所以再减去最大值是xi-1或者最大值不超过这个的情况数.即sum += xi * (xi^n-(xi-1)^n)/m^n,但是这样求肯定是不行,因为m

Codeforces Round #360 (Div. 2) D 数学推导 E dp

Codeforces Round #360 (Div. 2) A  == B  水,但记一下: 第 n 个长度为偶数的回文数是  n+reverse(n). C    dfs 01染色,水 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i

数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

题目传送门 1 /* 2 题意:这题就是求b+1到a的因子个数和. 3 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 4 */ 5 /************************************************ 6 Author :Running_Time 7 Created Time :2015-8-1 14:08:34 8 File Name :B.cpp 9 ******************************