Codeforces Round #240 (Div. 2)

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 m distinct 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.

Examples
Input
Copy
5 4
4 3 1 2
Output
1 1 3 4 4 
Input
Copy
5 5
5 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.

题意:有n个灯,m个开关,给你m个开关的编号,每按一个开关i能够关掉>=i的灯,输出每个灯对应的开关编号。

思路:模拟遍历即可

#include<stdio.h>
#include<string.h>
const int maxn = 110;
int num[maxn],book[maxn],vis[maxn];
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(book,0,sizeof(book));
		for(int i = 0; i < m; i ++)
		{
			scanf("%d",&num[i]);
			for(int j = num[i]; j <= n; j ++)
			{
				if(!book[j])
				{
					book[j] = 1;
					vis[j] = num[i];
				}
			}
		}
		for(int i = 1; i < n; i ++)
		{
			printf("%d ",vis[i]);
		}	
		printf("%d\n",vis[n]);
		
	}
	return 0;
}



B. Mashmokh and Tokens
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back w tokens then he'll get dollars.

Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1, x2, ..., xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

Input

The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).

Output

Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

Examples
Input
Copy
5 1 4
12 6 11 9 1
Output
0 2 3 1 1 
Input
Copy
3 1 2
1 2 3
Output
1 0 1 
Input
Copy
1 1 1
1
Output
0 

题意:输入n,a,b,再输入n个数,表示每个工人每天可以拿到的物件数w,工人每天可以将物件换成钱数的公式:w*a/b,输出每天工人留下的物件数。

思路:当w*a%b==0时,说明所有物件都可以换成钱,那么直接输出0,否则的话,计算出每个工人能得到的钱数y=w*a/b,对最小件数y*b/a向上取整就得到了整数的最小件数(比如计算出得到最多的钱所需的最小件数为4.8,但是物件必须为整并且不能取比当前数更小的整数,否则无法得到最多钱数,所以只能向上取整得到5),用当前物件数减去最小件数就是留下的物件数

#include<stdio.h>
#include<math.h>
const int maxn = 100100;
long long  vis[maxn],vis2[maxn];

int main()
{
	long long  n,a,b;
	while(scanf("%lld%lld%lld",&n,&a,&b)!=EOF)
	{
		for(long long  i = 0; i < n; i ++)
			scanf("%lld",&vis[i]);
		int k = 0;
		for(long long  i = 0; i < n; i ++)
		{
			if((vis[i]*a)%b == 0)
				vis[i] = 0;
			else
			{
				long long w = vis[i]*a/b;
				long long x = (long long )ceil(w*1.0/a*1.0*b);//向上取整函数 
				vis[i] = vis[i] - x;
			}
				
		}
		for(long long  i = 0; i < n; i ++)
			printf("%lld ",vis[i]);
		
		printf("\n");
	}
	return 0;
}
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).

Examples
Input
Copy
5 2
Output
1 2 3 4 5
Input
Copy
5 3
Output
2 4 3 7 1
Input
Copy
7 2
Output
-1
Note

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


题意:输入n,m,找到一个序列满足这n个数完全不相同并且所有的两个数公约数的总和为m。

思路:大致分为三种情况进行讨论:

第一种:n/2 > k,不存在序列满足这一条件,因为两个数最小的公约数为1,那么这n/2对数最小的公约数之和只能为n/2,k<n/2这种情况下,显然无法找到满足这一条件的序列

第二种:n/2==k,那么只需要输出n/2对公约数为1的数。

第三种:n/2<k,第一对数需满足公约数为k-(n/2-1),其余n/2-1对数满足公约数为n/2-1即可。

注意:当n==1&&k!=0这种情况也是不存在满足条件的序列滴,,emm,还有就是,当n为奇数时,最末尾的数可以为规定范围的任意数,所以这道题答案不唯一啊。

总结:以后注意分类讨论哇,自己注意注意~~~

#include<stdio.h>

int gcd(int a,int b)
{
	if(a%b == 0)
		return b;
	return gcd(b,a%b);
}

int main()
{
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		if(n/2 > k||(n==1&&k!=0))
		{
			printf("-1");
		}
		else if(n/2 == k)//当对数等于点数时,直接输出所有对数公约数为1的数 
		{
			for(int i = 1; i <= n; i ++)	
				printf("%d ",i);
		}
		else if(n/2 < k)//当所需对数小于点数时,令除了第一对数之外的对数的公约数之和为n/2-1 
		{
			printf("%d %d ",k-(n/2-1),(k-(n/2-1))*2);
			for(int i = (k-(n/2-1))*2+1; i <= (k-(n/2-1))*2+n-2; i ++)
				printf("%d ",i);
		}
			printf("\n");
	}
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值