点我看题目

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.

题意 : 如果按下一个开关,所有编号比这个开关的编号大的灯都会被关掉,让你输出n盏灯分别是被那个开关关上的。

思路 :也算是一个小标记吧。

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map> using namespace std ; int b[] ;
int a[] ;
int main()
{
int n,m ;
while (~scanf("%d %d",&n,&m))
{
for(int i = ; i <= m ; i++)
scanf("%d",&b[i]) ;
memset(a,,sizeof(a)) ;
for(int i = ; i <= m ; i++)
{
for(int j = b[i] ; j <= n ; j++)
{
if(a[j] == )
a[j] = b[i] ;
}
}
for(int i = ; i < n ; i++)
printf("%d ",a[i]) ;
printf("%d\n",a[n]) ;
}
return ;
}

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 backw 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 containsn 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.

Sample test(s)
input
5 1 4
12 6 11 9 1
output
0 2 3 1 1 
input
3 1 2
1 2 3
output
1 0 1 
input
1 1 1
1
output

0

题意:如果一个人有w张票,那他会得到w*a/b取整个钱,现在让你在保证得到的钱数不变的情况下能够省得最多的票是多少。

思路 : 我一开始是这么想的,如果有4张票,a是3,b是7,那就是取余一下,3*4%7得到的就是省下来的,真是脑子崩溃了啊,3*4得到12这个数而非12张票,所以怎么可能我只有4张票却能够省掉5张呢?我真是让自己佩服死了,脑子居然没转转。所以就是要保证能够得到1个钱的情况下,让4减小,如果变为3,则还能得到一个钱,但是如果变为2就会变为0个钱了,所以只要找出那个满足这个式子的最大值,然后4减去这个最大值就行了。
 #include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; long long aa[] ;
int main()
{
long long n,a,b ;
while(cin>>n>>a>>b)
{
for(int i = ; i <= n ; i++)
cin>>aa[i] ;
for(int i = ; i <= n ; i++)
cout<<aa[i]*a%b/a<<" " ;
cout<<endl ;
}
return ;
}

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.

题意 : 给你n和k,让你找出n个完全不一样的数,要求gcd(a1,a2)+gcd(a3,a4)+.....+gcd(an-1,an) = k。如果n是奇数则最后那个数就不用算了就是要满足gcd(a1,a2)+....+gcd(an-2,an-1) = k。

思路 : 比赛的时候已经让B题搞透支了,所以一时都没想到这其实也是一道水题啊!!!你只要把第一组的那个最大公约数求出来,然后让后边的全都互质不就行了。

 #include <stdio.h>
#include <string.h> using namespace std ; int main()
{
int n , k;
while(~scanf("%d %d",&n,&k))
{
if(k < n/ || (n < && k != ))
{
printf("-1\n") ;
continue ;
}
else if(k == n/)
{
for(int i = ; i < n ; i++)
printf("%d ",i) ;
printf("%d\n",n) ;
}
else
{
int flag[] ;
memset(flag,,sizeof(flag));
int x = k-n/+ ;
printf("%d %d ",x,x*) ;
for(int i = x*+ ; i <= x*+n- ; i++)
printf("%d ",i) ;
puts("") ;
}
}
return ;
}

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
5
input
6 4
output
39
input
2 1
output
2
Note

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

题意 : 给你两个数n和k,让你找满足一下条件的数列个数,数列里的所有数大小都不超过n,数列长度为k,数列的每后一个数都是前一个数的整数倍。

思路 : DP。比赛的时候压根儿都没看这个题,比完了补得题。因为后一个是前一个的倍数,所以我们说每一个状态都只跟前一个状态有关。dp[i][j]代表的以 i 为结尾长度为j的数列的个数,也就是说,指的是第j为是 i 的数列个数。

dp[p][j + 1] = dp[p][j + 1] + dp[i][j];(p是i的整数倍)

 #include <stdio.h>
#include <string.h> using namespace std ; const int maxn = ;
const int MOD = ; int dp[maxn][maxn] ; int main()
{
int n,k ;
while(~scanf("%d %d",&n,&k))
{
int num = ;
for(int i = ; i < maxn ; i++)
dp[i][] = ;
for(int j = ; j < k ; j++)
{
for(int i = ; i <= n ; i ++)
{
for(int h = i ; h <= n ; h += i)
{
dp[h][j+] = (dp[h][j+]+dp[i][j])%MOD ;
}
}
}
for(int i = ; i <= n ; i++)
{
num += dp[i][k] ;
num %= MOD ;
}
printf("%d\n",num) ;
}
return ;
}

Codeforces Round #240 (Div. 2)(A -- D)的更多相关文章

  1. Codeforces Round #316 (Div. 2) (ABC题)

    A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...

  2. Codeforces Round #324 (Div. 2) (哥德巴赫猜想)

    题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...

  3. Codeforces Round #395 (Div. 2)(未完)

    2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...

  4. B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

    ---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...

  5. 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)

    题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...

  6. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...

  7. Codeforces Round #671 (Div. 2) (A~E)

    Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...

  8. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  9. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

随机推荐

  1. web安全实战

    前言 本章将主要介绍使用Node.js开发web应用可能面临的安全问题,读者通过阅读本章可以了解web安全的基本概念,并且通过各种防御措施抵御一些常规的恶意攻击,搭建一个安全的web站点. 在学习本章 ...

  2. asp.net连接oracle的问题及方法总结

    .net连oracle数据库的两个方法介绍1. 安装oracle客户端,连接oracle 需要在客户端%oracle_client_home%network/admin/配置tnsnames.ora, ...

  3. ###《VIM实用技巧》

    ###<VIM实用技巧> #@author: gr #@date: 2015-11-20 #@email: forgerui@gmail.com <VIM实用技巧>阅读笔记. ...

  4. Cocos2d-x数据持久化-修改数据

    修改数据时,涉及的SQL语句有insert.update和delete语句,这3个SQL语句都可以带参数.修改数据的具体步骤如下所示.(1) 使用sqlite3_open函数打开数据库.(2) 使用s ...

  5. requirejs实验001.对我来说,用AMD的方式来组织代码并不轻松.

    http://www.requirejs.org/ http://www.requirejs.cn/ http://requirejs.readthedocs.org/en/1.0.1/ 目录结构: ...

  6. AE实现投影定义和投影转换

    添加引用ESRI.ArcGIS.DataManagementTools 1.获取要定义和要转换的投影 IWorkspaceFactory wsf = new ShapefileWorkspaceFac ...

  7. 04_例子讲解:rlViewDemo.exe

    参考资料:http://www.roboticslibrary.org/tutorials/first-steps-windows 使用rlViewDemo对应的快捷方式启动程序,可以看到如下界面: ...

  8. 如何在Android SDK 下查看应用程序输出日志的方法

          该文章源于安卓教程网(http://android.662p.com),转载时要注明文章的来自和地址,感谢你的支持. 在Android程序中可以使用 android.util.Log 类来 ...

  9. RestFul && HATEOAS && Spring-Data-Rest介绍

    1.什么是RestFul 经常上网的同学会发现,现代软件的一个重要趋势就是互联网化,几乎没有一款软件是纯粹的单机版了.通常的情况下,软件管理着服务器的资源以及这些资源的状态变化,用户通过在浏览器输入h ...

  10. PySide 简易教程<一>-------Hello PySide

    PySide 是一个python绑定的跨平台GUI Qt库.目前,支持Python的Qt库有两个PyQt和PySide.PySide是一个免费的软件,与PyQt不同之处在于使用了LGPL,允许PySi ...