Home  >  Article  >  Web Front-end  >  Codeforces Round #240 (Div. 2)_html/css_WEB-ITnose

Codeforces Round #240 (Div. 2)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:06:291007browse

500pt:

A. Mashmokh and Lights

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mashmokh works in a factory. At the end of each day he must turn off all of the lights.

The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.

Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed mdistinct buttons b1,?b2,?...,?bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.

Please, help Mashmokh, print these indices.

Input

The first line of the input contains two space-separated integers n and m (1?≤?n,?m?≤?100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1,?b2,?...,?bm (1?≤?bi?≤?n).

It is guaranteed that all lights will be turned off after pushing all buttons.

Output

Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.

Sample test(s)

input

5 44 3 1 2

output

1 1 3 4 4 

input

5 55 4 3 2 1

output

1 2 3 4 5 

Note

In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.


分析:弄一个数组,开始初始化为-1,然后每次开关某light,就把比它大的还是-1的值设为该开关

代码:

#include 7d10b7d419803d4062679b4587905232#include 4309a73696dbaeac0ddd115cebb6f9b7#include dab9f699790ab0922e596ecb9f6677d5#include ace372f96ca3ec664acb3aaa2421b04c#include 3551a684f1a745421ff759d399d46a3b#include 5641e239672757671c01dfb14ebc3e70#include 343eafb2ff483d57b45e4bcad1af1468#include e23c27865115669ba6cc99530e9d22b3#include da2c3d4ec9d0ede5770d8970d3e75edc#include 8ff8f0891976e8c430157dde469bf924#include fd21907a0e13328ffda092e1790a5d69#include b9d007fdd0a9230760ee80bd9f78ebf5#include 317e6b6395ab75e70e7f0880af8f6835#include 3f68df5471146346142495b14e43a419#include 45058086eae7db99d2192447a4fd5a2c#include 5f0e0135be24bb6e777387dff70c8994#include e1ef53ce3da5b8481bfc355af26c17a5#include 59b5a21a894e4d7777bb8f3516d0ab02using namespace std;typedef long long ll;const int N=100010;int arr[N];int n;int main(){    while(cin>>n)    {        int m;        for(int i=1;i8aac1ebb4f48afb7ed6044d06bdccf36>m;        for(int i=0;ia37608c8635aef643bfd55e3c6eaa979>b;            for(int j=b;j6550716cf764456843aa8ebe1dd46d5cint n, a, b, x[100000];int main(){	scanf("%d%d%d", &n, &a, &b);	for(int i = 0; i < n; i++)		scanf("%d", &x[i]);	for(int i = 0; i < n; i++)	{		long long tmp = (long long)x[i] * a / b;		printf("%d ", x[i] - (tmp * b % a ? tmp * b / a + 1 : tmp * b / a));	}	getchar(); getchar();	return 0;}

1500pt:

C. Mashmokh and Numbers

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.

In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x,?y) points. At the beginning of the game Bimokh has zero points.

Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.

Please, help him. Find n distinct integers a1,?a2,?...,?an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.

Input

The first line of input contains two space-separated integers n,?k (1?≤?n?≤?105; 0?≤?k?≤?108).

Output

If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1,?a2,?...,?an (1?≤?ai?≤?109).

Sample test(s)

input

5 2

output

1 2 3 4 5

input

5 3

output

2 4 3 7 1

input

7 2

output

-1

Note

gcd(x,?y) is greatest common divisor of x and y.


分析:貌似乱搞搞过了。。。我是先平均每对分担到的k值,然后对于每个k,都用连续的两个值去乘,比如k=4,一共5个数的话,前两队每对得分为2,第一队的两个数为1*2和2*2,第二队的两个数为3*2和4*2,连续的两个数能保证gcd,针对平摊的最后一个k值要特殊处理一下

代码:

#include 7d10b7d419803d4062679b4587905232#include 4309a73696dbaeac0ddd115cebb6f9b7#include dab9f699790ab0922e596ecb9f6677d5#include ace372f96ca3ec664acb3aaa2421b04c#include 3551a684f1a745421ff759d399d46a3b#include 5641e239672757671c01dfb14ebc3e70#include 343eafb2ff483d57b45e4bcad1af1468#include e23c27865115669ba6cc99530e9d22b3#include da2c3d4ec9d0ede5770d8970d3e75edc#include 8ff8f0891976e8c430157dde469bf924#include fd21907a0e13328ffda092e1790a5d69#include b9d007fdd0a9230760ee80bd9f78ebf5#include 317e6b6395ab75e70e7f0880af8f6835#include 3f68df5471146346142495b14e43a419#include 45058086eae7db99d2192447a4fd5a2c#include 5f0e0135be24bb6e777387dff70c8994#include e1ef53ce3da5b8481bfc355af26c17a5#include 59b5a21a894e4d7777bb8f3516d0ab02#include bbed3fed50f96ac7490cfc6a498c4bc5using namespace std;typedef long long ll;const int N=(int)1e9+1;map1de795117e11ccb2ee036aee72a4aedc visited;int n,k;int main(){    cin>>n>>k;    if(n==1)    {        if(k==0)            coutae11667e8e290f52bb1fbb4318904ca0 ans;    int t = n/2;    if(t>k)    {        cout70b2726ad76bcee3a3dc4f45b9de632cN||t2>N)        {            cout<<-1<<endl;            return 0;        }        if(!visited[t1]&&!visited[t2])        {            ans.push_back(t1);            ans.push_back(t2);            visited[t1]=true;            visited[t2]=true;            cur+=2;        }    }    for(int i=1;i<N;i++)    {        if(!visited[i*last]&&!visited[i*last+last])        {            ans.push_back(i*last);            ans.push_back(i*last+last);            visited[i*last+last]=true;            visited[i*last]=true;            break;        }    }    if(ans.size()<n)    {        for(int i=1;i<N;i++)        {            if(!visited[i])            {                ans.push_back(i);                break;            }        }    }    for(int i=0;i<ans.size();i++)        cout<<ans[i]<<" ";    cout<<endl;    return 0;}

2000pt:

D. Mashmokh and ACM

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.

A sequence of l integers b1,?b2,?...,?bl (1?≤?b1?≤?b2?≤?...?≤?bl?≤?n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally  for all i (1?≤?i?≤?l?-?1).

Given n and k find the number of good sequences of length k. As the answer can be rather large print it modulo 1000000007 (109?+?7).

Input

The first line of input contains two space-separated integers n,?k (1?≤?n,?k?≤?2000).

Output

Output a single integer ? the number of good sequences of length k modulo 1000000007 (109?+?7).

Sample test(s)

input

3 2

output

input

6 4

output

39

input

2 1

output

Note

In the first sample the good sequences are: [1,?1],?[2,?2],?[3,?3],?[1,?2],?[1,?3].

分析:早知道应该做这题的,连我都会的dp.....用dp[i][j]表示长度为i,最后一个元素为j的序列数

代码:

#include 7d10b7d419803d4062679b4587905232#include 4309a73696dbaeac0ddd115cebb6f9b7#include dab9f699790ab0922e596ecb9f6677d5#include ace372f96ca3ec664acb3aaa2421b04c#include 3551a684f1a745421ff759d399d46a3b#include 5641e239672757671c01dfb14ebc3e70#include 343eafb2ff483d57b45e4bcad1af1468#include e23c27865115669ba6cc99530e9d22b3#include da2c3d4ec9d0ede5770d8970d3e75edc#include 8ff8f0891976e8c430157dde469bf924#include fd21907a0e13328ffda092e1790a5d69#include b9d007fdd0a9230760ee80bd9f78ebf5#include 317e6b6395ab75e70e7f0880af8f6835#include 3f68df5471146346142495b14e43a419#include 45058086eae7db99d2192447a4fd5a2c#include 5f0e0135be24bb6e777387dff70c8994#include e1ef53ce3da5b8481bfc355af26c17a5#include 59b5a21a894e4d7777bb8f3516d0ab02#include bbed3fed50f96ac7490cfc6a498c4bc5using namespace std;typedef long long ll;const int N=2010;const int MOD = (int)1e9+7;int dp[N][N];int n,k;int main(){    while(cin>>n>>k)    {		memset(dp,0,sizeof(dp));		for(int i=1;i<=n;i++)			dp[1][i]=1;		for(int length=1;length<k;length++)		{			for(int i=1;i<=n;i++)			{				for(int j=1;j*i<=n;j++)				{					dp[length+1][j*i]+=dp[length][i];					dp[length+1][j*i]%=MOD;				}			}		}		int ret = 0;		for(int i=1;i<=n;i++)		{			ret+=dp[k][i];			ret%=MOD;		}		cout<<ret<<endl;    }    return 0;}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn