第一个d题,寒假的时候看过,没看懂题目意思,现在回看了一手,发现就是打表找规律题
代码如下:
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
int n;
string s;
map<int,map<int,int>>dp;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n;
cin>>s;
ll ln=0;
ll rn=0;
ll l=0,r=0;
for(int i=0;i<s.size();i++){
if(s[i]=='1'){
if(l==0)l=1;
else l<<=1;
ln+=l;
}
else {
if(r==0)r=1;
else r<<=1;
rn+=r;
}
}
ll m=pow(2,s.size());
for(int i=ln+1;i<=m-rn;i++){
printf("%d ",i);
}
}
第二题c,是个很妙的题,运用了比较特殊的倒着加减的原理,最开始t了几发,后来看了jiangly大神的代码,直呼妙。
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
int n,m,t;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>t;
while(t--){
cin>>n>>m;
vector<int>b(n+m+5);
vector<int>hh(n+m+5);
for(int i=1;i<=n;i++){
cin>>b[i];
hh[b[i]]=m+1;
}
for(int i=1;i<=m;i++){
int l,r;
cin>>l>>r;
hh[b[l]]-=m-i+1;
b[l]=r;
hh[b[l]]+=m-i+1;
}
ll ans=1ll*m*(m+1)*n; //化简前:ans=m*(m+1)/2*2n;
for(int i=1;i<=n+m;i++){
ans-=1ll*(hh[i]-1)*hh[i]/2;
}
printf("%lld\n",ans);
}
return 0;
}
最后一个是个数学题,就是探究倍数之间的范围一般都是2倍,但是有可能会出现其中一位数是3倍的情况:
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
ll t;
ll lx,rx,an;
ll N=998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>t;
while(t--){
cin>>lx>>rx;
an=0;
ll l1=lx;
while(l1<=rx){
an++;
l1<<=1;
}
if(an==1){
printf("1 %lld\n",rx-lx+1);
continue;
}
l1>>=1;
ll ans=0;
ll x=l1/lx;
ans=(rx/x-lx+1)%N;
x=x/2*3;
ans=(ans+max((rx/x-lx+1)*(an-1),0ll)%N)%N;
printf("%lld %lld\n",an,ans);
}
}