问题 A: 幸运数字
思路:直接把N当成字符串读入,循环判断是否有一位是7就可以了。
#include <bits/stdc++.h>//#include<iostream>//#include<string.h>//#include<math.h//#include<algorithm>
#define ll long long
#define db double
#define pii pair<int,int>
#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<<endl;
#define mem(x,v) memset(x,v,sizeof(x))
#define L(x) x&(-x)
#define pb push_back//emplace_back//priority_queue <int,vector<int>,greater<int> > q;
#define INF 0x3f3f3f3f
#define endl '\n'
//function<void(int)> dfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
string a;
bool ok=0;
cin>>a;
for(auto i:a){
if(i=='7')ok=1;
}
cout<<(ok?"Yes":"No")<<endl;
}
问题 B: 幸运数字2
思路:直接暴力从1到N判断是不是幸运数字,如果是答案就加上它。
#include <bits/stdc++.h>//#include<iostream>//#include<string.h>//#include<math.h//#include<algorithm>
#define ll long long
#define db double
#define pii pair<int,int>
#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<<endl;
#define mem(x,v) memset(x,v,sizeof(x))
#define L(x) x&(-x)
#define pb push_back//emplace_back//priority_queue <int,vector<int>,greater<int> > q;
#define INF 0x3f3f3f3f
#define endl '\n'
//function<void(int)> dfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n;
ll res=0;
for(int i=1;i<=n;i++){
if(i%3&&i%5)res+=i;
}
cout<<res<<endl;
}
问题 C: gcd问题
思路:直接K三方+辗转相除法暴力求解就行。
#include <bits/stdc++.h>//#include<iostream>//#include<string.h>//#include<math.h//#include<algorithm>
#define ll long long
#define db double
#define pii pair<int,int>
#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<<endl;
#define mem(x,v) memset(x,v,sizeof(x))
#define L(x) x&(-x)
#define pb push_back//emplace_back//priority_queue <int,vector<int>,greater<int> > q;
#define INF 0x3f3f3f3f
#define endl '\n'
//function<void(int)> dfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n;
ll res=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
int t=gcd(i,j);
for(int k=1;k<=n;k++){
res+=gcd(t,k);
}
}
}
cout<<res<<endl;
}
问题 D: RGB
思路:先求出满足条件1的所有答案,就是R的个数×G的个数×B的个数,然后枚举i和j,得出不满足条件2的k,然后判断i,j,k是否满足条件1,如果满足则把它从答案中减去。
#include <bits/stdc++.h>//#include<iostream>//#include<string.h>//#include<math.h//#include<algorithm>
#define ll long long
#define db double
#define pii pair<int,int>
#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<<endl;
#define mem(x,v) memset(x,v,sizeof(x))
#define L(x) x&(-x)
#define pb push_back//emplace_back//priority_queue <int,vector<int>,greater<int> > q;
#define INF 0x3f3f3f3f
#define endl '\n'
//function<void(int)> dfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=998244353;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n;
string a;
cin>>a;
ll r=0,g=0,b=0;
for(int i=0;i<n;i++){
if(a[i]=='R')r++;
else if(a[i]=='G')g++;
else b++;
}
ll res=r*b*g;
for(int i=0;i<n;i++){
for(int j=1;;j++){
int ii=i+j,jj=ii+j;
if(jj>=n)break;
if(a[i]!=a[ii]&&a[i]!=a[jj]&&a[ii]!=a[jj])res--;
}
}
cout<<res<<endl;
}
问题 E: gcd问题2
思路:设f[i]等于gcd(a1,a2,...,an)=i的a数组的个数,那么k中可以被i整除的数的个数有k/i,但是f[i]不等于k/i的n次方,因为其中还包含gcd(a1,a2,...,an)=i的倍数的a数组,所以要减去f[j](j=i的倍数,最后f[i]*i求和即可得到答案。
#include <bits/stdc++.h>//#include<iostream>//#include<string.h>//#include<math.h//#include<algorithm>
#define ll long long
#define db double
#define pii pair<int,int>
#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<<endl;
#define mem(x,v) memset(x,v,sizeof(x))
#define L(x) x&(-x)
#define pb push_back//emplace_back//priority_queue <int,vector<int>,greater<int> > q;
#define INF 0x3f3f3f3f
#define endl '\n'
//function<void(int)> dfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=1e9+7;
int n,k;
ll f[100005];
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n>>k;
for(int i=k;i>=1;i--){
f[i]=powmod(k/i,n);
for(int j=i*2;j<=k;j+=i){
f[i]-=f[j];
if(f[i]<0)f[i]+=mod;
}
}
ll res=0;
for(int i=1;i<=k;i++){
res+=i*f[i]%mod;
res%=mod;
}
cout<<res<<endl;
}
问题 F: 付哥拿糖果
思路:设f[i][j][k]为从i开始跳跳到j其中多跳了k个的最大答案(默认每次取相中间差一个的糖果,如果中间差两个那么多跳了1个),那么当n是奇数时答案就取dp[1][n][3],dp[1][n-1][2],dp[1][n-2][1],dp[2][n][2],dp[2][n-1][1],dp[3][n][1]中的最大值,是偶数时答案就取dp[1][n][2],dp[1][n-1][1],dp[2][n][1]中的最大值。
#include <bits/stdc++.h>//#include<iostream>//#include<string.h>//#include<math.h//#include<algorithm>
#define ll long long
#define db double
#define pii pair<int,int>
#define cf int _;cin>>_;while(_--)
#define de cout<<"---"<<endl;
#define mem(x,v) memset(x,v,sizeof(x))
#define L(x) x&(-x)
#define pb push_back//emplace_back//priority_queue <int,vector<int>,greater<int> > q;
#define INF 0x3f3f3f3f
#define endl '\n'
//function<void(int)> dfs = [&](int u);
//#define x first
//#define y second
using namespace std;
const int mod=1e9+7;
int n,k;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll dp[5][100050][5];
int main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n;
vector<ll>a(n+10,0);
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=3;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=3;k++){
dp[i][j][k]=-1e18;
}
}
}
dp[1][1][1]=a[1];dp[2][2][1]=a[2],dp[3][3][1]=a[3];
for(int i=1;i<=n;i++){
for(int j=1;j<=3;j++){
dp[j][i+2][1]=max(dp[j][i+2][1],dp[j][i][1]+a[i+2]);
dp[j][i+2][2]=max(dp[j][i+2][2],dp[j][i][2]+a[i+2]);
dp[j][i+3][2]=max(dp[j][i+3][2],dp[j][i][1]+a[i+3]);
dp[j][i+2][3]=max(dp[j][i+2][3],dp[j][i][3]+a[i+2]);
dp[j][i+3][3]=max(dp[j][i+3][3],dp[j][i][2]+a[i+3]);
dp[j][i+4][3]=max(dp[j][i+4][3],dp[j][i][1]+a[i+4]);
}
}
if(n&1){
ll res=-1e18;
res=max(res,dp[1][n][3]);
res=max(res,dp[1][n-1][2]);
res=max(res,dp[1][n-2][1]);
res=max(res,dp[2][n][2]);
res=max(res,dp[2][n-1][1]);
res=max(res,dp[3][n][1]);
cout<<res<<endl;
}
else {
ll res=-1e18;
res=max(res,dp[1][n][2]);
res=max(res,dp[1][n-1][1]);
res=max(res,dp[2][n][1]);
cout<<res<<endl;
}
}