Codeforces Round #FF (Div. 2) 题解

Jun 07, 2016 pm 03:31 PM
round 比較する

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p ?-?1 . He

比赛链接:http://codeforces.com/contest/447

A. DZY Loves Hash

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x)?=?x mod p. Operation a mod b denotes taking a remainder after division a by b.

However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1.

Input

The first line contains two integers, p and n (2?≤?p,?n?≤?300). Then n lines follow. The i-th of them contains an integer xi (0?≤?xi?≤?109).

Output

Output a single integer — the answer to the problem.

Sample test(s)

input

10 5
0
21
53
41
53
ログイン後にコピー

output

4
ログイン後にコピー

input

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

output

-1
ログイン後にコピー

链接:http://codeforces.com/contest/447

题意:找出hash时第一次产生冲突的位置。

解题思路:用一个数组表示是否存放有hash之后的元素,0表示这个位置还没有使用过,1表示这个位置上有hash之后的元素(即产生了冲突)。

代码:

#include <cstdio>
#include <cstring>

const int MAXN = 305;
int a[MAXN], p, n, ans = -1;

int main()
{
    bool flag = true;
    scanf("%d%d", &p, &n);
    for(int i = 0; i <br>


<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
B. DZY Loves Strings</p>
<p>
</p>
<p>
time limit per test</p>
1 second
<p>
</p>
<p>
memory limit per test</p>
256 megabytes
<p>
</p>
<p>
input</p>
standard input
<p>
</p>
<p>
output</p>
standard output

<p>
</p>
<p>DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter<span> </span><span><em>c</em></span><span> </span>DZY
 knows its value<span> </span><span><em>w</em><sub><em>c</em></sub></span>.
 For each special string<span> </span><span><em>s</em>?=?<em>s</em><sub>1</sub><em>s</em><sub>2</sub>...<span> </span><em>s</em><sub>|<em>s</em>|</sub></span><span> </span>(<span>|<em>s</em>|</span><span> </span>is
 the length of the string) he represents its value with a function<span> </span><span><em>f</em>(<em>s</em>)</span>, where</p>
<center><img  src="/static/imghw/default1.png" data-src="/inc/test.jsp?url=http%3A%2F%2Fespresso.codeforces.com%2F47c9783b69409ca6ade8e93f7d51bed11f430539.png&refer=http%3A%2F%2Fblog.csdn.net%2Fu010084308%2Farticle%2Fdetails%2F37758201" class="lazy" alt="Codeforces Round #FF (Div. 2) 题解" ></center>
<p>Now DZY has a string<span> </span><span><em>s</em></span>. He wants to
 insert<span> </span><span><em>k</em></span><span> </span>lowercase letters into this string in order to get the largest possible value of the resulting
 string. Can you help him calculate the largest possible value he could get?</p>

<p>
</p>
<p>
Input</p>
<p>The first line contains a single string<span> </span><span><em>s</em> (1?≤?|<em>s</em>|?≤?10<sup>3</sup>)</span>.</p>
<p>The second line contains a single integer<span> </span><span><em>k</em> (0?≤?<em>k</em>?≤?10<sup>3</sup>)</span>.</p>
<p>The third line contains twenty-six integers from<span> </span><span><em>w</em><sub><em>a</em></sub></span><span> </span>to<span> </span><span><em>w</em><sub><em>z</em></sub></span>.
 Each such number is non-negative and doesn't exceed<span> </span><span>1000</span>.</p>

<p>
</p>
<p>
Output</p>
<p>Print a single integer — the largest possible value of the resulting string DZY could get.</p>

<p>
</p>
<p>
Sample test(s)</p>
<p>
</p>
<p>
</p>
<p>
input</p>
<pre class="brush:php;toolbar:false">abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ログイン後にコピー

output

41
ログイン後にコピー

Note

In the test sample DZY can obtain "abcbbc", value?=?1·1?+?2·2?+?3·2?+?4·2?+?5·2?+?6·2?=?41.


链接:http://codeforces.com/contest/447/problem/B

题意:在给出的字符串中增加k个字符,求可以得到的最大权值和。

解题思路:找出最大的位权,将k个有最大位权的字符放到原字符串的末尾,求权值和。ps:答案可能会超出int,要用long long

代码:

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    int k, a[27], imax = -1;
    cin >> s >> k;
    for(int i = 0; i > a[i];
        if(a[i] > imax)
        {
            imax = a[i];
        }
    }
    long long ans = 0;
    int len = s.length();
    for(int i = 0; i <br>

<p>
</p>
<p>
C. DZY Loves Sequences</p>
<p>
</p>
<p>
time limit per test</p>
1 second
<p>
</p>
<p>
memory limit per test</p>
256 megabytes
<p>
</p>
<p>
input</p>
standard input
<p>
</p>
<p>
output</p>
standard output

<p>
</p>
<p>DZY has a sequence<span> </span><span><em>a</em></span>, consisting of<span> </span><span><em>n</em></span><span> </span>integers.</p>
<p>We'll call a sequence<span> </span><span><em>a</em><sub><em>i</em></sub>,?<em>a</em><sub><em>i</em>?+?1</sub>,?...,?<em>a</em><sub><em>j</em></sub></span><span> </span><span>(1?≤?<em>i</em>?≤?<em>j</em>?≤?<em>n</em>)</span><span> </span>a
 subsegment of the sequence<span> </span><span><em>a</em></span>. The value<span> </span><span>(<em>j</em>?-?<em>i</em>?+?1)</span><span> </span>denotes
 the length of the subsegment.</p>
<p>Your task is to find the longest subsegment of<span> </span><span><em>a</em></span>,
 such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.</p>
<p>You only need to output the length of the subsegment you find.</p>

<p>
</p>
<p>
Input</p>
<p>The first line contains integer<span> </span><span><em>n</em> (1?≤?<em>n</em>?≤?10<sup>5</sup>)</span>.
 The next line contains<span> </span><span><em>n</em></span><span> </span>integers<span> </span><span><em>a</em><sub>1</sub>,?<em>a</em><sub>2</sub>,?...,?<em>a</em><sub><em>n</em></sub> (1?≤?<em>a</em><sub><em>i</em></sub>?≤?10<sup>9</sup>)</span>.</p>

<p>
</p>
<p>
Output</p>
<p>In a single line print the answer to the problem — the maximum length of the required subsegment.</p>

<p>
</p>
<p>
Sample test(s)</p>
<p>
</p>
<p>
</p>
<p>
input</p>
<pre class="brush:php;toolbar:false">6
7 2 3 1 5 6
ログイン後にコピー

output

5
ログイン後にコピー

Note

You can choose subsegment a2,?a3,?a4,?a5,?a6 and change its 3rd element (that is a4) to 4.

链接:http://codeforces.com/contest/447/problem/C

题意:从一串数字中选出一个子串,可以改变子串中一个数字的值得到一个新的子串,求最大的递增新子串的长度。

解题思路:

将原数组分割成递增的子串,记录下每个子串的开始和结束位置,以及长度。接下来要分几种情况讨论:1.相邻的两个子串改变一个数字之后,可以合并形成新的递增子串,2.相邻的3个子串,中间子串长度为1,改变中间的数字后可以形成新的递增子串,3.相邻的子串不能合并形成新的递增子串,但是可以在原串的基础上,得到一个长度增加1的新的递增子串(在子串开头位置前有数字,或是结束位置后有数字)。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 100010;
int a[MAXN];
struct P
{
    int l, len, r;
};
P p[MAXN];
int n;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n);
    int t = 0;
    for(int i = 0; i  a[p[i - 1].r - 1] + 1 ||
           a[p[i].l + 1] > a[p[i - 1].r] + 1)
        {
            ans = max(ans, p[i].len + p[i - 1].len);
        }
        if(i >= 2 && 1 == p[i - 1].len &&
           a[p[i].l] > a[p[i - 2].r + 1])
        {
            ans = max(ans, p[i].len + p[i - 2].len + 1);
        }
     //   printf("%d \n", p[i].len);
    }
    printf("%d\n", ans);
    return 0;
}
</algorithm></cstring></cstdio>
ログイン後にコピー


このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

PHPでラウンドは何を意味しますか PHPでラウンドは何を意味しますか Mar 10, 2023 am 10:04 AM

PHP では、round は「丸め」を意味し、浮動小数点数を整数に変換する組み込み関数です。この関数は浮動小数点数を丸め、float 型の整数値を返すことができます。構文は「round(number, precision,mode)」です。 );"。

PHPのround()関数を使って割り算と丸めを行う方法 PHPのround()関数を使って割り算と丸めを行う方法 Mar 21, 2023 pm 04:32 PM

Round() 関数は、PHP 数値書式設定ライブラリの非常に便利な関数で、浮動小数点数を指定された小数点以下の桁数に丸めることができます。ただし、PHP の除算演算では小数が無限になったり、精度が低下したりする可能性があるため、除数の丸めも必要です。次に、PHPのround()関数を使って除算と丸めを行う方法を詳しく説明します。

MySQL で ROUND 関数を使用して小数点以下の桁をインターセプトする方法 MySQL で ROUND 関数を使用して小数点以下の桁をインターセプトする方法 Jul 13, 2023 pm 09:21 PM

MySQL で ROUND 関数を使用して小数点以下の桁数をインターセプトする方法 MySQL では、ROUND 関数を使用して小数点以下の桁数をインターセプトできます。 ROUND 関数は、数値を指定された小数点以下の桁数に丸めます。以下では、ROUND 関数の使用方法を詳しく紹介し、コード例を示します。構文: ROUND(X,D)X は四捨五入される数値を表し、D は保持される小数点以下の桁数を表します。 ROUND 関数を使用して小数点以下の桁数を取得する例: produc という名前のテーブルがあるとします。

