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 Output Example Yet Another Crosses Problem CodeForces - 1194B 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 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 Example …… .… *… ..* …. 5 5 .. 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). From S To T CodeForces - 1194C 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; Note that you have to answer q independent queries. Input 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 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 s= ab, t= acxb, p= cax; s= a, t= aaaa, p= aaabbcc; 1-2-K Game CodeForces - 1194D 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 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 Example 努力加油a啊,(o)/~
Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.
Input
3
3 1
4 2
69 6
Output
2
4
12
直接输出2*x就好了。。
代码如下:#include
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.
The first line contains an integer q (1≤q≤5⋅104) — the number of queries.
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.
Input
9
5 5
……
……
……
3 4
.…
4 3
*…
*…
5 5
…***
1 4
…
……
..
……
…
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.
这个题过得听迷糊的,我以为用string不行呢,然后用数组试了几下,结果re和wa,用string之后就过了。
n*m反正不大,我把每一行和每一列的星星数记录下来,再去遍历每一行加每一列的个数,去更新最优值。
代码如下:#include
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.
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.
The first line contains one integer q (1≤q≤100) — the number of queries. Each query is represented by three consecutive lines.
For each query print YES if it is possible to make s equal to t, and NO otherwise.
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= acb, t= acxb, p= ax;
s= acxb, t= acxb, p= a.
In the second test case there is the following sequence of operation:
s= aa, t= aaaa, p= aabbcc;
s= aaa, t= aaaa, p= abbcc;
s= aaaa, t= aaaa, p= bbcc.
就按着题意去不断的求解,找不符合的情况,之后就是符合的情况了。最后还dp求了一个最长公共子序列。。
代码如下:#include
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).
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.
For each game, print Alice if Alice wins this game and Bob otherwise.
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
sg函数打表找规律,看的题解,不怎么会博弈。。。
代码如下:#include