A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 50;
struct node {
int x, r;
int l, R;
}a[N];
bool cmp(node an, node bn) {
return an.l < bn.l;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].r;
a[i].R = a[i].x + a[i].r;
a[i].l = a[i].x - a[i].r;
}
sort(a + 1, a + n + 1, cmp);
long long ans = 0;
int end = a[1].R;
for (int i = 2; i <= n; i++)
{
if (a[i].l > end)
{
ans += (a[i].l - end);
end = a[i].R;
}
else {
if (end < a[i].R) {
end = a[i].R;
}
}
}
cout << ans << endl;
return 0;
}
G
// 1 616
//
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
string a;
cin >> a;
int idx = 0;
if (a[0] == '9') {
int flag = 0;
for (int i = 0; i < a.size() - 1 ; i++) {
if (a[i] != '9') {
flag = 1;
break;
}
}
if (flag == 0) {
cout << a;
}
else {
for (int i = 1; i <= a.size() - 1 ; i++) {
cout << 9;
}
}
}
else {
if (a == "1" || a == "2" || a == "3" || a == "4" || a == "5" || a == "6" || a == "7" || a == "8" || a == "9") {
cout << a;
}
else {
for (int i = 1; i <= a.size() - 1; i++) {
cout << "9";
}
}
}
return 0;
}
D
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 50;
const double pi = acos(-1);
int main()
{
int t;
cin >> t;
while (t--) {
double r;
cin >> r;
double x, y, d;
cin >> x >> y >> d;
double dis = sqrt(x * x + y * y);
double a_x = dis - d;
double b_x = dis + d;
// 两侧
if (a_x * b_x < 0) {
double jd1 = acos(fabs(a_x) / r);
//jd1 = arccos(a_x/r)
double jd2 = acos(fabs(b_x) / r);
double jd = pi - jd1 - jd2;
printf("%.12f\n", jd * r);
}
else if (a_x < 0 && b_x <= 0) {
// 一侧
double jd2 = acos(fabs(b_x) / r);
double jd1 = acos(fabs(a_x) / r);
double jd = abs(jd1 - jd2);
printf("%.12f\n", jd * r);
}
else {
double jd2 = acos(fabs(b_x) / r);
double jd1 = acos(fabs(a_x) / r);
double jd = abs(jd1 - jd2);
printf("%.12f\n", jd * r);
}
}
return 0;
}