Codeforces 712A Memory and Crow 水题
2016-11-30 21:04
323 查看
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
output
input
output
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.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll n;
ll a[100005];
ll re[100005];
int main(int argc, char** argv)
{
scanf("%I64d",&n);
for(int i=1;i<=n;i++)
scanf("%I64d",&a[i]);
re
= a
;
for(int i =1;i<n;i++)
re[i] = a[i]+a[i+1];
for(int i=1;i<=n;i++)
printf("%I64d ",re[i]);
return 0;
}
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.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll n;
ll a[100005];
ll re[100005];
int main(int argc, char** argv)
{
scanf("%I64d",&n);
for(int i=1;i<=n;i++)
scanf("%I64d",&a[i]);
re
= a
;
for(int i =1;i<n;i++)
re[i] = a[i]+a[i+1];
for(int i=1;i<=n;i++)
printf("%I64d ",re[i]);
return 0;
}
相关文章推荐
- Codeforces 451B Sort the Array(水题)
- Codeforces--400A--Inna and Choose Options(模拟水题)
- CodeForces 732A Buy a Shovel (水题)
- Triangle - CodeForces 407A 水题
- codeforces 653A A. Bear and Three Balls(水题)
- Codeforces 459A Pashmak and Garden(水题)
- Codeforces 638A Home Numbers 【水题】
- Codeforces 735B Urbanization【水题】
- Codeforces 659A Round House【水题,细节】
- Codeforces--584A--Olesya and Rodion(水题)
- CodeForces 707A Brain's Photos (水题)
- codeforces 569B B. Inventory(水题)
- Codeforces 766C. Mahmoud and a Message 水题详解+错点记录
- codeforces 141A Amusing Joke(模拟水题)
- Codeforces 557A Ilya and Diplomas 【水题】
- CodeForces 711B. Chris and Magic Square(水题)
- codeforces 669A A. Little Artem and Presents(水题)
- CodeForces 534D-B - Handshakes-模拟水题
- codeforces 672B B. Different is Good(水题)
- Codeforces 96A: Football(水题)