Educational Codeforces Round 68 (Rated for Div. 2)(ABCD)

Remove a Progression CodeForces - 1194A
You have a list of numbers from 1 to n written from left to right on the blackboard.

You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
在这里插入图片描述

When there are less than i numbers remaining, you stop your algorithm.

Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?

Input
The first line contains one integer T (1≤T≤100) — the number of queries. The next T lines contain queries — one per line. All queries are independent.

Each line contains two space-separated integers n and x (1≤x<n≤109) — the length of the list and the position we wonder about. It’s guaranteed that after the algorithm ends, the list will still contain at least x numbers.

Output
Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.

Example
Input
3
3 1
4 2
69 6
Output
2
4
12
直接输出2*x就好了。。
代码如下:

#include<iostream>
#define ll long long
using namespace std;

ll n,x;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld",&n,&x);
		cout<<(x<<1L)<<endl;
	}
}

Yet Another Crosses Problem CodeForces - 1194B
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white.

You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x and y, where 1≤x≤n and 1≤y≤m, such that all cells in row x and all cells in column y are painted black.

For examples, each of these pictures contain crosses:
在这里插入图片描述

The fourth picture contains 4 crosses: at (1,3), (1,5), (3,3) and (3,5).

Following images don’t contain crosses:
在这里插入图片描述

You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.

What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?

You are also asked to answer multiple independent queries.

Input
The first line contains an integer q (1≤q≤5⋅104) — the number of queries.

The first line of each query contains two integers n and m (1≤n,m≤5⋅104, n⋅m≤4⋅105) — the number of rows and the number of columns in the picture.

Each of the next n lines contains m characters — ‘.’ if the cell is painted white and ‘*’ if the cell is painted black.

It is guaranteed that ∑n≤5⋅104 and ∑n⋅m≤4⋅105.

Output
Print q lines, the i-th line should contain a single integer — the answer to the i-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

Example
Input
9
5 5




3 4


.
.

4 3


*…
*…
*…
5 5


..*


.
…***
1 4


5 5


.
.


5 3

.
.
.*.


..
3 3
.
.
.
.*.
4 4
.*

.*
.*
Output
0
0
0
0
0
4
1
1
2
Note
The example contains all the pictures from above in the same order.

The first 5 pictures already contain a cross, thus you don’t have to paint anything.

You can paint (1,3), (3,1), (5,3) and (3,5) on the 6-th picture to get a cross in (3,3). That’ll take you 4 minutes.

You can paint (1,2) on the 7-th picture to get a cross in (4,2).

You can paint (2,2) on the 8-th picture to get a cross in (2,2). You can, for example, paint (1,3), (3,1) and (3,3) to get a cross in (3,3) but that will take you 3 minutes instead of 1.

There are 9 possible crosses you can get in minimum time on the 9-th picture. One of them is in (1,1): paint (1,2) and (2,1).
这个题过得听迷糊的,我以为用string不行呢,然后用数组试了几下,结果re和wa,用string之后就过了。
n*m反正不大,我把每一行和每一列的星星数记录下来,再去遍历每一行加每一列的个数,去更新最优值。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

const int maxx=5e4+100;
string s[maxx];
int a[maxx];
int b[maxx];
int n,m;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(int i=0;i<n;i++) cin>>s[i];
		int cnt=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				if(s[i][j]=='*')
					cnt++;
			}
			a[i]=cnt;
			cnt=0;
		}
		cnt=0;
		for(j=0;j<m;j++)
		{
			for(i=0;i<n;i++)
			{
				if(s[i][j]=='*')
					cnt++;
			}
			b[j]=cnt;
			cnt=0;
		}
		int flag=0;
		int ans=inf;
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				if(a[i]+b[j]-(s[i][j]=='*'?1:0)==(n+m-1))
				{
					puts("0");
					flag=1;
					break;
				}
				else
				{
					ans=min(ans,n+m-1-(a[i]+b[j]-(s[i][j]=='*'?1:0)));
				}
			}
			if(flag) break;
		}
		if(!flag) cout<<ans<<endl;
	}
}

From S To T CodeForces - 1194C
You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of s, in the end or between any two consecutive characters).

For example, if p is aba, and s is de, then the following outcomes are possible (the character we erase from p and insert into s is highlighted):

aba → ba, de → ade;
aba → ba, de → dae;
aba → ba, de → dea;
aba → aa, de → bde;
aba → aa, de → dbe;
aba → aa, de → deb;
aba → ab, de → ade;
aba → ab, de → dae;
aba → ab, de → dea;
Your goal is to perform several (maybe zero) operations so that s becomes equal to t. Please determine whether it is possible.

Note that you have to answer q independent queries.

Input
The first line contains one integer q (1≤q≤100) — the number of queries. Each query is represented by three consecutive lines.

