博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)
阅读量:6292 次
发布时间:2019-06-22

本文共 5117 字,大约阅读时间需要 17 分钟。

A. Splits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n.

For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1].

The following sequences aren't splits of 8: [1, 7], [5, 4], [11,  - 3], [1, 1, 4, 1, 1].

The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split [1, 1, 1, 1, 1] is 5, the weight of the split [5, 5, 3, 3, 3] is 2 and the weight of the split [9] equals 1.

For a given n, find out the number of different weights of its splits.

Input

The first line contains one integer n (1 ≤ n ≤ 109).

Output

Output one integer — the answer to the problem.

Examples
input
Copy
7
output
Copy
4
input
Copy
8
output
Copy
5
input
Copy
9
output
Copy
5
Note

In the first sample, there are following possible weights of splits of 7:

Weight 1: []

Weight 2: [, 1]

Weight 3: [, 1]

Weight 7: []

把一个数分为不同的集合(元素可以重复),和为n

n是奇数,长度为n的,n/2+1,。。。1(长度为2不存在)

n是偶数,长度为n,长度为n/2。。。1(均可以存在)

所以结论就是n/2+1

#include 
using namespace std;typedef long long ll;int main(){ int n; cin>>n; cout<
B. Messages
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.

Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.

Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.

Determine the maximum amount of money Vasya's bank account can hold after T minutes.

Input

The first line contains five integers nABC and T (1 ≤ n, A, B, C, T ≤ 1000).

The second string contains n integers ti (1 ≤ ti ≤ T).

Output

Output one integer  — the answer to the problem.

Examples
input
Copy
4 5 5 3 5 1 5 5 4
output
Copy
20
input
Copy
5 3 1 1 3 2 2 2 1 1
output
Copy
15
input
Copy
5 5 3 4 5 1 2 3 4 5
output
Copy
35
Note

In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.

In the second sample the messages can be read at any integer moment.

In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.

昨天晚上没有这个Note啊,毒瘤

所以就是看下(T-t[i])*(c-b)的正负啊,%%%聚聚

#include 
using namespace std;typedef long long ll;long long ans;int t[1005];int main(){ int n,a,b,c,T; cin>>n>>a>>b>>c>>T; for(int i=1;i<=n;i++) cin>>t[i]; for(int i=1;i<=n;i++) if((T-t[i])*(c-b)<=0) ans+=a; else ans+=a+(T-t[i])*(c-b); cout<
C. Alternating Sum
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two integers aa and bb. Moreover, you are given a sequence s0,s1,,sns0,s1,…,sn. All values in ss are integers 11 or 1−1. It's known that sequence is kk-periodic and kk divides n+1n+1. In other words, for each kink≤i≤n it's satisfied that si=siksi=si−k.

Find out the non-negative remainder of division of ni=0sianibi∑i=0nsian−ibi by 109+9109+9.

Note that the modulo is unusual!

Input

The first line contains four integers n,a,bn,a,b and k(1n109,1a,b109,1k105)(1≤n≤109,1≤a,b≤109,1≤k≤105).

The second line contains a sequence of length kk consisting of characters '+' and '-'.

If the ii-th character (0-indexed) is '+', then si=1si=1, otherwise si=1si=−1.

Note that only the first kk members of the sequence are given, the rest can be obtained using the periodicity property.

Output

Output a single integer — value of given expression modulo 109+9109+9.

Examples
input
Copy
2 2 3 3 +-+
output
Copy
7
input
Copy
4 1 5 1 -
output
Copy
999999228
Note

In the first example:

(ni=0sianibi)(∑i=0nsian−ibi) = 22302131+20322230−2131+2032 = 7

In the second example:

(ni=0sianibi)=14501351125211531054=781999999228(mod109+9)(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9).

等比数列啊,但是等比数列的比可以是1,记得判断

#include 
using namespace std;typedef long long ll;const ll MD=1e9+9;ll po(ll a,ll b){ ll ans=1; while(b) { if(b&1)ans=ans*a%MD; b>>=1,a=a*a%MD; } return ans;}int main(){ ll n,a,b,k; cin>>n>>a>>b>>k; string s; cin>>s; ll cur=0; for(int i=0;i

 

转载于:https://www.cnblogs.com/BobHuang/p/8872307.html

你可能感兴趣的文章
域控制器建立教程
查看>>
RHCE 学习笔记(20) ACL
查看>>
Django 和 Ajax 简介
查看>>
Qt的一个颜色选取按钮QColorButton
查看>>
perl 散列数组
查看>>
puppet之service管理
查看>>
Exchange2010server证书申请及分配服务
查看>>
Cassandra 处理客户端请求
查看>>
[WinApi]邮槽通信C/S实例
查看>>
linux NFS配置:NFS相关概念及其配置与查看
查看>>
需求转化到文档维护
查看>>
《互联网运营智慧》第7章“简单cdn”正式版下载
查看>>
如何解决SQL Server 2008 R2中“阻止保存要求重新创建表的更改”的问题!
查看>>
基于Xcode原型驱动的iOS应用设计
查看>>
SOA标准之----SCA架构思想
查看>>
9.VMware View 4.6安装与部署-connection server(View Replica Server)
查看>>
项目管理和产品管理绉议
查看>>
Rafy 领域实体框架设计 - 重构 ORM 中的 Sql 生成
查看>>
编程之基础:数据类型(二)
查看>>
倒排索引PForDelta压缩算法——基本假设和霍夫曼压缩同
查看>>