A - Exponential or Quadratic
B - Pizza
C - digitnum
A - Exponential or Quadratic
思路: 先将n变成
n
2
n^2
n2用一个变量
a
a
a储存起来,用一个循环从1遍历到
n
n
n
看看
2
n
2^n
2n会不会在某个时候与
n
2
n^2
n2相等。
code:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int n;
cin>>n;
ll b=n*n;
for(int i=1;i<=n;i++)
{
ll a=pow(2,i);
if(a>b){cout<<"Yes"<<endl;return 0;}
}
cout<<"No"<<endl;
return 0;
}
B - Pizza
思路: 用一个动态数组来储存每次切的角度,最后排序求之间最大差值即可。还有一点需要注意的就是0和360都要放进数组里。
code:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
int n,now=0;
vector<int>q;
cin>>n;
q.push_back(0);
while(n--)
{
int k;
cin>>k;
now+=k;
now%=360;
q.push_back(now);
}
q.push_back(360);
sort(q.begin(),q.end());
int res=0;
for(int i=1;i<q.size();i++)
res=max(res,q[i]-q[i-1]);
cout<<res<<endl;
return 0;
}
C - digitnu
思路: 观察 f ( 1 ) ∼ f ( n ) f(1)\sim f(n) f(1)∼f(n)可以将 n n n分割成 ( 1 ∼ 9 ) (1\sim 9) (1∼9), ( 10 ∼ 99 ) (10 \sim 99) (10∼99)… ( x , n ) (x,n) (x,n),在这个过程成就可以分开计算其和值。然后本题还有一个点需要注意,那就是取模,这里到某个时候和值会很大,然后观察可以发现等差数列的性质,求和就可以像下面这样子写:
ll calc(ll x)
{
x%=mod;
ll res=x;
res*=(x+1);
res%=mod;
res*=inv2;//这里相当于除以2操作,inv2的值为mod的两倍
res%=mod;
return res;
}
完整代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 998244353, inv2 = 499122177;
ll calc(ll x)
{
x%=mod;
ll res=x;
res*=(x+1);
res%=mod;
res*=inv2;
res%=mod;
return res;
}
int main()
{
ll n;
cin>>n;
ll res=0,p10=10;
for(int i=1;i<=18;i++)
{
ll l=p10/10;
ll r=min(n,p10-1);
if(l<=r)
{
res+=calc(r-l+1);
res%=mod;
}
p10*=10;
}
cout<<res<<endl;
return 0;
}