题目链接:http://codeforces.com/contest/1194         

                                  A.Remove a Progression

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

You have a list of numbers from 11 to nn written from left to right on the blackboard.

You perform an algorithm consisting of several steps (steps are 11-indexed). On the ii-th step you wipe the ii-th number (considering only remaining numbers). You wipe the whole number (not one digit).

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

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

Input

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

Each line contains two space-separated integers nn and xx (1≤x<n≤1091≤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 xx numbers.

Output

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

Example
input

Copy
3
3 1
4 2
69 6
output

Copy
2
4
12
题解:依照题意,每次删除第 i 个数,直到剩余的数的个数之和小于被删除数的数字,算法终止。在对给定算法进行一些模拟后,在纸上,我们可以意识到所有奇数都被删除了。所以,所有偶数仍然存在,答案是2X。
 #include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
while(~scanf("%d",&T))
{
while(T--)
{
int n,x;
scanf("%d%d",&n,&x);
printf("%d\n",*x);
}
}
return ;
}

B.Yet Another Crosses Problem

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

You are given a picture consisting of nn rows and mm columns. Rows are numbered from 11 to nn from the top to the bottom, columns are numbered from 11 to mm 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 xx and yy, where 1≤x≤n1≤x≤n and 1≤y≤m1≤y≤m, such that all cells in row xx and all cells in column yy are painted black.

For examples, each of these pictures contain crosses:

The fourth picture contains 4 crosses: at (1,3)(1,3), (1,5)(1,5), (3,3)(3,3) and (3,5)(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 qq (1≤q≤5⋅1041≤q≤5⋅104) — the number of queries.

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

Each of the next nn lines contains mm characters — '.' if the cell is painted white and '*' if the cell is painted black.

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

Output

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

Example
input

Copy
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
output

Copy
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)(1,3), (3,1)(3,1), (5,3)(5,3) and (3,5)(3,5) on the 66-th picture to get a cross in (3,3)(3,3). That'll take you 44 minutes.

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

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

There are 9 possible crosses you can get in minimum time on the 99-th picture. One of them is in (1,1)(1,1): paint (1,2)(1,2) and (2,1)(2,1).

题解:题目说在一个 n 行 m 列区域内,看有没一个黑色通道通往这个区域的行与列,有输出0,没有计算需要改变白色区域的最少次数。暴力解法开两个数组记录每行和每列缺少黑色的个数,最后遍历一遍,注意每次遍历的时候都要看一下当前字母是黑色还是白色,因为每行和每列都有个重复的字母,所以要特别判断一下。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXX = 0x7fffffff;
int main()
{
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
int q;
cin>>q;
while(q--)
{
int m,n;
cin>>n>>m;
char a[n + ][m + ];
int x[n + ] , y[m + ];
memset(x,,sizeof(x));
memset(y,,sizeof(y));
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
cin>>a[i][j]; for(int i = ; i < n; i++)
{
int flag = ;
for(int j =; j < m; j++)
if(a[i][j] == '.')
flag++;
x[i] = flag;
} for(int i = ; i < m; i++)
{
int flag = ;
for(int j = ; j < n; j++)
if(a[j][i] == '.')
flag++;
y[i] = flag;
}
int ans = MAXX;
for(int i = ; i < n; i++)
{
for(int j = ; j < m; j++)
{
if(a[i][j] == '.')
ans = min(ans,x[i] + y[j] - );
else
ans = min(ans,x[i] + y[j]);
}
}
cout<<ans<<endl;
}
return ;
}

C. From S To T

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

You are given three strings ss, tt and pp consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

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

