Codeforces Round #514 (Div. 2) A B C题解

传送门

A. Cashier

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has recently got a job as a cashier at a local store. His day at work is LL minutes long. Vasya has already memorized nn regular customers, the ii-th of which comes after titi minutes after the beginning of the day, and his service consumes lili minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.

Vasya is a bit lazy, so he likes taking smoke breaks for aa minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

Input

The first line contains three integers nn, LL and aa (0≤n≤1050≤n≤105, 1≤L≤1091≤L≤109, 1≤a≤L1≤a≤L).

The ii-th of the next nn lines contains two integers titi and lili (0≤ti≤L−10≤ti≤L−1, 1≤li≤L1≤li≤L). It is guaranteed that ti+li≤ti+1ti+li≤ti+1 and tn+ln≤Ltn+ln≤L.

Output

Output one integer  — the maximum number of breaks.

Examples

input

Copy

2 11 3
0 1
1 1

output

Copy

3

input

Copy

0 5 2

output

Copy

2

input

Copy

1 3 2
1 2

output

Copy

0

Note

In the first sample Vasya can take 33 breaks starting after 22, 55 and 88 minutes after the beginning of the day.

In the second sample Vasya can take 22 breaks starting after 00 and 22 minutes after the beginning of the day.

In the third sample Vasya can't take any breaks.

题意:有一个人在一个商场上班,每天有n个人来访,但是这个人喜欢吸烟。他每天上班时间为L分钟,每次休息吸烟需要a分钟,并且给出n个人到商场的时间以及待多长时间,问你这个人一天最多吸多少次烟

#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long
#define N 0x3f3f3f3f 
using namespace std;
int main()
{
	ll n,l,a;
	cin>>n>>l>>a;
	ll flag=0;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;
		ans+=(x-flag)/a;
		flag=x+y;
	}
	cout<<ans+(l-flag)/a<<endl;
	return 0;
}

B. Forgery

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3 square without its central cell if it is completely contained inside the grid, as shown below.

xxx
x.x
xxx

Determine whether is it possible to forge the signature on an empty n×mn×m grid.

Input

The first line of input contains two integers nn and mm (3≤n,m≤10003≤n,m≤1000).

Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

Output

If Andrey can forge the signature, output "YES". Otherwise output "NO".

You can print each letter in any case (upper or lower).

Examples

input

Copy

3 3
###
#.#
###

output

Copy

YES

input

Copy

3 3
###
###
###

output

Copy

NO

input

Copy

4 3
###
###
###
###

output

Copy

YES

input

Copy

5 7
.......
.#####.
.#.#.#.
.#####.
.......

output

Copy

YES

Note

In the first sample Andrey can paint the border of the square with the center in (2,2)(2,2).

In the second sample the signature is impossible to forge.

In the third sample Andrey can paint the borders of the squares with the centers in (2,2)(2,2) and (3,2)(3,2):

  1. we have a clear paper:
    ...
    ...
    ...
    ...
    
  2. use the pen with center at (2,2)(2,2).
    ###
    #.#
    ###
    ...
    
  3. use the pen with center at (3,2)(3,2).
    ###
    ###
    ###
    ###
    

In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3)(3,3) and (3,5)(3,5).

要伪造医生签名,先给你医生的签名nm的网格'.'表示空白',#'表示墨水,你的笔可以这么画以一个3*3的网格除了中心周围你都能画墨水,问你能不能伪造签名

By henucm, contest: Codeforces Round #514 (Div. 2), problem: (B) Forgery, Accepted, #
 #include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#define ll long long
#define N 0x3f3f3f3f 
using namespace std;
int map[1100][1100];
int mapp[1100][1100];
int find(int i,int j)
{
	if(map[i][j-1]==1&&map[i][j+1]==1&&map[i-1][j]==1&&map[i-1][j-1]==1&&map[i-1][j+1]==1&&
	map[i+1][j]==1&&map[i+1][j-1]==1&&map[i+1][j+1]==1)
	return 1;
	return 0;
}
int main()
{
	int n,m;
	cin>>n>>m;
	memset(map,0,sizeof(map));
	memset(mapp,0,sizeof(mapp));
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			cin>>c;
			if(c=='#')
			map[i][j]=1,ans++;
		}
	}
	int h=0;
	for(int i=2;i<n;i++)
	{
		for(int j=2;j<m;j++)
		{
			//cout<<i<<" "<<j<<endl; 
			//cout<<find(i,j)<<endl;
			if(find(i,j))
			{
			if(mapp[i][j-1]!=map[i][j-1])
			h++,mapp[i][j-1]=map[i][j-1];
			
			if(mapp[i][j+1]!=map[i][j+1])
			h++,mapp[i][j+1]=map[i][j+1];
			
			if(mapp[i-1][j]!=map[i-1][j])
			h++,mapp[i-1][j]=map[i-1][j];
			
			if(mapp[i-1][j-1]!=map[i-1][j-1])
			h++,mapp[i-1][j-1]=map[i-1][j-1];
			
			if(mapp[i-1][j+1]!=map[i-1][j+1])
			h++,mapp[i-1][j+1]=map[i-1][j+1];
			
			if(mapp[i+1][j]!=map[i+1][j])
			h++,mapp[i+1][j]=map[i+1][j];
			
			if(mapp[i+1][j-1]!=map[i+1][j-1])
			h++,mapp[i+1][j-1]=map[i+1][j-1];
			
			if(mapp[i+1][j+1]!=map[i+1][j+1])
			h++,mapp[i+1][j+1]=map[i+1][j+1];
			}
		}
	
	}
	if(h==ans)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
} 

C. Sequence Transformation

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's call the following process a transformation of a sequence of length nn.

If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of nn integers: the greatest common divisors of all the elements in the sequence before each deletion.

You are given an integer sequence 1,2,…,n1,2,…,n. Find the lexicographically maximum result of its transformation.

A sequence a1,a2,…,ana1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bnb1,b2,…,bn, if there is an index ii such that aj=bjaj=bj for all j<ij<i, and ai>biai>bi.

Input

The first and only line of input contains one integer nn (1≤n≤1061≤n≤106).

Output

Output nn integers  — the lexicographically maximum result of the transformation.

Examples

input

3

output

1 1 3 

input

2

output

1 2 

input

1

output

1 

Note

In the first sample the answer may be achieved this way:

  • Append GCD(1,2,3)=1(1,2,3)=1, remove 22.
  • Append GCD(1,3)=1(1,3)=1, remove 11.
  • Append GCD(3)=3(3)=3, remove 33.

We get the sequence [1,1,3][1,1,3] as the result.

题意:给你个n 每次从中任意拿走一个数 使gcd最大 分别输出每次gcd的值

#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#define ll long long
#define N 0x3f3f3f3f
/*
    1
    1 2
    1 1 3
    1 1 2 4
    1 1 1 2 4
    1 1 1 2 2 6
    1 1 1 1 2 2 6
    1 1 1 1 2 2 4 8
    1 1 1 1 1 2 2 4 8
    1 1 1 1 1 2 2 2 4 8
    1 1 1 1 1 1 2 2 2 4 8
    1 1 1 1 1 1 2 2 2 4 4 12
    1 1 1 1 1 1 1 2 2 2 4 4 12
    1 1 1 1 1 1 1 2 2 2 2 4 4 12
    1 1 1 1 1 1 1 1 2 2 2 2 4 4 12
    1 1 1 1 1 1 1 1 2 2 2 2 4 4 8 16

*/

// 首先排除奇数 因为n个连续的数 那么他们的gcd 必定都是1
// 所以先输出n/2个1 然后即使gcd为2 那么他们有 n/2/2个 
// 其实很容易理解 因为都是偶数 2 4 6 8 10 12...
// 我们要再次留下gcd为4 所以得删除偶数的一半 以此类推
// 最后如果剩余三个数则说明 剩下三个树的gcd为qaq 则输出 qaq qaq 3*qaq 类似于 1 2 3 
// 最后剩余两个数 类似于 1 2 若最后只剩下一个数 直接输出qaq 
using namespace std;
int main()
{
	int n;
	cin>>n;
	int qaq=1;
	while(n>=4)
	{
		for(int i=0;i<(n+1)/2;i++)
		cout<<qaq<<" ";
		n/=2;
		qaq*=2;
	}
	if(n==3)
	{
		cout<<qaq<<" "<<qaq<<" "<<3*qaq<<endl;
		return 0;
	}
	if(n==2)
	{
		cout<<qaq<<" "<<2*qaq<<endl;
		return 0;
	}
	if(n==1)
	{
		cout<<qaq<<endl;
		return 0;
	}
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值