Codeforces Round #FF (Div. 2) 题解
比赛链接: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
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>

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP에서 round는 "반올림"을 의미하며 부동 소수점 숫자를 정수로 변환하는 내장 함수입니다. 이 함수는 부동 소수점 숫자를 반올림하고 float 유형의 정수 값을 반환할 수 있습니다. 구문은 "round(number, Precision,mode)입니다. );".

round() 함수는 부동 소수점 숫자를 지정된 소수 자릿수로 반올림할 수 있는 PHP 숫자 형식 라이브러리의 매우 유용한 함수입니다. 그러나 PHP의 나눗셈 연산은 소수점이 무한하거나 정밀도가 손실될 수 있으므로 제수에 대한 반올림도 필요합니다. 다음으로 PHP의 round() 함수를 사용하여 나누기와 반올림하는 방법을 자세히 설명하겠습니다.

MySQL에서 ROUND 함수를 사용하여 소수 자릿수를 가로채는 방법 MySQL에서는 ROUND 함수를 사용하여 소수 자릿수를 가로챌 수 있습니다. ROUND 함수는 숫자를 지정된 소수 자릿수로 반올림합니다. 다음에서는 ROUND 함수의 사용법을 자세히 소개하고 코드 예제를 제공합니다. 구문: ROUND(X,D)X는 반올림할 숫자를 나타내고, D는 유지할 소수 자릿수를 나타냅니다. ROUND 함수를 사용하여 소수 자릿수를 가로채는 예: produc이라는 테이블이 있다고 가정합니다.

노트북에는 어떤 마우스를 사용해야 하나요? 무선 마우스를 사용하는 것이 가장 좋습니다. 1. 무선마우스는 선이 엉키는 문제가 없어 작업이 더욱 편리합니다. 2. 무선 마우스가 장착되어 복잡한 케이블을 피하고 더 자유롭게 이동할 수 있습니다. 3. 무선 마우스를 노트북에 연결하기 위해 케이블을 사용할 필요가 없으며, 케이블이 쉽게 빠지지 않아 사용 경험이 더 좋아집니다. 4. 출장 등의 상황에서는 무선 마우스가 휴대가 더욱 편리합니다. 노트북으로 마우스를 사용할 때에는 무선마우스를 선택해야 합니다. 무선마우스는 케이블이 필요하지 않기 때문에 사용이 더욱 편리하고 케이블이 엉키는 현상을 방지할 수 있습니다. 동시에 무선 마우스의 감도와 응답 속도는 유선 마우스보다 뛰어나 작업 효율성을 향상시킬 수 있습니다. 오랫동안 사용해야 할 경우 충전을 선택하는 것이 좋습니다

대학생들에게 적합한 노트북은 어떤게 있나요? 모두 적합한 저가형 버전이 있습니다. 선택할 때 Intel의 CPU를 선택하는 것이 더 안정적이고 신뢰할 수 있기 때문에 가장 좋습니다. 게다가 메모리도 로우엔드 버전인 16GB를 선택해야 한다. 이런 메모리 용량 덕분에 어떤 소프트웨어든 부담 없이 실행할 수 있다. 그래픽카드에 관해서는 작년에 출시된 1650 모델 등 평범하고 평범한 제품을 선택하는 것을 추천드립니다. 현재 시중에 나와 있는 컴퓨터들은 가격 대비 성능이 별로 좋지 않기 때문에 올해 노트북을 구입하는 것을 추천하지 않습니다. 보급형 게이밍 노트북을 선택하는 것이 권장되는 이유는 무엇입니까? 왜냐하면 졸업 후에는

2024 년에 10 대 디지털 자산 거래 플랫폼을 권장하여 Cryptocurrency World에 안전하고 편리하게 들어가도록 도와줍니다! 거래량, 보안, 사용자 경험 및 처리 요금과 같은 다차원 지표를 기반 으로이 기사는 10 개의 우수한 플랫폼 (순위에 관계없이)을 선택하고 SPOT 및 계약과 같은 다양한 거래 유형을 선택하고 초보자 및 전문 투자자에게 다양한 선택을 제공합니다. 플랫폼을 선택할 때는 자신의 투자 목표, 위험 허용 오차, 경험 수준, 플랫폼 보안 및 고객 지원과 같은 요소를 고려해야합니다. 이 기사는 참조 용입니다. 디지털 자산 투자는 위험이 높습니다.

여기에서는 부동 소수점 수를 반올림할 수 있는 한 줄 C 함수를 작성하는 방법을 살펴보겠습니다. 이 문제를 해결하려면 다음 단계를 따라야 합니다. 숫자 얻기 숫자가 양수이면 0.5를 더하고 그렇지 않으면 0.5를 뺍니다. 유형 변환을 사용하여 부동 소수점 값을 정수로 변환합니다. 예 #include<stdio.h> intmy_round(floatnumber){ return(int)(number<0?number - 0.5:숫자+0.5);}intmain(){ 

이 가이드는 크리에이터에게 중요한 멤버십 옵션, 수수료 구조 및 보안 조치를 포함하여 2025년 가장 신뢰할 수 있는 상위 10개 비트코인 거래 플랫폼에 대해 심층적으로 살펴보는 동시에 초보자를 위한 디지털 통화 거래에 대한 소개도 제공합니다.
