-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20240307 tsreaper's submission (#140)
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
daily_problems/2024/03/0307/personal_submission/cf453a_tsreaper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
double power(double a, int b) { | ||
double y = 1; | ||
for (; b; b >>= 1) { | ||
if (b & 1) y *= a; | ||
a *= a; | ||
} | ||
return y; | ||
} | ||
|
||
int main() { | ||
int m, n; scanf("%d%d", &m, &n); | ||
double ans = 0; | ||
for (int i = 1; i <= m; i++) { | ||
double t = power(1.0 * i / m, n) - power(1.0 * (i - 1) / m, n); | ||
ans += t * i; | ||
} | ||
printf("%.9f\n", ans); | ||
return 0; | ||
} |
42 changes: 42 additions & 0 deletions
42
daily_problems/2024/03/0307/personal_submission/cf855e_tsreaper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <bits/stdc++.h> | ||
#define MAXB 10 | ||
#define MAXP 60 | ||
using namespace std; | ||
|
||
vector<int> A; | ||
long long f[MAXB + 1][MAXP][2][1 << MAXB]; | ||
|
||
long long dp(int b, int pos, int full, int bgn,int msk) { | ||
if (pos < 0) return msk == 0; | ||
long long ret = f[b][pos][bgn][msk]; | ||
if (!full && ret >= 0) return ret; | ||
ret = 0; | ||
|
||
int R = (full ? A[pos] : b - 1); | ||
for (int i = 0; i <= R; i++) { | ||
int nxtBgn = bgn || i > 0; | ||
int nxtMsk = msk; | ||
if (nxtBgn) nxtMsk ^= 1 << i; | ||
ret += dp(b, pos - 1, full && i == R, nxtBgn, nxtMsk); | ||
} | ||
if (!full) f[b][pos][bgn][msk] = ret; | ||
return ret; | ||
} | ||
|
||
long long solve(long long X, int b) { | ||
A.clear(); | ||
for (; X; X /= b) A.push_back(X % b); | ||
return dp(b, A.size() - 1, 1, 0, 0); | ||
} | ||
|
||
int main() { | ||
memset(f, -1, sizeof(f)); | ||
int tcase; scanf("%d", &tcase); | ||
while (tcase--) { | ||
int b; | ||
long long l, r; | ||
scanf("%d%lld%lld", &b, &l, &r); | ||
printf("%lld\n", solve(r, b) - solve(l - 1, b)); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters