A. Memory and Crow
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:

  • The crow sets ai initially 0.
  • The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus,ai = bi - bi + 1 + bi + 2 - bi + 3....

Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row.

The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Output

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

Examples
input
5
6 -4 8 -2 3
output
2 4 6 1 3 
input
5
3 -2 -1 5 6
output
1 -3 4 11 6 
Note

In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.

In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

题意:a,b序列满足ai = bi - b(i + 1) + b(i + 2) - b(i + 3)....

给你a序列 输出b序列

题解:观察样咧很容易得出b[i]=a[i]+a[i+1];

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n;
ll a[];
ll b[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]);
b[n]=a[n];
for(int i=n-;i>=;i--)
b[i]=a[i]+a[i+];
cout<<b[];
for(int i=;i<=n;i++)
cout<<" "<<b[i];
cout<<endl;
return ;
}
 
B. Memory and Trident
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion:

  • An 'L' indicates he should move one unit left.
  • An 'R' indicates he should move one unit right.
  • A 'U' indicates he should move one unit up.
  • A 'D' indicates he should move one unit down.

But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.

Input

The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.

Output

If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.

Examples
input
RRU
output
-1
input
UDUR
output
1
input
RUUR
output
2
Note

In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.

In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.

题意:给你一个串4个方向用4个字母表示 形成路径 要求要从起点最终回到起点 问你最少需要更改多少字母(某次的方向)

使得满足条件 回到起点。

题解:对于当前路径 判断起点与终点间的曼哈顿距离为dis

dis%2!=0则无论怎么更改都不能回到起点  (每更改一次方向都会使得距离变化2)

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
char s[];
int main()
{
cin>>s;
int len=strlen(s);
int xx=,yy=;
for(int i=; i<len; i++)
{
if(s[i]=='L')
xx--;
if(s[i]=='R')
xx++;
if(s[i]=='U')
yy++;
if(s[i]=='D')
yy--;
}
if((abs(xx)+abs(yy))%)
cout<<"-1"<<endl;
else
cout<<(abs(xx)+abs(yy))/<<endl;
return ;
}
C. Memory and De-Evolution
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.

In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.

What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?

Input

The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.

Output

Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.

Examples
input
6 3
output
4
input
8 5
output
3
input
22 4
output
6
Note

In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides ab, and c as (a, b, c). Then, Memory can do .

In the second sample test, Memory can do .

In the third sample test, Memory can do: 

.

题意:给你x,y分别为初始等边三角形的边长和目标等边三角形的边长(x>y) 每次只能变化一条边,并且中间三角形为非退化三角形也就是必须是合法的三角形

问你最少的变化次数

题解:逆向思维 由y变到x 贪心使得 某条边增量尽可能大 并且能行成三角形 统计次数

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int x,y;
int a[];
int main()
{
scanf("%d %d",&x,&y);
a[]=y;a[]=y;a[]=y;
int ans=;
while(a[]!=x||a[]!=x||a[]!=x)
{
sort(a,a+);
if(a[]+a[]->=x)
a[]=x;
else
a[]=a[]+a[]-;
ans++;
}
cout<<ans<<endl;
return ;
}

Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心的更多相关文章

  1. Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  2. Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心

    A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. Codeforces Round #370 (Div. 2) A , B , C 水,水,贪心

    A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #376 (Div. 2) A B C 水 模拟 并查集

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #392 (Div. 2) A B C 水 模拟 暴力

    A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  8. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  9. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

随机推荐

  1. windows下svn自动更新

    配置hooks下post-commit.bat文件,文件内容如下 @echo offSET REPOS=%1SET REV=%2SET DIR=%REPOS%/hooksSET PATH=%PATH% ...

  2. 【数论+技巧】神奇的Noip模拟试题第二试 T1 素数统计

    1.      素数统计 (pcount.pas/.c/.cpp) [问题描述] 小tan的老师揣谙戈给同学们布置了一道题,要求统计给定区间内素数的个数.“这不是很简单吗?”小tan忍不住说.揣谙戈冷 ...

  3. c#读取文本文档实践2-计算商品价格

    商品 数量 单价英语 66 100语文 66 80数学 66 100化学 66 40物理 66 60 上面是文本文档中读入的数据. using System; using System.Collect ...

  4. Setup Factory 打包.netframework 2.0

    在setup factory 的安装目录下的Dependencies中新建目录dotnet20/并放入dotnetfx2.0.exe: Dependencies目录中再加xml文件dotnet20.x ...

  5. poj1845 数论

    //Accepted 204K 16MS //约数和 //n=p1^e1*p2^e2***pk^ek //约数和为:(p1^0+p1^1+..+p1^e1)*(p2^0+p2^1+..+p2^e2)* ...

  6. javascript 构造函数中的属性与原型上属性优先级的比较

    备注: 下面这个问题是我前天看书上发现的. 按照我以前的理解, a.rename()这个方法传什么值,结果都会弹出 小a,但我看书上的demo 弹出的是大A.... 我的困惑是:  js的构造函数中的 ...

  7. MVP架构。。。。

    Model-View-Presenter(MVP)概述    MVC模式已经出现了几十年了,在GUI领域已经得到了广泛的应用,由于微软ASP.NET MVC Framework的出现,致使MVC一度成 ...

  8. 12-27cell常用的属性

    1.创建cell //    创建一个cell并且设置cell的风格 UITableViewCell *cell  = [[UITableViewCell alloc]initWithStyle:UI ...

  9. C++ offsetof

    这是一个宏,用于计算类中某个成员的地址相对于类实例的偏移量 在C++11中,要求这个类standard_layout 基本用法是这样子的: #include <stdio.h> /* pr ...

  10. (spring-第15回【IoC基础篇】)容器事件

    五个人在报社订阅了报纸.报社一旦有了新报纸,就派员工分别送到这五个人手里.在这个例子中,“报纸”就是事件,“报社”就是广播器,五个订阅者就是监听器.广播器收到事件,把事件传给监听器,监听器对事件做一些 ...