A
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
signed main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
int t=0;
while(n>3)
{
n=n/4;
t++;
}
int ans=1;
for(int i=1;i<=t;i++)
ans*=2;
cout<<ans<<endl;
}
return 0;
}
B
数位和为9 3倍数得可以整除9 3
个位为0或5得可整除5
至于7可拆解运算 https://www.cnblogs.com/matinalcosmos/p/18634230
#include <bits/stdc++.h>
using namespace std;
int n,d;
int a[6]={0,1,3,5,7,9};
vector<int>v;
int main()
{
//cout<<8*7*6*5*4*3*2*5;
int T;
cin>>T;
while(T--)
{
v.clear();
cin>>n>>d;
bool st=0;
int ans=1;
for(int i=2;i<=min(int(9),n);i++)
ans*=i;
ans*=d;
//cout<<ans<<endl;
if(ans%3==0)v.push_back(3);
if(ans%9==0)v.push_back(9);
if(d==0||d==5)
v.push_back(5);
v.push_back(1);
if(d%7==0||n>=3)
v.push_back(7);
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<endl;
}
return 0;
}
C
我们可以找到不为1和-1的数分开考虑 左侧右侧得最大最小值即为最大最小子段和dp即可 注意段长可以取0 对于加上x后数值取值范围(不可以用子段和,无法确定子段是否与x直接相连)则需要计算出x左侧的最大后缀和右侧得最大前缀和
#include<bits/extc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 5;
int n,val,pos,sum;
int max1,min1,max2,min2;
int a[maxn],dp1[maxn],dp2[maxn];
set<int>s;
void solve()
{
s.clear();
cin>>n;
pos=val=0;
for (int i=1;i<=n;i++)
{
cin>>a[i];
if (a[i]!=1&&a[i]!=-1)
{
val=a[i];
pos=i;
}
}
max1=-1e18;
min1=1e18;
for(int i=1;i<=n;i++)
dp1[i]=dp2[i]=0;
for(int i=1;i<=pos-1;i++)
{
dp1[i]=max(a[i],dp1[i-1]+a[i]);
max1=max(max1,dp1[i]);
dp2[i]=min(dp2[i-1]+a[i],a[i]);
min1=min(min1,dp2[i]);
}
max1=max(max1,0ll);
min1=min(min1,0ll);
//cout<<max1<<" "<<min1<<endl;
max2=-1e18;
min2=1e18;
for(int i=pos+1;i<=n;i++)
{
dp1[i]=max(a[i],dp1[i-1]+a[i]);
max2=max(max2,dp1[i]);
dp2[i]=min(dp2[i-1]+a[i],a[i]);
min2=min(min2,dp2[i]);
}
max2=max(max2,0ll);
min2=min(min2,0ll);
//cout<<max2<<" "<<min2<<endl;
for(int i=min(min1,min2);i<=max(max1,max2);i++)
s.insert(i);
int sum=0;
int mx1=-1e18,mn1=1e18;
for(int i=pos-1;i>=1;i--)
{
sum+=a[i];
mx1=max(mx1,sum);
mn1=min(mn1,sum);
}
mx1=max(mx1,0ll);
mn1=min(mn1,0ll);
//cout<<mx1<<" "<<mn1<<endl;
int mx2=-1e18,mn2=1e18;
sum=0;
for(int i=pos+1;i<=n;i++)
{
sum+=a[i];
mx2=max(mx2,sum);
mn2=min(mn2,sum);
}
mx2=max(mx2,0ll);
mn2=min(mn2,0ll);
//cout<<mx2<<" "<<mn2<<endl;
for(int i=val+mn1+mn2;i<=val+mx1+mx2;i++)
s.insert(i);
cout<<s.size()<<endl;
for(auto x:s)
cout<<x<<" ";
cout<<endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}