Codeforces ラウンド #240 (ディビジョン 2)_html/css_WEB-ITnose

WBOY
リリース: 2016-06-24 12:06:29
オリジナル
976 人が閲覧しました

500pt:

A. マシュモクとライト

テストごとの制限時間

1 秒

テストごとのメモリ制限

256 メガバイト

入力

標準入力

出力

標準出力

マシュモクは工場で働いています。毎日の終わりには、すべての照明を消さなければなりません。

工場の照明には 1 から n までのインデックスが付けられています。マシュモクの部屋にも、1 から n までのインデックスが付けられた n 個のボタンがあります。マシュモクがインデックス i のボタンを押すと、まだ点灯しているインデックス i 以上のライトがそれぞれ消灯します。

マシュモクはあまり賢くありません。そのため、最初のボタンを押す代わりに、毎晩いくつかのボタンをランダムに押します。彼は今夜、別々のボタン b1、?b2、?...、?bm を押しました(ボタンは指定された順序で連続して押されました)。次に、彼は各ライトについて、このライトを消したボタンのインデックスを知りたいと考えています。ボタン bi のインデックスは、実際には i ではなく bi であることに注意してください。

マシュモクを手伝って、これらのインデックスを印刷してください。

入力

入力の最初の行には、スペースで区切られた 2 つの整数 n と m が含まれています(1 ?≤?n、?m?≤?100)、それぞれ工場出荷時のライトと押されたボタンの数。次の行には、m 個のスペースで区切られた個別の整数 b1,?b2,?...,?bm (1?≤?bi?≤?n) が含まれています。

すべてのボタンを押すと、すべてのライトが消えることが保証されています。 .

出力

スペースで区切られた n 個の整数を出力します。ここで、i 番目の数字は、i 番目のライトをオフにするボタンのインデックスです。

サンプルテスト

入力

5 44 3 1 2
ログイン後にコピー

出力

1 1 3 4 4 
ログイン後にコピー

入力

5 55 4 3 2 1
ログイン後にコピー

出力

1 2 3 4 5 
ログイン後にコピー

最初のサンプルでは、​​ボタン番号 4 を押した後、ライト 4 と 5 はオフになり、ライト 1、2、および3はまだ続いています。次に、ボタン 3 を押すと、ライト 3 も消えます。ボタン 1 を押すとライト 1 と 2 も消灯するため、最後にボタン 2 を押しても効果はありません。したがって、ボタン番号 4 はライト 4 と 5 をオフにし、ボタン番号 3 はライト 3 をオフにし、ボタン番号 1 はライト 1 と 2 をオフにしました。开关ある光、就把比它大的还是-1的值设的该开关

代:

#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>using 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;i<=n;i++)            arr[i]=-1;        cin>>m;        for(int i=0;i<m;i++)        {            int b;            cin>>b;            for(int j=b;j<=n;j++)            {                if(arr[j]==-1)                    arr[j]=b;            }        }        for(int i=1;i<=n;i++)            cout<<arr[i]<<" ";        cout<<endl;    }    return 0;}
ログイン後にコピー

1000pt:


B. マシュモクとトークン

テストごとの制限時間

1 2番目

テストごとのメモリ制限

256 メガバイト

入力

標準入力

出力

標準出力

Bimokh は Mashmokh の上司です。その後の n 日間、彼は従業員に新しい方法で支払うことにしました。毎日の初めに、彼は各労働者に一定量のトークンを与えます。その後、毎日の終わりに、各労働者は自分のトークンの一部を返して、一定の金額を受け取ることができます。ワーカーは残りのトークンを保存できますが、それを他の日に使用してさらにお金を稼ぐことはできません。労働者がバックトークンを与えると、ドルが得られます。

マシュモクはトークンが好きですが、お金の方が好きです。だからこそ、彼はできるだけ多くのトークンを節約して、毎日得られる金額を最大限に高めたいと考えています。彼は n 個の数字 x1、?x2、?...、?xn を持っています。数字 xi は、i 日目に各労働者に与えられたトークンの数です。 n 日ごとに保存できるトークンの数を計算するのを手伝ってください。

入力

入力の最初の行には、スペースで区切られた 3 つの整数 n,?a,?b (1?≤?n?≤?) が含まれています。 105; 1?≤?a、?b?≤?109)。入力の 2 行目には、スペースで区切られた整数 x1、?x2、?...、?xn (1?≤?xi?≤?109) が含まれています。

出力

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 412 6 11 9 1
ログイン後にコピー

output

0 2 3 1 1 
ログイン後にコピー

input

3 1 21 2 3
ログイン後にコピー

output

1 0 1 
ログイン後にコピー

input

1 1 11
ログイン後にコピー

output

分析:数学题,不要理解错题意就行,反正就是不要多拿没用的来token来换钱就行

代码:

#include <stdio.h>int 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 <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>#include <string.h>using namespace std;typedef long long ll;const int N=(int)1e9+1;map<int,bool> visited;int n,k;int main(){    cin>>n>>k;    if(n==1)    {        if(k==0)            cout<<1<<endl;        else            cout<<-1<<endl;        return 0;    }    vector<int> ans;    int t = n/2;    if(t>k)    {        cout<<-1<<endl;        return 0;    }    int avg = k/t;    int last = k-avg*(t-1);    int cur = 1;    for(int i=1;i<t;i++)    {        int score = avg;        ll t1 = (ll)score*(ll)cur;        ll t2 = (ll)score*(ll)(cur+1);        if(t1>N||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 <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>#include <string.h>using 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;}
ログイン後にコピー


関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!