A Exponential or Quadratic
第一题的意思是判断2n>n2?,如果大于就输出“Yes”, 否则输出“No”
可以使用数学函数pow求得数判断:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin >> n;
if(pow(2, n)>pow(n, 2))
cout << "Yes";
else
cout << "No";
return 0;
}
也可以通过函数的增长趋势判断:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
if(n==1)
{
cout << "Yes";
return 0;
}
if(n>4)
cout << "Yes";
else
cout << "No";
return 0;
}
B Pizza
题意:一个圆盘,按输入的数据转着切,最后最大的一块的圆心角是多少。
思路:模拟,使用vector记录切到的点,最后判断最大角。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin >> n;
int now = 0;
int temp;
vector<int> a;
a.push_back(0);
a.push_back(360);
for(int i=0;i<n;i++)
{
cin >> temp;
now = (temp+now)%360;
a.push_back(now);
}
sort(a.begin(), a.end());
int ans = 0;
for(int i=0;i<n+1;i++)
ans = max(ans, a[i+1]-a[i]);
cout << ans;
return 0;
}
C digitnum
题意:这道题的题意挺绕,函数f(x),代表不超过x的相同位数的个数,例如f(15) = 6,因为不超过15的二位数有10,11,12,13,14,15,6个数字。
思路,一位一位的判断,使用等差数列的求和公式。
#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
typedef long long ll;
int main()
{
ll n, m, l, h, add, ans;
cin >> n;
m = 1;
ans = 0;
while(m <= n)
{
l = 1;
h = min(m*10-1, n)-m+1;
add = ((h+l)%mod*(h%mod)/2)%mod;
ans = (ans+add)%mod;
m*=10;
}
cout << ans;
return 0;
}