比赛链接: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 < n; i++)
{
int x;
scanf("%d", &x);
if(flag)
{
if(0 == a[x % p])
{
a[x % p] = 1;
}
else
{
ans = i + 1;
flag = false;
}
}
}
printf("%d\n", ans);
return 0;
}
B. DZY Loves Strings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY
knows its value wc.
For each special string s = s1s2... s|s| (|s| is
the length of the string) he represents its value with a function f(s), where

Now DZY has a string s. He wants to
insert k 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?

Input

The first line contains a single string s (1 ≤ |s| ≤ 103).

The second line contains a single integer k (0 ≤ k ≤ 103).

The third line contains twenty-six integers from wa to wz.
Each such number is non-negative and doesn't exceed 1000.

Output

Print a single integer — the largest possible value of the resulting string DZY could get.

Sample test(s)
input
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 < 26; i++)
{
cin >> a[i];
if(a[i] > imax)
{
imax = a[i];
}
}
long long ans = 0;
int len = s.length();
for(int i = 0; i < len; i++)
{
ans += a[s[i] - 'a'] * (i + 1);
}
ans += (long long)imax * k * (2 * len + k + 1) / 2;
cout << ans << endl;
}

C. DZY Loves Sequences
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DZY has a sequence a, consisting of n integers.

We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a
subsegment of the sequence a. The value (j - i + 1) denotes
the length of the subsegment.

Your task is to find the longest subsegment of a,
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.

You only need to output the length of the subsegment you find.

Input

The first line contains integer n (1 ≤ n ≤ 105).
The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In a single line print the answer to the problem — the maximum length of the required subsegment.

Sample test(s)
input
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 < n; i++)
{
scanf("%d", &a[i]);
if(!i)
{
p[t].len++;
p[t].l = p[t].r = i;
continue;
}
if(a[i] <= a[i - 1])
{
t++;
}
if(0 == p[t].len)
{
p[t].l = i;
}
p[t].len++;
p[t].r = i;
}
int ans = p[0].len < n ? p[0].len + 1 : p[0].len;
for(int i = 1; i <= t; i++)
{
ans = max(ans, p[i].len + 1);
if(a[p[i].l] > 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;
}

Codeforces Round #FF (Div. 2) 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. titlesplit

    /** * Created by lkl on 2017/6/26. *///spark-shell --driver-class-path /home/hadoop/test/mysqljdbc.j ...

  2. ElasticSearch在linux上的安装部署全程记录

    由于项目需求,需要在linux平台搭建一套ES服务.在搭建过程中,遇到各种各样的问题.后来都一一解决.现在要记录下来这个过程,以及其中遇到的问题,及其解决方法. 一.环境配置 操作系统:Cent OS ...

  3. SpringBoot自定义错误页面,SpringBoot 404、500错误提示页面

    SpringBoot自定义错误页面,SpringBoot 404.500错误提示页面 SpringBoot 4xx.html.5xx.html错误提示页面 ====================== ...

  4. Orleans学习总结(六)--应用篇

    上一篇Orleans学习总结(五)--监控篇,我们这篇来说说我们项目的应用   这是我们项目的结构图   我们分别来说下各个部分 1.Zookeeper作为集群基础,至少开5个,分别在不同的物理机上 ...

  5. Android开发实战(申明:来源于网络)

    Android开发实战(申明:来源于网络) 地址:http://so.csdn.net/so/search/s.do?q=Android%E5%BC%80%E5%8F%91%E5%AE%9E%E6%8 ...

  6. AIX装机问题123

    好久没有实施,好记性不如好笔记,那就记录下吧 1文件系统创建挂载 通过smit工具很容易简单举例创建一个jfs2类型文件系统并挂载 创建lv smit mklv 创建jfs2类型文件系统 指定lv s ...

  7. thymeleaf 标签的使用

    1.html页面 2.<label class="control-label col-sm-1" for="vehiclesFormalities"> ...

  8. NPOI 自定义单元格背景颜色 XSSFWorkbook - Excel

    x 网上找到了,HSSFWorkbook自定义颜色的例子(讲的还挺细致的),但是XSSFWorkbook确没找到...研究了一下,坑掉了一地... NPOI.XSSF.UserModel.XSSFWo ...

  9. 会话(Session)与cookies

    由于http是无状态的,向服务器发送请求后,服务器解析请求然后返回对应的响应,服务器负责完成这个过程是完全独立的,不会记录前后状态的变化,因此缺少状态记录. 我们分别需要会话和Cookies的技术来保 ...

  10. TIC Read Status此类网络活动提醒隐藏

    这个方法会使得NSLog输出失效,printf正常工作 不推荐使用,应该是很多操作均被关闭,需要详细了解该参数意义 OS_ACTIVITY_MODE = disable