ラップトップに適したマウスを選択してください ラップトップに適したマウスを選択してください Jan 02, 2024 pm 09:54 PM

ラップトップではどのようなマウスを使用すればよいですか? ワイヤレス マウスを使用するのが最善です。 1. ワイヤレスマウスはワイヤーが絡まる問題がなく、操作がより便利です。 2. ワイヤレスマウスを装備しているため、ケーブルが煩雑になるのを避け、移動する際により自由になります。 3. ワイヤレスマウスをノートパソコンに接続するためにケーブルを使用する必要がなく、ケーブルが簡単に抜けないため、使用体験が向上します。 4. 出張などの場合は、ワイヤレスマウスの方が持ち運びに便利です。ラップトップでマウスを使用する場合は、ワイヤレスマウスを選択する必要があります。ワイヤレスマウスはケーブルが不要なため、ケーブルの絡まりを避けてより便利に使用できます。同時に、無線マウスの感度と応答速度は有線マウスよりも優れており、作業効率を向上させることができます。長時間使用する場合は充電式を選択することをお勧めします

大学生はどのようなラップトップを選択すべきですか? (大学生はどのようなラップトップを選択すべきですか?) 大学生はどのようなラップトップを選択すべきですか? (大学生はどのようなラップトップを選択すべきですか?) Dec 30, 2023 pm 09:27 PM

大学生に適したノートパソコンの種類は何ですか? ゲーム用ノートパソコンは通常構成を選択できます 大学在学中に基本構成のゲーム用ノートパソコンを購入すると、価格は約5,000元以上になります Savior、Flying Fortress、Shadow Elfなどのブランド適切なローエンドバージョンがあります。選択する際は、より安定性と信頼性が高い Intel の CPU を選択するのが最善であることに注意してください。さらに、16GB のメモリを搭載したローエンド バージョンを選択すると、あらゆるソフトウェアをストレスなく実行できます。グラフィックカードについては、昨年の1650モデルなど、普通の普通の製品を選ぶことをお勧めします。現在市場に出ているコンピューターは費用対効果があまり高くないため、今年のラップトップを購入することはお勧めしません。エントリーレベルのゲーミング ラップトップを選択することが推奨されるのはなぜですか?なぜなら、卒業後は、

TOP10デジタル通貨交換ランキング TOP10デジタル通貨交換ランキング Mar 14, 2025 pm 05:36 PM

2024年にトップ10のデジタル資産取引プラットフォームを推奨し、暗号通貨の世界に安全かつ便利に参加するのに役立ちます!トランザクションのボリューム、セキュリティ、ユーザーエクスペリエンス、取り扱い料などの多次元指標に基づいて、この記事では、スポットや契約などのさまざまなトランザクションタイプをカバーし、初心者やプロの投資家にさまざまな選択肢を提供する10の優れたプラットフォーム(ランキングに関係なく)を選択します。 プラットフォームを選択するときは、独自の投資目標、リスク許容度、経験レベル、プラットフォームセキュリティ、カスタマーサポートなどの要因を考慮する必要があります。 この記事は参照のみです。

浮動小数点数を四捨五入する 1 行の C 関数を作成します。 浮動小数点数を四捨五入する 1 行の C 関数を作成します。 Aug 26, 2023 pm 01:53 PM

ここでは、浮動小数点数を丸めることができる 1 行の C 関数を記述する方法を見ていきます。この問題を解決するには、次の手順に従う必要があります。数値を取得する 数値が正の場合は 0.5 を加算し、そうでない場合は 0.5 を減算します。 型変換を使用して浮動小数点値を整数に変換します。 例 #include<stdio.h> intmy_round(floatnumber){ return(int)(number<0?number - 0.5:数値+0.5);}intmain(){&nbsp

2025年におすすめのビットコイン取引プラットフォームトップ10、初心者におすすめのデジタル通貨取引アプリ 2025年におすすめのビットコイン取引プラットフォームトップ10、初心者におすすめのデジタル通貨取引アプリ Dec 14, 2024 am 09:09 AM

このガイドでは、2025 年に最も信頼できるビットコイン取引プラットフォームのトップ 10 について、メンバーシップ オプション、料金体系、クリエイターにとって重要なセキュリティ対策などを詳しく紹介するとともに、初心者向けのデジタル通貨取引の入門も提供します。

See all articles