恢复性训练
就是每次消除当前数组中的一个位置上的数
写写例子,发现其实每次消除的都是一开始数组上的奇数位置,所以最后答案应该就是2*x
3
3 1
4 2
69 6
问你形成一个一行 和一列都是黑色方块的最少操作次数(涂色一次只能涂一个方块)
找到行和列最多的黑色的方块(然后判断一个特殊位置就是行和列都是最多的时候, 这个交叉的地方是否是空白的)
#include <cstdio>
#include <algorithm>
#include<iomanip>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <cstring>
#include<stack>
#include <cassert>
#include<map>
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define pb push_back
#define de(x) cerr<<#x<<" = "<<x<<endl
#define __i __int128
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
using namespace std;
//using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
const LL Max = 9.1e10;
const int N =5.1e5;
const int maxn = 200010;
void clear(unsigned char *pta, int size )
{//结构体初始化
while(size>0)
{
*pta++ = 0;
size --;
}
}
LL n, k, m ;
LL ar[N],br[N];
LL i,j,g;
LL MOD = 998244353 ;
LL f[N], ans[N] , last[N];
//f是该长度最小的坐标 ans 是最后输出的数 , last 是相同的数上一个位置
LL fac[N],inv_fac[N];
//快速幂
LL qpow(LL x, LL y ){
x%=MOD;
long long res=1%MOD;
while(y){
if(y&1)res=res*x%MOD;
y>>=1;
x=x*x%MOD;
}
return res;
}
void pre(){
fac[0] =1 ;
for(int i=1;i<N;i++){
fac[i] =fac[i-1] * i %MOD;
}
inv_fac[N - 1 ] = qpow(fac[N - 1] , MOD-2 ) ;
for(int i =N-2 ;i>=0 ;i--){
inv_fac[i] = inv_fac[i+1] * (i+1) %MOD;
}
}
LL C (LL a ,LL b){
if(a<0 || b> a )//因为是C(a,b) 所以b《= a
{
return 0;
}
return fac[a] * inv_fac[b] % MOD *inv_fac[a-b]%MOD;//a 的阶乘 / ( b的阶乘 * (a-b的阶乘))
}
string s[N];
void answer(){
cin >> n >>m ;
for(int i=0;i<n;i++){
cin >>s[i];
}
// ar 是行 , br 是列
for(int i=0;i<n;i++)ar[i] =0 ;
for(int j=0;j<m;j++)br[j] =0 ;
LL mh = 0 , ml =0 ;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
char ch = s[j][i];
if(ch!=‘.‘)br[i] ++ ;
}
ml = max(br[i] , ml) ; // n - ml
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char ch = s[i][j];
if(ch!=‘.‘)ar[i] ++ ;
}
mh = max(ar[i] , mh) ; // m- mh
}
// cout<<mh <<" "<<ml<<endl;
LL num =0 ;
LL sum = n - ml + m -mh;
for(int i=0;i<n;i++){
if(mh == ar[i]){
f[num ++ ] = i;
}
}
for(int j=0;j<m;j++){
if(ml == br[j]){
for(int i=0;i<num;i++){
if(s[f[i]][j]==‘.‘){
cout<<sum -1<<endl;
return ;
}
}
}
}
cout<<sum<<endl;
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// pre();
LL t;
// sld(t);
cin >> t ;
while(t--)
answer();
return 0;
}
给你三个字符串 ,问你是否通过p字符串中的字符(这个里面的字符可以随便插入s中)插入s,使得s与t相等
想考虑一下,不能成立的就是s 中字符的顺序和t 中的字符顺序不同(详情看样例中的第三个) 和q中的字符无法是s构造成t
#include <cstdio>
#include <algorithm>
#include<iomanip>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <cstring>
#include<stack>
#include <cassert>
#include<map>
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define pb push_back
#define de(x) cerr<<#x<<" = "<<x<<endl
#define __i __int128
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
using namespace std;
//using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
const LL Max = 9.1e10;
const int N =5.1e5;
const int maxn = 200010;
void clear(unsigned char *pta, int size )
{//结构体初始化
while(size>0)
{
*pta++ = 0;
size --;
}
}
LL n, k, m ;
LL ar[N],br[N];
LL i,j,g;
LL MOD = 998244353 ;
LL f[N], ans[N] , last[N];
//f是该长度最小的坐标 ans 是最后输出的数 , last 是相同的数上一个位置
LL fac[N],inv_fac[N];
//快速幂
LL qpow(LL x, LL y ){
x%=MOD;
long long res=1%MOD;
while(y){
if(y&1)res=res*x%MOD;
y>>=1;
x=x*x%MOD;
}
return res;
}
void pre(){
fac[0] =1 ;
for(int i=1;i<N;i++){
fac[i] =fac[i-1] * i %MOD;
}
inv_fac[N - 1 ] = qpow(fac[N - 1] , MOD-2 ) ;
for(int i =N-2 ;i>=0 ;i--){
inv_fac[i] = inv_fac[i+1] * (i+1) %MOD;
}
}
LL C (LL a ,LL b){
if(a<0 || b> a )//因为是C(a,b) 所以b《= a
{
return 0;
}
return fac[a] * inv_fac[b] % MOD *inv_fac[a-b]%MOD;//a 的阶乘 / ( b的阶乘 * (a-b的阶乘))
}
void answer(){
string s, t, p,ss;
cin >>s>>t>>p;
map<char, int > mp;
for(int i=0;i<p.size();i++){
mp[p[i]]++;
}
int len =0 ;
for(int i=0;i<t.size();i++){
if(s[len]==t[i])len++;
else {
if(mp[t[i]])mp[t[i]]--;
else {
cout<<"NO"<<endl;
return ;
}
}
}
if(len == s.size()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// pre();
LL t;
// sld(t);
cin >> t ;
while(t--)
answer();
return 0;
}
两个人玩游戏, Alice先手, 然后每回合可以走1 , 2 和k步,谁无法走谁输
这个是个博弈, 只要想明白k这里其他的就好搞了
先看没有k的情况 -> 也就是只有 1 和 2 的情况:
#include <cstdio>
#include <algorithm>
#include<iomanip>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <cstring>
#include<stack>
#include <cassert>
#include<map>
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define pb push_back
#define de(x) cerr<<#x<<" = "<<x<<endl
#define __i __int128
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
using namespace std;
//using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
const LL Max = 9.1e10;
const int N =5.1e5;
const int maxn = 200010;
void clear(unsigned char *pta, int size )
{//结构体初始化
while(size>0)
{
*pta++ = 0;
size --;
}
}
LL n, k, m ;
LL ar[N],br[N];
LL i,j,g;
LL MOD = 998244353 ;
LL f[N], ans[N] , last[N];
//f是该长度最小的坐标 ans 是最后输出的数 , last 是相同的数上一个位置
LL fac[N],inv_fac[N];
//快速幂
LL qpow(LL x, LL y ){
x%=MOD;
long long res=1%MOD;
while(y){
if(y&1)res=res*x%MOD;
y>>=1;
x=x*x%MOD;
}
return res;
}
void pre(){
fac[0] =1 ;
for(int i=1;i<N;i++){
fac[i] =fac[i-1] * i %MOD;
}
inv_fac[N - 1 ] = qpow(fac[N - 1] , MOD-2 ) ;
for(int i =N-2 ;i>=0 ;i--){
inv_fac[i] = inv_fac[i+1] * (i+1) %MOD;
}
}
LL C (LL a ,LL b){
if(a<0 || b> a )//因为是C(a,b) 所以b《= a
{
return 0;
}
return fac[a] * inv_fac[b] % MOD *inv_fac[a-b]%MOD;//a 的阶乘 / ( b的阶乘 * (a-b的阶乘))
}
void answer (){
cin >> n >> m;
if(m%3){
if(n%3)cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
else {
n%=m+1;// 即每个回合b都可以让这个回合总和%3 为1 我觉得 2 也行 2 不行的理由可能是因为没有改变模数? 8 + 2 = 6 10%3 == 1 8 %3==2
// cout<< n<<endl;
if(n==m || n%3)cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// pre();
LL t;
// sld(t);
cin >> t ;
while(t--)
answer();
return 0;
}
Educational Codeforces Round 68 (Rated for Div. 2)
原文:https://www.cnblogs.com/gaohaoy/p/13765613.html