The first line of each query contains the string s (1≤|s|≤100) consisting of lowercase Latin letters.

The second line of each query contains the string t (1≤|t|≤100) consisting of lowercase Latin letters.

The third line of each query contains the string p (1≤|p|≤100) consisting of lowercase Latin letters.

Output
For each query print YES if it is possible to make s equal to t, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example
Input
4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa
Output
YES
YES
NO
NO
Note
In the first test case there is the following sequence of operation:

s= ab, t= acxb, p= cax;
s= acb, t= acxb, p= ax;
s= acxb, t= acxb, p= a.
In the second test case there is the following sequence of operation:

s= a, t= aaaa, p= aaabbcc;
s= aa, t= aaaa, p= aabbcc;
s= aaa, t= aaaa, p= abbcc;
s= aaaa, t= aaaa, p= bbcc.
就按着题意去不断的求解,找不符合的情况,之后就是符合的情况了。最后还dp求了一个最长公共子序列。。
代码如下:

#include<bits/stdc++.h>
using namespace std;

char a[101],b[101],c[101];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s%s%s",a+1,b+1,c+1);
		int len1=strlen(a+1);//s,s->t
		int len2=strlen(b+1);//t
		int len3=strlen(c+1);//p
		if(len1>len2)
		{
			puts("NO");
			continue;
		}
		map<char,int> mp2,mp1,mp3;
		for(int i=1;i<=len2;i++) mp2[b[i]]++;
		int flag=0;
		for(int i=1;i<=len1;i++)
		{
			mp1[a[i]]++;
			if(mp1[a[i]]>mp2[a[i]])
			{
				flag=1;
				break;
			}
		}
		if(flag) puts("NO");
		else
		{
			for(int i=1;i<=len3;i++)
			{
				mp3[c[i]]++;
			}
			for(int i=1;i<=len2;i++)
			{
				if(mp1[b[i]]+mp3[b[i]]<mp2[b[i]])
				{
					flag=1;
					break;
				}
			}
			if(flag) puts("NO");
			else
			{
				int dp[101][101];
				for(int i=1;i<=len1;i++) dp[i][0]=0;
				for(int j=1;j<=len2;j++) dp[0][j]=0;
				for(int i=1;i<=len1;i++)
				{
					for(int j=1;j<=len2;j++)
					{
						if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1;
						else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
					}
				}
				if(dp[len1][len2]==len1) puts("YES");
				else puts("NO");
			}
		}
	}
}

1-2-K Game CodeForces - 1194D
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).

Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can’t make a move loses the game.

Who wins if both participants play optimally?

Alice and Bob would like to play several games, so you should determine the winner in each game.

Input
The first line contains the single integer T (1 ≤ T ≤ 100) — the number of games. Next T lines contain one game per line. All games are independent.

Each of the next T lines contains two integers n and k (0 ≤ n ≤ 109, 3 ≤ k ≤ 109) — the length of the strip and the constant denoting the third move, respectively.

Output
For each game, print Alice if Alice wins this game and Bob otherwise.

Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
sg函数打表找规律,看的题解,不怎么会博弈。。。
代码如下:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int f[35],sg[35],hashing[35];
void getsg(int n,int size)
{
    memset(sg,0,sizeof(sg));
    for(int i=0;i<=n;++i)//总个数
    {
        memset(hashing,0,sizeof(hashing));
        for(int j=0;f[j]<=i&&j<size;++j)
            hashing[sg[i-f[j]]]=1;//可以到达的i的下一个状态
        for(int j=0;j<=n;++j)
        {
            if(hashing[j]==0)
            {
                sg[i]=j;
                break;
            }
        }
    }
}

void gettable()
{
    for(int i=3;i<=30;++i)
    {
        f[0]=1;
        f[1]=2;
        f[2]=i;
        for(int j=0;j<=30;++j)
        {
            cout<<i<<" "<<j<<" ";
            getsg(j,3);
//            if(sg[i]) cout<<"Alice"<<endl;
//            else cout<<"Bob"<<endl;
            for(int k=0;k<=j;++k)
                cout<<sg[k]<<" ";
            cout<<endl;
        }
    }
}

int main()
{
	int t;
	scanf("%d",&t);
	int n,k;
	while(t--)
	{
		scanf("%d%d",&n,&k);
		if(k%3!=0)
		{
			ll x=(n+1)%3;
			if(x!=1) cout<<"Alice"<<endl;
			else cout<<"Bob"<<endl;
		}
		else 
		{
			ll x=(n+1)%(k+1);
			if(x%3==1) cout<<"Bob"<<endl;
			else cout<<"Alice"<<endl;
		}
	}
	//gettable();
}

努力加油a啊,(o)/~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值