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 ...
随机推荐
- influxDB---Data Exploration
the group clause group by 返回的分组结果是根据用户指定的tag ,time interval. 1.group by tags 2.group by time interva ...
- 将电脑中编写的app网页放到手机上访问
http://jingyan.baidu.com/article/3065b3b6e5becdbecff8a4d5.html 1.在控制面板-管理工具找不到IIS,则先在程序-打开或关闭window功 ...
- 六百字读懂 Git(转)
add by zhj:还是原文 六百字读懂 Git 看着更舒服一些,显示更好 原文:六百字读懂 Git 英文原文:Git in 600 words 译注:来自 Hacker School 的 Mary ...
- Python代码实现删除一个list里面的重复元素
lst=[11,22,33,44,22,11,22,44] print(list(set(lst))) # 打印结果:[33, 11, 44, 22] d = {} for index,item in ...
- python面试题(八)
1 Python中如何使用线程池和进程池? 需要注意一下 不能无限的开进程,不能无限的开线程 最常用的就是开进程池,开线程池.其中回调函数非常重要 回调函数其实可以作为一种编程思想,谁好了谁就去掉 只 ...
- 一、2440裸机点亮led
从代码開始(先写一个像普通单片机一样的代码): /********led.c************************/ #define GPFCON (*(volatile unsigned ...
- locust基本使用
# coding:utf-8 from locust import HttpLocust,TaskSet,task class BlogDemo(TaskSet): '''用户行为:打开我的博客首页d ...
- Mybatis参数总结(转载)
转载自: MyBatis传入多个参数的问题 mybatis传递参数总结 一.单个参数 1.基本数据类型 (1)直接使用 List<ChargeRuleDO> tests(long id); ...
- mysql-5.7.16-linux-glibc2.5-x86_64精简后的主从配置
1.创建复制账号,并授予复制权限CREATE USER 'fansik'@'10.%' IDENTIFIED BY 'fansik';GRANT REPLICATION SLAVE ON *.* TO ...
- C#编写图书列表winform
Book.cs文件 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...