无限区域

《模拟》

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int t;
cin >> t;
double pi = acos(-1);
for (int i = 1; i <= t; i ++)
{
int r, a, b;
cin >> r >> a >> b;
double ans = 0;
while (r)
{
ans += pi * r * r;
r *= a;
ans += pi * r * r;
r /= b;
}
printf("Case #%d: %.12f\n", i, ans);
}
}

交替数字和

《模拟》

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
int alternateDigitSum(int n) {
int ans = 0;
string str = to_string(n);
int pre = 1;
for (auto ch : str)
{
ans += pre * (ch - '0');
pre *= -1;
}

return ans;
}
};