A
# include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
cout<<n-1<<endl;
}
}
B
# include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int T;
cin>>T;
while(T--)
{
string s;
cin>>s;
reverse(s.begin(),s.end());
for(int i=0;i<s.size();i++)
{
if(s[i]=='p')
s[i]='q';
else if(s[i]=='q')
s[i]='p';
}
cout<<s<<endl;
}
}
C
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int m,a,b,c;
void solve()
{
cin>>m>>a>>b>>c;
int sum=0,ans=0;
if(a>=m)
sum+=m;
else sum+=a,ans+=m-a;
if(b>=m)
sum+=m;
else sum+=b,ans+=m-b;
//cout<<sum<<" "<<ans<<endl;
if(ans)
{
sum=sum+min(ans,c);
}
cout<<sum<<endl;
}
signed main ()
{
int T;
cin >> T;
while (T --) solve();
return 0;
}
D
我们可以构造一个排列 使每个数只出现一次也满足要求 先预处理出未出现的数 当重复出现的时候则用未出现的数代替
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int n,a[N],b[N];
map<int,int>ma;
set<int>ma1,ma2;
void solve()
{
ma1.clear(),ma2.clear();
cin>>n;
int x=1;
for(int i=1;i<=n;i++)
cin>>a[i],ma1.insert(a[i]);
for(int i=1;i<=n;i++)
{
if(ma1.count(i)==0)
{
b[x++]=i;
//cout<<i<<" ";
}
}
x--;
int l=1;
for(int i=1;i<=n;i++)
{
if(ma2.count(a[i])==0)
{
cout<<a[i]<<" ";
ma2.insert(a[i]);
}
else
{
cout<<b[l++]<<" ";
}
}
cout<<'\n';
}
signed main ()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T --) solve();
return 0;
}
E
计算出满足范围的数即可
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int k,l1,r1,l2,r2;
void solve()
{
cin>>k>>l1>>r1>>l2>>r2;
int ans=0,res=1;
for(int i=1;i<=32;i++)
{
int ll1=(l2+res-1)/res,rr1=r2/res;
ll1=max(ll1,l1),rr1=min(rr1,r1);
ans+=max(rr1-ll1+1,(int)0);
res*=k;
if(res>1e9)break;
}
cout<<ans<<endl;
}
signed main ()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T --) solve();
return 0;
}
```