For example, if pp is aba, and ss is de, then the following outcomes are possible (the character we erase from pp and insert into ss 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 ss becomes equal to tt. Please determine whether it is possible.

Note that you have to answer qq independent queries.

Input

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

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

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

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

Output

For each query print YES if it is possible to make ss equal to tt, 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

Copy
4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa
output

Copy
YES
YES
NO
NO
Note

In the first test case there is the following sequence of operation:

  1. s=s= ab, t=t= acxb, p=p= cax;
  2. s=s= acb, t=t= acxb, p=p= ax;
  3. s=s= acxb, t=t= acxb, p=p= a.

In the second test case there is the following sequence of operation:

  1. s=s= a, t=t= aaaa, p=p= aaabbcc;
  2. s=s= aa, t=t= aaaa, p=p= aabbcc;
  3. s=s= aaa, t=t= aaaa, p=p= abbcc;
  4. s=s= aaaa, t=t= aaaa, p=p= bbcc.

题解:题目说给你三个字符串 s , t , p, 然后从 字符串p 拿任意字符插入 字符串s 任何位置, 最后匹配一下 字符串s 是否等价于 字符串t, 若匹配输出 "YES", 反之输出 "NO"。

思路: 模拟一下是否为子序列,然后记下数。

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int q;
int a[],b[];
cin>>q;
while(q--)
{
string s,t,p;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
cin>>s>>t>>p;
int k = ;
bool flag = true;
for(int i = ; i < s.size(); i++)
{
int j;
a[s[i] - 'a']++;
for(j = k; j < t.size(); j++)
{
if(s[i] == t[j])
{
k = j + ;
break;
}
}
if(j >= t.size())
flag = false;
}
if(!flag)
{
cout<<"NO"<<endl;
continue;
}
for(int i = ; i < p.size(); i++)
a[p[i] -'a']++;
for(int i = ; i < t.size(); i++)
b[t[i] - 'a']++;
for(int i = ; i <= ; i++)
{
if(a[i] < b[i])
{
flag = false;
break;
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}
 #include<iostream>
#include<string>
using namespace std; int number(string a, char b)
{
int cnt = ;
for (int i = ; i < a.size(); i++)
if (a[i] == b)
cnt++;
return cnt;
} int main()
{
int q;
cin >> q;
string s, t, p;
while (q--)
{
cin >> s >> t >> p;
int k = ;
bool is_continue = false;
for (int i = ; i < s.size(); i++)
{
if (t.find(s[i], k) != t.npos)
{
k = t.find(s[i], k)+;
}
else
{
cout << "NO" << endl;
is_continue = true;
break;
}
}
if (is_continue == true)
continue;
bool is_real = false;
for (int i = ; i < t.size(); i++)
{
if ((number(s, t[i]) + number(p, t[i])) < number(t, t[i]))
{
cout << "NO" << endl;
is_real = true;
break;
}
}
if (is_real == false)
cout << "YES" << endl;
}
return ;
}
                                                                                                                   D. 1-2-K Game
                                                                                                                       time limit per test:2 seconds
                                                                                                                       memory limit per test:256 megabytes
                                                                                                                                     input:standard input
                                                                                                                                     output:standard output

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

Copy
4
0 3
3 3
3 4
4 4
output

Copy
Bob
Alice
Bob
Alice
题解:博弈问题两人每人能取 1 , 2 , k 个东西,谁先不能移动谁先输,我们来看看当不取K个时的SG函数:
G(s0)=0,G(s1)=1,G(s2)=2,G(s3)=0,G(S4)=1,G(S5)=2,G(s6)=1......
G(s) = 0是一个 P 态,反之是一个N态。即n≡0mod3时是必败态,否则是必胜态。
  • 根据以下原则打表:
  • 当前状态指向的所有后继状态都是必胜态,那么当前状态是必败态
  • 当前状态能够指向某一个必败态,那么当前状态是必胜态
 #include <iostream>
using namespace std; int main() {
int t;
cin >> t;
while(t--) {
int n, k;
cin >> n >> k;
if(k % != )
cout << (n % == ? "Bob\n" : "Alice\n");
else {
n %= (k + );
if(n % == && n < k)
cout << "Bob\n";
else
cout << "Alice\n";
}
}
}

Educational Codeforces Round 68 Editorial的更多相关文章

  1. Educational Codeforces Round 68 E. Count The Rectangles

    Educational Codeforces Round 68 E. Count The Rectangles 传送门 题意: 给出不超过\(n,n\leq 5000\)条直线,问共形成多少个矩形. ...

  2. Educational Codeforces Round 68 差G

    Educational Codeforces Round 68 E 题意:有 n 个线段,每个都是平行 x 或者 y 轴,只有互相垂直的两线段才会相交.问形成了多少个矩形. \(n \le 5000, ...

  3. Educational Codeforces Round 68 (Rated for Div. 2)---B

    http://codeforces.com/contest/1194/problem/B /* */ # include <bits/stdc++.h> using namespace s ...

  4. Educational Codeforces Round 53 Editorial

    After I read the solution to the problem, I found that my solution was simply unsightly. Solved 4 ou ...

  5. Educational Codeforces Round 68

    目录 Contest Info Solutions A.Remove a Progression B.Yet Another Crosses Problem C.From S To T D.1-2-K ...

  6. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

  7. Educational Codeforces Round 68 (Rated for Div. 2) C. From S To T (字符串处理)

    C. From S To T time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...

  8. Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)

    D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...

  9. Educational Codeforces Round 39 Editorial B(Euclid算法,连续-=与%=的效率)

    You have two variables a and b. Consider the following sequence of actions performed with these vari ...

随机推荐

  1. Java8中的流操作-基本使用&性能测试

    为获得更好的阅读体验,请访问原文:传送门 一.流(Stream)简介 流是 Java8 中 API 的新成员,它允许你以声明式的方式处理数据集合(通过查询语句来表达,而不是临时编写一个实现).这有点儿 ...

  2. 基于Spring注解的上下文初始化过程源码解析(一)

    最近工作之余有时间和精力,加上平时对源码比较感兴趣,就开始啃起了Spring源码.为加深印象写了这篇博客,如有错误,望各位大佬不吝指正. 我看的是Spring5的源码,从同性社区download下来后 ...

  3. sqoop 密码别名模式 --password-alias

    sqoop要使用别名模式隐藏密码 1.首先使用命令创建别名 hadoop credential create xiaopengfei  -provider jceks://hdfs/user/pass ...

  4. ASP.NET Core MVC 之控制器(Controller)

    操作(action)和操作结果(action result)是 ASP.NET MVC 构建应用程序的一个基础部分. 在 ASP.NET MVC 中,控制器用于定义和聚合一组操作.操作是控制器中处理传 ...

  5. UnityShader之积雪效果

    积雪效果是比较简单的,只需要计算顶点法线方向和世界向上方向之间的点乘,将得到的值与预设的阀值比较,小于阀值为0,用这个值进行插值就OK了 代码: Shader "MyShader/SnowS ...

  6. http测试工具

    http测试工具: https://github.com/denji/awesome-http-benchmark wrk https://github.com/wg/wrk wrk2 https:/ ...

  7. Java学习|强引用,软引用,弱引用,幻想引用有什么区别?

    在Java语言中,除了基本数据类型外,其他的都是指向各类对象的对象引用:Java中根据其生命周期的长短,将引用分为4类. 1 强引用 特点:我们平常典型编码Object obj = new Objec ...

  8. sql server数据库查询链接服务器

    服务器对象->链接服务器: 或者 select  * from sys.servers: 找到服务器对象名称 select  * from [服务器对象名称].[数据库名称].dbo.[表名]:

  9. 7.18 collection time random os sys 序列化 subprocess 等模块

    collection模块 namedtuple 具名元组(重要) 应用场景1 # 具名元组 # 想表示坐标点x为1 y为2 z为5的坐标 from collections import namedtu ...

  10. php Basic HTTP与Digest HTTP 应用

    Basic HTTP 认证范例 <?php //Basic HTTP 认证 if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authen ...