文章目录
- [L-Need Zero](#L-Need Zero)
- K-Constructive
- [C-Array Covering](#C-Array Covering)
- [E-Block Game](#E-Block Game)
- [B-Card Game](#B-Card Game)
L-Need Zero
解题思路
个位数的情况只有0~9,个位数为1,3,7,9时,x最小为10;个位数为5时,x最小为2;个位数为0时,x最小为1;个位数为52,6,8时,x最小为5;
代码实现
cpp
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
const int N=1e6+6;
int n;
void solve()
{
cin>>n;
int x=n%10,k;
if(x==1||x==3||x==7||x==9)k=10;
else if(x==5)k=2;
else if(x==0)k=1;
else k=5;
cout<<k<<endl;
}
signed main()
{
IOS;
int _=1;
// cin>>_;
while(_--)
solve();
return 0;
}
K-Constructive
解题思路
通过举例各种情况可得,只有n=1或3有满足情况的数组,当n=1时,数组:1。当n=3时,数组:1 2 3.可证明当n为其他数时不可能有满足情况的数组。
代码实现
cpp
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
const int N=1e6+6;
int n,a[N];
void solve()
{
cin>>n;
if(n==1)
{
cout<<"YES"<<endl;
cout<<1<<endl;
return ;
}
else if(n==3)
{
cout<<"YES"<<endl;
cout<<"1 2 3"<<endl;
return ;
}
else
cout<<"NO"<<endl;
}
signed main()
{
IOS;
int _=1;
cin>>_;
while(_--)
solve();
return 0;
}
C-Array Covering
解题思路
由于可以选择将开区间内的每个数变为端点最大值,可证明除了最左边和最右边端点不能改变,其余数都可以改变为数组中的最大值,再将结果相加即可,注意范围要开long long。
代码实现
cpp
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
const int N=1e6+6;
int n,a[N];
void solve()
{
cin>>n;
int mx=-1;
for(int i=1;i<=n;i++)
{
cin>>a[i];
mx=max(mx,a[i]);
}
if(n==1)cout<<a[1]<<endl;
else if(n==2)cout<<(a[1]+a[2])<<endl;
else cout<<(mx*(n-2)+a[1]+a[n])<<endl;
}
signed main()
{
IOS;
int _=1;
cin>>_;
while(_--)
solve();
return 0;
}
E-Block Game
解题思路
这道题简而言之就是在一个数组的最左侧插入一个数字,并也与最后一个数相连构成一个环,求这个环中相邻两个元素的最大值。
代码实现
cpp
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
const int N=1e6+6;
int n,a[N],k;
void solve()
{
cin>>n>>k;
a[0]=k;
int mx=-1e18;
for(int i=1;i<=n;i++)
{
cin>>a[i];
mx=max(a[i]+a[i-1],mx);
}
mx=max(mx,k+a[n]);
cout<<mx<<endl;
}
signed main()
{
IOS;
int _=1;
cin>>_;
while(_--)
solve();
return 0;
}
B-Card Game
解题思路
可以证明将大于小红最小牌的牌都放前面得分最多。我们只需要先算出小苯的牌中,大于小红的最小牌mi的数量m1,将大于mi的牌放在前面,有m1!种排列方式,剩下的小于mi的牌没有利用价值,放在后面,有(n-m1)!种排列方式,因此最终的组合方式就是二者之积。
代码实现
cpp
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define PII pair<int,int>
#define fi first
#define se second
#define endl '\n'
const int N=1e6+6;
const int mod=998244353;
int n,a[N],b[N],k;
int Jie(int x1,int x2)
{
int s1=1,s2=1;
for(int i=1;i<=x1;i++)
{
s1=(s1*i)%mod;
}
for(int i=1;i<=x2;i++)
{
s2=(s2*i)%mod;
}
if(x1==0)return s2;
if(x2==0)return s1;
return (s1*s2)%mod;
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
int mi=1e18;
for(int i=1;i<=n;i++)
{
cin>>b[i];
mi=min(mi,b[i]);
}
int m1=0;//大于b中最小值的
for(int i=1;i<=n;i++)
{
if(a[i]>mi)m1++;
}
int m2=n-m1;
// cout<<m1<<" "<<m2<<endl;
int ans=Jie(m1,m2);
cout<<ans<<endl;
}
signed main()
{
IOS;
int _=1;
cin>>_;
while(_--)
solve();
return 0;
}