A - YES or YES?
题解略
#include<bits/stdc++.h>
using namespace std;
void solve()
{
string s;cin >> s;
if(s.size() == 3)
{
if(s[0]=='y'||s[0]=='Y')
{
if(s[1]=='e'||s[1]=='E')
{
if(s[2]=='s'||s[2]=='S')
{
cout << "YES" <<'\n';
return ;
}
}
}
}
cout << "NO" <<'\n';
return ;
}
int main()
{
int t;cin >> t;
while(t--) solve();
return 0;
}
B - ICPC Balloons
第一次出现的加 2 就行
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define Start cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
using namespace std;
#define x first
#define y second
const int N = 3e5 + 10;
int a[N];
void Rainbow_()
{
int n;cin >> n;
map<char,bool> m;
string s;cin >> s;
int cnt = 0;
for(int i = 0; i < n; i ++)
{
if(m[ s[i] ] == false)
{
cnt += 2;
m[s[i]] = true;
}
else cnt += 1;
}
cout << cnt <<'\n';
return ;
}
signed main()
{
Start;int t = 1;
cin >> t;
while (t--) Rainbow_();
return 0;
}
C - Cypher
反过来操作,他加你就减 。
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define Start cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
using namespace std;
#define x first
#define y second
const int N = 3e5 + 10;
int a[N];
void Rainbow_()
{
int n;cin >> n;
for(int i = 1 ; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++ )
{
int len;cin >> len;
string s; cin >> s;
for(int j = 0; j < len ; j ++)
{
if( s[j] == 'D' )
{
if( a[i] == 9) a[i] = 0;
else a[i] ++;
}
else
{
if(a[i] == 0) a[i] = 9;
else a[i] --;
}
}
}
for(int i = 1; i <= n; i ++)
{
cout << a[i] <<' ';
}
cout << '\n';
return ;
}
signed main()
{
Start;int t = 1;
cin >> t;
while (t--) Rainbow_();
return 0;
}
D - Double Strings(考察map和substring)
这道题不可以暴力枚举,用map和substring来替代
map可以判断一个字符串是否出现过,substring在字符串中取得子串
所以直接判断原字符串的各个子串是否出现过
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define Start cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
using namespace std;
#define x first
#define y second
const int N = 1e5 + 10;
int a[N];string s[N];
void Rainbow_()
{
int n;cin >> n;
map<string,bool> m;
for(int i = 1 ; i <= n; i ++)
{
cin >> s[i];
m[ s[i] ] = true;
}
for(int i = 1 ; i <= n; i ++)
{
bool judge = 0;
for(int j = 1; j < s[i].size() ; j ++)
{
if( m[ s[i].substr(0,j) ] && m[s[i].substr(j,s[i].size() - j)])
{
judge = true;
cout << 1 ;
break;
}
}
if( !judge )
{
cout << 0;
}
}
cout << '\n';
return ;
}
signed main()
{
Start;int t = 1;
cin >> t;
while (t--) Rainbow_();
return 0;
}
E - Mirror Grid
判断旋转四次的位置(画个图就能判断出来)
0,1数量谁多,要把少的变成多的
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define Start cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
using namespace std;
#define x first
#define y second
const int N = 1e3 + 10;
int g[N][N];
void Rainbow_()
{
int n;cin >> n;
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
{
char c ;
cin >> c; // 因为题目中给的都是连在一起的,不能用int/string读入
g[i][j] = c - '0';
}
}
int cnt = 0;
int ans = 0;
for(int i = 1; i <= (n + 1) / 2; i ++) // 这里无论奇偶都能读完中间
{
for(int j = 1; j <= n / 2; j ++) // 奇数中间一个不用看
{
ans = g[i][j] + g[j][n - i + 1] + g[n - j + 1][i] + g[ n- i + 1][ n - j + 1];
cnt += min(4 - ans, ans );
}
}
cout << cnt << '\n';
return ;
}
signed main()
{
Start;int t = 1;
cin >> t;
while (t--) Rainbow_();
return 0;
}
F - Yet Another Problem About Pairs Satisfying an Inequality
ai<i<aj<j. 这个条件 抽象成两个 ak < k
我们管所有符合 下标大于储存值的 也就是 i > ai的点叫做 可行点
题目就转化成了在可行点数组中寻找 aj > i 的情况
所以用前缀和数组cnt储存i之前的所有符合情况的点
cnt[j] 意味着 在j之前(包括j)满足 ai < i 的点 有多少个
又因为 j 是 i的后继所以必定有 j > i , 所以 j > i > ai
我们把 j 用 a[j] 替换掉 就会出现 cnt[ a[j] ] 是前面有多少个满足 aj > i > ai的点的个数
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define Start cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
using namespace std;
#define x first
#define y second
const int N = 2e5 + 10;
int a[N];
int cnt[N];
void Rainbow_()
{
int n;cin >> n;
int ans = 0;
memset(cnt,0,sizeof cnt);
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
//if( a[i] < i) cnt[i] = cnt[i - 1] + 1;
//else cnt[i] = cnt[i - 1];
cnt[i] += cnt[i - 1] + (a[i] < i);
}// cnt数组储存的是 在 i 之前(包括i点)有多少符合 i > a[i] 的个数
for(int i = 1; i <= n ; i ++)
if( i > a[i] ) ans += cnt[a[i] - 1];
cout << ans <<'\n';
return ;
}
signed main()
{
Start;int t = 1;
cin >> t;
while (t--) Rainbow_();
return 0;
}