Codeforces Round #370 (Div. 2) A , B , C 水,水,贪心
2 seconds
256 megabytes
standard input
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?
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.
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.
5
6 -4 8 -2 3
2 4 6 1 3
5
3 -2 -1 5 6
1 -3 4 11 6
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[i]+a[i+1];
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
ll a[N];
int main()
{
int x;
scanf("%d",&x);
for(int i=;i<=x;i++)
scanf("%lld",&a[i]);
for(int i=;i<=x;i++)
printf("%lld ",a[i]+a[i+]);
return ;
}
2 seconds
256 megabytes
standard input
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.
The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.
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.
RRU
-1
UDUR
1
RUUR
2
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.
题意:上下左右的走,问最少变几步可以回到原点;
思路:奇数步,显然不能回到,ans=(abs(l-r)+abs(u-d))/ 2;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
char a[N];
int flag[];
int main()
{
int x;
scanf("%s",a);
x=strlen(a);
if(x&)
{
printf("-1\n");
return ;
}
for(int i=;i<x;i++)
{
if(a[i]=='U')
flag[]++;
if(a[i]=='D')
flag[]++;
if(a[i]=='L')
flag[]++;
if(a[i]=='R')
flag[]++;
}
printf("%d\n",(abs(flag[]-flag[])+abs(flag[]-flag[]))/);
return ;
}
2 seconds
256 megabytes
standard input
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?
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.
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.
6 3
4
8 5
3
22 4
6
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 a, b, 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的等边三角形;
思路:贪心,从y往上最大的改变;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int a[];
int main()
{
int x,y;
scanf("%d%d",&x,&y);
for(int i=;i<=;i++)a[i]=y;
int ans=;
while()
{
if(a[]==x&&a[]==x&&a[]==x)
break;
sort(a+,a+);
a[]=min(x,a[]+a[]-);
ans++;
}
cout<<ans<<endl;
return ;
}
Codeforces Round #370 (Div. 2) A , B , C 水,水,贪心的更多相关文章
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题
C. Memory and De-Evolution 题目连接: http://codeforces.com/contest/712/problem/C Description Memory is n ...
- Codeforces Round #370 (Div. 2) B. Memory and Trident 水题
B. Memory and Trident 题目连接: http://codeforces.com/contest/712/problem/B Description Memory is perfor ...
- Codeforces Round #370 (Div. 2) A. Memory and Crow 水题
A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)
题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树
E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心
地址:http://codeforces.com/problemset/problem/712/C 题目: C. Memory and De-Evolution time limit per test ...
- Codeforces Round #370 (Div. 2)B. Memory and Trident
地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 se ...
- Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划
D. Memory and Scores 题目连接: http://codeforces.com/contest/712/problem/D Description Memory and his fr ...
随机推荐
- Django基础流程
软件环境: Pycharm 2018.1 Python 3.6 Django 2.0.3 1.新建项目 直接使用Pycharm的菜单来创建项目,命名为mysite. mysite mysite __i ...
- MySQL权限系统(二). MySQL提供的特权 Privileges Provided by MySQL
MySQL provides privileges that apply in different contexts and at different levels of operation: Adm ...
- Mysql在大型网站的应用架构演变(转)
原文: Mysql在大型网站的应用架构演变 本文已经被多处转载,包括CSDN推荐以及码农周刊等等,阅读数超过5w+,回流到我博客流量的还是比较少,不过这不重要, 后续会分享更多技术,尽量试图把自己理解 ...
- python函数回顾:setattr()
描述 setattr 函数对应函数 getatt(),用于设置属性值,该属性必须存在. 语法 setattr 语法: setattr(object, name, value) 参数 object -- ...
- 前端之 JS 实现全选、反选、取消选中
需求 制作如下可选表格,实现“全选”.“反选”.“取消”功能 代码示例 <!DOCTYPE html> <html lang="zh-CN"> <he ...
- 我的Java开发学习之旅------>Eclipse 项目有红感叹号解决之道
今天一个读者问我关于Android通过调用Webservice实现天气预报这篇文章的源码下载后出现的错误 Could not find class 'org.ksoap2.transport.Http ...
- 图的遍历:DFS和BFS
图的遍历一般由两者方式:深度优先搜索(DFS),广度优先搜索(BFS),深度优先就是先访问完最深层次的数据元素,而BFS其实就是层次遍历,每一层每一层的遍历. 1.深度优先搜索(DFS) 我一贯习惯有 ...
- 深度学习:Keras入门(一)之基础篇(转)
转自http://www.cnblogs.com/lc1217/p/7132364.html 1.关于Keras 1)简介 Keras是由纯python编写的基于theano/tensorflow的深 ...
- Parzen-Window Density Estimation(PWDE)
1.概率密度函数 在在数学中,连续型随机变量的概率密度函数(在不至于混淆时可以简称为密度函数)是一个描述这个随机变量的输出值,在某个确定的取值点附近的可能性的函数.而随机变量的取值落在某个区域之内的概 ...
- Oracle 11G无法导出空表的解决办法
11G中有个新特性,当表无数据时,不分配segment,以节省空间解决方法:1.insert一行,再rollback就产生segment了.该方法是在在空表中插入数据,再删除,则产生segment.导 ...