1. 程式人生 > >Codeforces Round # 514(Div. 2)

Codeforces Round # 514(Div. 2)

總結:

這一次前兩個都是水題,著重模擬能力,題意能看的明確,只是一些小細節考慮的不清楚,所以做題還是應該多加細心,做題腦子要清晰,腦子要夠用,加油!!!?。

A. Cashier

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

2 11 3
0 1
1 1

output

Copy

3

input

0 5 2

output

2

input

1 3 2
1 2

output

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行是工作的時間,分別是開始時間與結束時間,在他不工作的時候,可以去吸菸,每間隔a分鐘吸一次煙,問在不影響為顧客服務的時候,可以吸菸多少次。

模擬即可,用陣列來模擬他開始工作與結束的時間,並且再判斷不工作的時間段是否夠他吸一次煙即可。

#include<iostream>
#include<cstdio>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
using namespace std;
int num1[1000100],num2[100100];
int main()
{
    int n,l,a;
    int cnt,sum;
    scanf("%d%d%d",&n,&l,&a);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&num1[i],&num2[i]);
	}
	cnt=0;
	sum=0;
	for(int i=0;i<n;i++)
	{
	     cnt+=(num1[i]-sum)/a;
	     sum=num1[i]+num2[i];
	}
     int L=(l-sum);
     printf("%d\n",cnt+(L/a));
    return 0;
}

B. Forgery

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×3square 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

3 3
###
#.#
###

output

YES

input

3 3
###
###
###

output

NO

input

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

output

YES

input

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

output

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).

模擬題:基本圖形是

###

#.#

###

題目給出的圖形,是否可以通過上面那個基本圖形轉化而來,‘.’代表空,‘#’代表有填充物,我們就假設原始圖形都是 . ,然後用題目給出的基本圖形在上面繪圖,看是否能夠畫出與題目給出的圖形一樣,能就輸出YES,不能就輸出NO。

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=1010;
char g[maxn][maxn];
int flag[maxn][maxn];
int n,m;
int dir[8][2]={1,-1,-1,1,1,1,-1,-1,1,0,0,1,-1,0,0,-1};
int check(int x,int y)
{
	for(int i=0;i<8;i++)
	{
		int xx=x+dir[i][0];
		int yy=y+dir[i][1];
		if(g[xx][yy]=='.')
		  return 0;
	}
	return 1;
}
void change(int x,int y)
{
	for(int i=0;i<8;i++)
	{
		int xx=x+dir[i][0];
		int yy=y+dir[i][1];
		flag[xx][yy]=true;
	}
}
int judge()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(g[i][j]=='#' && flag[i][j]==false)
			return 0; 
		}
	}
	return 1;
}
int main()
{
   	scanf("%d%d",&n,&m);
   	for(int i=0;i<n;i++)
   	   scanf("%s",g[i]);
   	for(int i=1;i<n-1;i++)
   	{
   	   for(int j=1;j<m-1;j++)
	   {
	   	  if(check(i,j))
			change(i,j); 
	   } 
	}
   	if(judge())
   	 printf("YES\n");
   	else
   	 printf("NO\n");
   	 return 0;
} 

C. Sequence Transformation

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=3的時候,特意輸出一下就好了。

n=1             1

n=2             

n=3

n=4

n=5

n=6

n=7

n=8

n=9

n=10

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=1000100;
int n,ans=1;
int main()
{
	scanf("%d",&n);
	while(n)
	{
		if(n==3)
		{
			printf("%d %d %d\n",ans,ans,ans*3);
			break;
		}
		else
		{
			for(int i=0;i<(n+1)/2;i++)
			   printf("%d ",ans);
		}
			n=n/2;
			ans=ans*2;
	}
	return 0;
}