W/Educational Codeforces Round 68 (Rated for Div.

我要补题。。。
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 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
Copy

3
3 1
4 2
69 6

Output
Copy

2
4
12

类似找规律

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<functional>
#include<unordered_map>
#include<stack>
#include<queue>
typedef long long ll;
int main()
{
	int tt;
	scanf("%d",&tt);
	while(tt--)
	{
		ll  n,x;
		scanf("%lld%lld",&n,&x);
		printf("%lld\n",2*x);
	 } 
}
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 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
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)
, (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
考虑i=0时候 就可以统计出每一列的中所需星号个数
对于每一行只要求一次行所需的星号就可以了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string mp[50010];
int numy[50010];
int main()
{
	ios::sync_with_stdio(false);
	int tt;
	cin>>tt;
	while(tt--)
	{
		int n,m;
		cin>>n>>m;
		memset(numy,-1,sizeof(numy));
		for(int i=0;i<n;i++)
		{
			cin>>mp[i];
		}
		int ans=0x3f3f3f3f;
		int numx; 
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				int ss=0;
				if(j==0)
				{
					int s=mp[i][j]=='.'?1:0;
				int x=j-1;
					while(x>=0)
					{
						
						if(mp[i][x]=='.') s++;x--;
					}
					x=j+1;
					while(x<m)
					{
						
						if(mp[i][x]=='.') s++;x++;
					}
					numx=s;
				   	
				}
				ss+=numx;
				if(i==0)
				{
				int sss=mp[i][j]=='.'?1:0;
					int t=i-1;
					while(t>=0)
					{
						
						if(mp[t][j]=='.') sss++;t--;
					}
					t=i+1;
					while(t<n)
					{
					
						if(mp[t][j]=='.') sss++;	t++;
					}
					numy[j]=sss;
				}
				
					ss+=numy[j];
				    if(mp[i][j]=='.') ss-=1;
					
				     ans=ans>ss?ss:ans;
					if(ans==0)
					{
						break;
					}
			
			}
			if(ans==0)
			{
				break;
			}
		}
		cout<<ans<<endl;
	 } 
}

在这里插入图片描述
代码比较乱
想法就是
s t p 都是

  • 将p中每一字符捡一个对应数量的map
  • 考虑遍历s
    对于每个s中的元素如果是成立的情况都应该可以在t中在到对应的相同元素,在while遍历找这个元素的过程中遇到的其他元素都应该是被删减去的(对应map[t[index]]–)
    不成立的情况
  1. map中的某一元素无法–即为0
  2. i循环还未结束,t已经遍历完
  3. s 的大小小于 t
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		map<char ,int >mp1,mp2,mp3;
		cin>>a;
		cin>>b;
		cin>>c;
		for(int i=0;i<a.length();i++ )
		{
			mp1[a[i]]++;
		}
		for(int i=0;i<b.length();i++ )
		{
			mp2[b[i]]++;	
		}
		for(int i=0;i<c.length();i++ )
		{
			mp3[c[i]]++;
		}
		int ff=0;
		if(a.size()>b.size())
		{
			printf("NO\n");
			continue;
		}
		int gs=0;
		int tt=0;
		for(int i=0;i<a.size();i++)
		{
			while(tt<b.size()&&b[tt]!=a[i])
			{
			
				if(mp3[b[tt]]==0)
				{
					ff=1;
					break;
				}
				mp3[b[tt]]--;
				tt++;
			}
			if(tt<b.size()&&b[tt]==a[i]) gs++,tt++;
			if(gs==a.size()) break;
			if(tt==b.size())
			{
				
				ff=1;
				break;
			}
			
			if(ff) break;
		}
		if(!ff&&gs!=a.size())
		{
			ff=1;
		}
		if(tt<b.size()&&!ff)
		{
			
			while(tt<b.size())
			{
				if(mp3[b[tt]]==0)
				{
					ff=1;
					break;
				}
				mp3[b[tt]]--;
				tt++;
			}
		
		}
		if(ff) printf("NO\n");
		else printf("YES\n");
	} 
}
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

games /math
sg函数打表找规律
判断先手必胜还是后手必胜》》》

  • 0为必输点
  • sg[i-1]=0||sg[i-2]=0||sg[i-k]=0那么可以推断该点为必胜点
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		int  n,m;
		cin>>n>>m;
		int sg[100];
		memset(sg,0,sizeof(sg));
		sg[1]=1;
		sg[2]=1;
		sg[0]=0;
		for(int i=3;i<=n;i++)
		{
			if(i-m>=0)
			{
				if(sg[i-1]==0||sg[i-2]==0||sg[i-m]==0)
				{
					sg[i]=1;
				}
			}else 
			{
				if(sg[i-2]==0||sg[i-1]==0)
				{
					sg[i]=1;
				}
			}
		}
		for(int i=0;i<=n;i++)
		{
			printf("%d  %d",i,sg[i]);
			puts("");
		}
	} 
}

AC code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	int tt;
	cin>>tt;
	while(tt--)
	{
		ll n,k;
		cin>>n>>k;
		if(k%3)
		{
			if(n%3==0) printf("Bob\n");
			else printf("Alice\n");
		}else 
		{
			n%=(k+1);
			if(n==k) printf("Alice\n");
			else if(n%3==0) printf("Bob\n");
			else printf("Alice\n");
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值