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

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 11nn

You perform an algorithm consisting of several steps (steps are 11iiii

When there are less than ii

Now you wonder: what is the value of the xx

Input

The first line contains one integer TT1≤T≤1001≤T≤100TT

Each line contains two space-separated integers nnxx1≤x<n≤1091≤x<n≤109xx

Output

Print TTxx

Example

input

Copy

3
3 1
4 2
69 6

output

Copy

2
4
12

题意:

黑板上写上1~n的数字,第i次操作删掉第i个数(在剩余里数删),保证剩下的数的个数>=i,否则终止,问第x个数为多少?

分析:

删除删的为奇数,剩下的为偶数,

如果n为偶数,则剩下2,4,6,8,……2*n,

如果n为奇数,则剩下2,4,6,8,……2*n,2*n+1

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500005;
const int MOD=1e9+7;
const double PI = acos(-1.0);
int a[N];
int main()
{
    int T;
    ll n,x;
    cin>>T;
    while(T--)
    {
        scanf("%lld%lld",&n,&x);
        ll cnt=n/2;   
        //cout<<cnt<<endl;
        if(x<=cnt)
		{
			printf("%lld\n",x*2);
		}
		else
           printf("%lld\n",x-cnt+n/2*2);     
    }
 
    return 0;
}

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个方阵,要求使一列和一行都为黑色,为最少涂色次数?

分析:

这题很容易想歪,求出行里面白块最少的和里面白块最少的

. . . * *

* * * . *

* * . * *

. . * . *

可能会选第二行和第三列

但第三行和第三列为正确答案

但题意给你说明n*m<4*1e5

直接暴力枚举

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=50005;
const int MOD=1e9+7;
const double PI = acos(-1.0);
int a[N];
string g[N];
ll numR[N],numC[N];
int main()
{
    int T;
    ll n,m;
    cin>>T;
    while(T--)
    {
        scanf("%lld%lld",&n,&m);
        for(int i=0; i<n; i++)
            numR[i]=0;
        for(int i=0; i<m; i++)
            numC[i]=0;
        ll ans=1e9;
        int flag=0;
        for(int i=0; i<n; i++)
        {
            cin>>g[i];
            for(int j=0;j<m;j++)
			{
				if(g[i][j]=='.')
				{
					numR[i]++;
					numC[j]++;
				}
			}
        }
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(g[i][j]=='.') 
                	ans=min(ans,numR[i]+numC[j]-1);
				else
					ans=min(ans,numR[i]+numC[j]);
            }
        }
 
        printf("%lld\n",ans);
 
    }
 
    return 0;
}

 

 

题意:

给你三个字符串s,t,p,p的字符可以任意插入s,问s能否构成t?

分析:

我们发现s只要在t的里面就行,然后判断s和p是否包含全部的t的字符

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=50005;
const int MOD=1e9+7;
const double PI = acos(-1.0);
string s,t,p;

int spnum[105],tnum[105];
int main()
{
    int T;
    ll n,m;
    cin>>T;
    while(T--)
    {
        cin>>s>>t>>p;
        int slen=s.size();
        int tlen=t.size();
        int plen=p.size();

        for(int i=0; i<26; i++)
        {
            spnum[i]=0;
            tnum[i]=0;

        }


        for(int i=0; i<slen; i++)
        {
            spnum[s[i]-'a']++;
        }

        for(int i=0; i<tlen; i++)
        {
            tnum[t[i]-'a']++;

        }
        int flag=0;



        for(int i=0; i<plen; i++)
        {
            spnum[p[i]-'a']++;
        }

        for(int i=0; i<26; i++)
        {
            if(spnum[i]<tnum[i])
            {
                flag=1;
                break;
            }
        }

        int cnt=0;
        for(int i=0; i<t.size(); i++)
        {
            if(t[i]==s[cnt])
            {
                cnt++;
            }
        }
        if(cnt<s.size())
            flag=1;


        if(flag==0)
        {
            printf("YES\n") ;
        }
        else
            printf("NO\n");


    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值