题目大意:
解法:
#include
#include
using namespace std;
int main()
{
string s;
cin >> s;
if(s.size() == 1) cout << s << endl;
else
{
int flag = 0;
for(int i = 0;i < s.size() - 1;i ++)
if(s[i] != '9')
{
flag = 1;
break;
}
if(!flag) cout << s << endl;
else
{
for(int i = 1;i < s.size();i ++) cout << "9";
cout << endl;
}
}
return 0;
}
题目大意:
解法:
#include
#include
#include
using namespace std;
typedef pair<int, int> pii;
bool cmp(pii a, pii b)
{
if(a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
int main()
{
vector<pii> q;
int n;
cin >> n;
for(int i = 1;i <= n;i ++)
{
int x, d;
cin >> x >> d;
q.push_back({x - d, x + d});
}
sort(q.begin(), q.end(), cmp);
vector<pii> p;
int l = q[0].first, r = q[0].second;
for(int i = 1;i < q.size();i ++)
{
if(q[i].first <= r)
{
r = max(r, q[i].second);
}
else
{
p.push_back({l, r});
l = q[i].first, r = q[i].second;
}
if(i == q.size() - 1)
p.push_back({l, r});
}
int res = 0;
for(int i = 1;i < p.size();i ++) res += (p[i].first - p[i - 1].second);
cout << res << endl;
return 0;
}
题目大意:
解法:
#include
#include
#include
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
double r, x, y, d;
scanf("%lf %lf %lf %lf", &r, &x, &y, &d);
double dist = sqrt(x * x + y * y);
double d1 = acos((dist - d) / r);
double d2 = acos((dist + d) / r);
printf("%.12lf\n", r * (d1 - d2));
}
}