Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)
1 second
256 megabytes
standard input
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.
The first line contains one integer n (1 ≤ n ≤ 109).
Output one integer — the answer to the problem.
7
4
8
5
9
5
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin>>n;
cout<<n/+;
return ;
}
1 second
256 megabytes
standard input
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.
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000).
The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer — the answer to the problem.
4 5 5 3 5
1 5 5 4
20
5 3 1 1 3
2 2 2 1 1
15
5 5 3 4 5
1 2 3 4 5
35
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long ans;
int t[];
int main()
{
int n,a,b,c,T;
cin>>n>>a>>b>>c>>T;
for(int i=;i<=n;i++)
cin>>t[i];
for(int i=;i<=n;i++)
if((T-t[i])*(c-b)<=)
ans+=a;
else
ans+=a+(T-t[i])*(c-b);
cout<<ans;
return ;
}
1 second
256 megabytes
standard input
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 k≤i≤nk≤i≤n it's satisfied that si=si−ksi=si−k.
Find out the non-negative remainder of division of n∑i=0sian−ibi∑i=0nsian−ibi by 109+9109+9.
Note that the modulo is unusual!
The first line contains four integers n,a,bn,a,b and kk (1≤n≤109,1≤a,b≤109,1≤k≤105)(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 a single integer — value of given expression modulo 109+9109+9.
2 2 3 3
+-+
7
4 1 5 1
-
999999228
In the first example:
(n∑i=0sian−ibi)(∑i=0nsian−ibi) = 2230−2131+20322230−2131+2032 = 7
In the second example:
(n∑i=0sian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9).
等比数列啊,但是等比数列的比可以是1,记得判断
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MD=1e9+;
ll po(ll a,ll b)
{
ll ans=;
while(b)
{
if(b&)ans=ans*a%MD;
b>>=,a=a*a%MD;
}
return ans;
}
int main()
{
ll n,a,b,k;
cin>>n>>a>>b>>k;
string s;
cin>>s;
ll cur=;
for(int i=;i<k;i++)
{
if(s[i]=='+')cur=(cur+po(a,n-i)*po(b,i)%MD)%MD;
else cur=(cur-po(a,n-i)*po(b,i)%MD+MD)%MD;
}
ll t=po(a,k*(MD-)%(MD-))*po(b,k)%MD;
if(t==)
cout<<cur*((n+)/k)%MD;
else
cout<<cur*po(t-,MD-)%MD*(po(t,(n+)/k)-)%MD;
return ;
}
Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)的更多相关文章
- Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1) 963B 964D B Destruction of a Tree
题 OvO http://codeforces.com/contest/963/problem/B CF 963B 964D 解 对于题目要求,显然一开始的树,要求度数为偶数的节点个数为奇数个,通过奇 ...
- Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)D. Frequency of String
题意:有一个串s,n个串模式串t,问s的子串中长度最小的包含t k次的长度是多少 题解:把所有t建ac自动机,把s在ac自动机上匹配.保存每个模式串在s中出现的位置.这里由于t两两不同最多只有xsqr ...
- Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)
A. Alternating Sum 就是个等比数列,特判公比为 $1$ 的情况即可. #include <bits/stdc++.h> using namespace std; ; ; ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- Codeforces 932 A.Palindromic Supersequence (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分 ...
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A
2018-02-19 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 mega ...
- Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)
思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...
- ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)
靠这把上了蓝 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces 932 C.Permutation Cycle-数学 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- c/c++的const和static区别
C语言中的const和static用来修饰变量或者函数,用const修饰表示不可改变,用static修饰表示变量或者函数是静态的,作用域控制在函数内. const定义的常量在超出其作用域之后其空间会被 ...
- asterisk-java ami2 事件监听
asteriskServer文章1提到啦怎么获取,就不解释 asteriskServer.addChainListener(new AsteriskeventListenerInit());//整个服 ...
- 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her s ...
- Oracle CRS/GI 进程介绍
在10g和11.1,Oracle的集群称为CRS(Oracle Cluster Ready Service), 在11.2,Oracle的集群称为GI(Grid Infrastructure). 对于 ...
- [手势识别] CNN + OpenCV 手势识别记录
这几天没事,想着再学点一些视觉识别方向的东西,因为之前做了验证码识别,有了机器学习的信心,因此这次打算做个手势识别,参考了很多网上的图像处理方式,中间也遇到了很多问题,最终算是做出来了吧. 1.训练集 ...
- groupmod - 修 改 群 组
总览 SYNOPSIS groupmod [-g gid [-o]] [-n group_name ] group 描述 DESCRIPTION groupmod 命 令 会 参 照 你 命 令 列 ...
- 禁止DataGridView控件中添加和删除行
实现效果: 知识运用: DataGridView控件的AllowUserToAddRows AllowUserDeleteRows和ReadOnly属性 实现代码: private void btn_ ...
- python递归与非递归实现斐波那契数列
1.题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). 递归实现: class Solution(): def Fibnacci(self ...
- PAT (Basic Level) Practise (中文)-1019. 数字黑洞 (20)
http://www.patest.cn/contests/pat-b-practise/1019 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第 ...
- [转载]matlab图像处理为什么要归一化和如何归一化
matlab图像处理为什么要归一化和如何归一化,一.为什么归一化1. 基本上归一化思想是利用图像的不变矩寻找一组参数使其能够消除其他变换函数对图像变换的影响.也就是转换成唯一的标准形式以抵抗仿射变 ...