A.题
双指针模拟
/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 1e6+10;
ll qpow(ll a, ll b){
ll res = 1; while(b){
if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int main()
{
int t;
cin >> t;
while(t--)
{
int st[100] = {
0};
int n;
cin >> n;
string s;
cin >> s;
int f = 0;
for(int i = 0; i < n; i++){
int j = i;
if(st[s[j]]){
f = 1;
break;
}
while(s[j] == s[i] && j < n) j++;
st[s[i]] = 1;
i = j;
i--;
}
if(f) cout <<"NO"<<endl;
else{
cout <<"YES"<< endl;
}
}
return 0;
}
B.题
/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 1e6+10;
ll qpow(ll a, ll b){
ll res = 1; while(b){
if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int main()
{
int t;
cin >> t;
while(t--){
int n;
ll res = 0;
cin >> n;
if(n < 10) cout << n << endl;
else{
int q = n;
int cnt = 0;
while(q){
int t = q%10;
cnt++;
q /= 10;
}
res += 9*(cnt-1);
ll num = 0;
for(int i = cnt-1; i >= 0; i--){
num += pow(10.0,i);
}
//cout << num << endl;
int f = 0;
for(int i = 1; i <= 9;i++){
if(n < num*i) break;
f = i;
}
res += f;
cout << res << endl;
}
}
return 0;
}
C题:
/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 1e6+10;
ll qpow(ll a, ll b){
ll res = 1; while(b){
if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int e[101][101];
int main()
{
int t;
cin >> t;
while(t--){
mem(e,0);
int n;
cin >> n;
int cnt = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
e[i][j] = ++cnt;
if(n == 1) cout << 1 << endl;
else if(n == 2) cout << -1 << endl;
else{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
if(j%2){
int t = (j+1)%n;
swap(e[i][j],e[t][j]);
// e[i][j] = e[t][j];
}
}
for(int i = 0; i < n ;i++){
for(int j = 0; j < n; j++){
cout << e[i][j]<<" ";
}
cout << endl;
}
}
}
return 0;
}
D.
注意开long long
因为没开long long test five 就wa了
/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 2e5+10;
ll qpow(ll a, ll b){
ll res = 1; while(b){
if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int a[N];
int b[N];
map<ll,ll> cnt;
int main()
{
int t;
cin >> t;
while(t--){
cnt.clear();
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
b[i] = a[i] - i;
cnt[b[i]] ++;
}
ll res = 0;
for(auto i:cnt){
res += i.second*(i.second-1)/2;
}
cout << res << endl;
}
return 0;
}