A.数字权重
思路:
化简一下方程:
暴力有多少对a[n]和a[1]满足,中间[2,n-1]位10^(n-2) 快速幂
B.毒瘤xor
对于区间[L,R]的数,对第i位,若0的总数 > 1的总数 则, x[i]=1 ;否则为0
C.硬币游戏
模拟贪心,开4个set
D.粉樱花之恋
lgj : , 矩阵快速幂求一下第n+1 +2项-1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD= 998244353;
struct Matrix {
long long a[2][2];
Matrix() {
memset(a, 0, sizeof(a));
}
Matrix operator * (const Matrix y) {
Matrix ans;
for(int i = 0; i <= 1; i++)
for(int j = 0; j <= 1; j++)
for(int k = 0; k <= 1; k++)
ans.a[i][j] += a[i][k]*y.a[k][j],ans.a[i][j]%=MOD;
for(int i = 0; i <= 1; i++)
for(int j = 0; j <= 1; j++)
ans.a[i][j] %= MOD;
return ans;
}
void operator = (const Matrix b) {
for(int i = 0; i <= 1; i++)
for(int j = 0; j <= 1; j++)
a[i][j] = b.a[i][j];
}
};
ll solve(long long x) {
Matrix ans, trs;
ans.a[0][0] = ans.a[1][1] = 1;
trs.a[0][0] = trs.a[1][0] = trs.a[0][1] = 1;
while(x) {
if(x&1)
ans = ans*trs;
trs = trs*trs;
x >>= 1;
}
return ans.a[0][0]%MOD;
}
int main() {
ll n;
cin>>n;
cout << ((solve(n+2)-1)%MOD+MOD)%MOD << endl;
return 0;
}
E.符合条件的整数
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int n=cin.nextInt();
int m=cin.nextInt();
// System.out.println(n+" "+m);
BigInteger a=BigInteger.valueOf(1);
BigInteger b=BigInteger.valueOf(1);
for(int i=1;i<=n;i++) a=a.multiply(BigInteger.valueOf(2));
for(int i=1;i<=m;i++) b=b.multiply(BigInteger.valueOf(2));
// System.out.println(b+" "+a);
a=a.subtract(BigInteger.valueOf(2));
b=b.subtract(BigInteger.valueOf(2));
a=a.divide(BigInteger.valueOf(7));
if(a.compareTo(BigInteger.valueOf(0)) == 0 ) a=a.subtract(BigInteger.valueOf(1));
b=b.divide(BigInteger.valueOf(7));
System.out.println(b.subtract(a));
}
}
F.可爱即正义
思路:最弱智的题
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+6;
const ll MOD=1e9+7;
const int Seed=1e7+7;
template <class T>
bool sf(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
string t="suqingnianloveskirito",s;
set<int> st;
int check(){
int n=(int)s.size();
bool f=false;
int cnt=0;
// cout <<0<<"~"<<n+1-(int)t.size()<<endl;
for(int i=0;i<=n+1-(int)t.size();++i){
if(s.substr(i,(int)t.size()) == t){
++cnt;
st.insert(i);
// cout <<"GO " << endl;
}
}
return cnt;
}
int main(){
cin >> s;
int cnt=check();
// cout << cnt << endl;
// cout <<st.size() << endl;
if(cnt==0) cout <<"Yes"<<endl<<"1 2"<<endl;
else if(cnt==1) cout <<"Yes"<<endl<<*st.begin()+1<<" "<<*st.begin()+2<<endl;
else if(cnt==2) cout <<"Yes"<<endl<<*st.begin()+1<<" "<<*st.rbegin()+2<<endl;
else cout <<"No"<<endl;
return 0;
}