浪在ACM新春大作战
题目链接:
# | Name | 补题状态 |
---|---|---|
A |
已补
|
|
B |
已补
|
|
C |
已补
|
|
D | ||
E |
A:Memory and Crow
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
5
6 -4 8 -2 3
2 4 6 1 3
5
3 -2 -1 5 6
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.
题意描述:
大致意思就是,输入n输入n个整数,求挨着的两个整数和,然后最后一个整数单独输出。//因博主没过四级:题意是看样例看出来的,具体不确定
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
#define ll long long
int main() {
ll n, a[100010];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i]; if (i > 0)cout << a[i] + a[i - 1] << " ";
}
cout << a[n - 1] << "\n";
return 0;
}
B. Memory and Trident
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
RRU
-1
UDUR
1
RUUR
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.
题目大意:
输入一串字符串,包含:U(上),D(下),L(左),R(右),你在原点,按照字符串走,然后你可以随意修改里边任意一个字符改成你想要的,求最少修改多少次可以走回到原点,会不到的话输出-1。
1 》如果字符串长度是奇数的话肯定走不回原点。
2 》一个D就能抵消一个U,一个L就能抵消一个R,求抵消后的 sum= abs(sl - sr) + abs(su - sd),向右走一个,只需要修改第二个向左走就行,上下同理,所以结果为sum/2
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main() {
string a;
int sl = 0, sr = 0, su = 0, sd = 0, sum = 0;
//sl:'L'个数 sr:'R'个数 su:'U'个数 sd:'D'个数
cin >> a;
if (a.size() & 1)cout << "-1\n";
else {
for (int i = 0; i < a.size(); i++) {
if (a[i] == 'L')sl++;
else if (a[i] == 'R')sr++;
else if (a[i] == 'U')su++;
else sd++;
}
sum = abs(sl - sr) + abs(su - sd);
cout << sum / 2 << "\n";
}
return 0;
}
C. Memory and De-Evolution
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
6 3
4
8 5
3
22 4
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 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的等边三角形,一次只能改一条边,并且改完后仍然满足三条边构成三角形。(x>=y)
长变短,和短变长修改次数一样,所以逆向模拟,每次最多能把 最短的一条边 改成 两条长边-1,三条边都大于x,即满足条件。逆向推的好处是能够满足三角形的约束下改变最大。
例:3=>6 (3.3.5),(3.5.7),(5.7.11),(7.11.17)
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
#define ll long long
int main() {
int x, y,cnt=0;//cnt:修改次数
cin >> x >> y;
int a[3], b;
a[0]=a[1]=a[2]= y;
b= x;
while (a[0] < x || a[1] < x || a[2] < x) {//有一条边小于x,就不满足条件
sort(a, a + 3);
a[0] = a[1] + a[2] - 1;
cnt++;
}
cout << cnt << "\n";
return 0;
}
浪在ACM新春大作战的更多相关文章
- hiho #1114 : 小Hi小Ho的惊天大作战:扫雷·一
#1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室.监视器与充满危机的广场 “我们还是循序渐进,先来考虑这 ...
- OneAPM x 腾讯 | OneAPM 技术公开课·深圳 报名:前端性能大作战!
「 OneAPM 技术公开课」由应用性能管理第一品牌 OneAPM 发起,内容面向 IT 开发和运维人员.云集技术牛人.知名架构师.实践专家共同探讨技术热点. 11月28日,OneAPM 技术公开课第 ...
- 刺猬大作战(游戏引擎用Free Pascal写成,GUI用C++写成,使用SDL和Qt4)
游戏特性[编辑] 游戏引擎用Free Pascal写成,GUI用C++写成,使用SDL和Qt4[2]. 0.9.12开始支持实时动态缩放游戏画面. 个性化[编辑] 刺猬大作战有着高度定制性 游戏模式: ...
- cocos2d-x 3.2 它 三消游戏——万圣节大作战
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- 【百度地图API】情人节求爱大作战——添加标注功能
原文:[百度地图API]情人节求爱大作战--添加标注功能 任务描述: 2月2日是除夕,2月14立马来!即将到来的情人节,你想送TA一份什么礼物呢? 不如,在你们居住的地方,画个大大的桃心,表达你对TA ...
- [知了堂学习笔记]_用JS制作《飞机大作战》游戏_第2讲(四大界面之间的跳转与玩家飞机的移动)
一.通过点击按钮事件,实现四大界面之间的跳转: (一)跳转的思路: 1.打开软件,只显示登录界面(隐藏游戏界面.暂停界面.玩家死亡界面) 2.点击微信登录(QQ登录)跳转到游戏界面,隐藏登录界面 3. ...
- FC经典游戏还原之:松鼠大作战2
版权声明:本文原创发布于博客园"优梦创客"的博客空间(id:raymondking123) 原帖地址:http://www.cnblogs.com/raymondking123/p ...
- Android破解学习之路(十四)——【Unity3D】王牌大作战破解
一.前言 今天带来的是王牌大作战的破解教程,游戏下载的话,我是直接去TapTap官网下载的 支付宝内购破解用老套了,今天学点破解的新花样吧!! 二.支付宝内购破解 支付宝的内购破解已经很熟悉了, 直接 ...
- 2018.12.21 浪在ACM 集训队第十次测试赛
浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...
随机推荐
- WebGL学习笔记(1)
基本的WebGL图形操作(详细参考教程:https://www.yiibai.com/webgl,需要1周左右熟悉webgl的对象方法以及着色器代码):绘制三角形 drawElements gl.TR ...
- chromium之histogram.h
histogram不知道是干啥的 // Histogram is an object that aggregates statistics, and can summarize them in // ...
- mac Axure RP 8 授权码 以及汉化
Koshy wTADPqxn3KChzJxLmUr5jTTitCgsfRkftQQ1yIG9HmK83MYSm7GPxLREGn+Ii6xY 汉化包 汉化包链接 密码: upri 汉化步骤 以Win7 ...
- 关于Vue的组件的通用性问题
在项目中,经常会有需求让我们把很多通用性的功能写成一个模板,然后根据不同的应用场景传入不同的参数来完成某种功能 但是在很多时候,其实并不是一个模板就能完成所有的功能的 这就需要分类写组件了,但是需求方 ...
- openstack之kvm常用操作
KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理. 1. 查看KVM虚拟机配置文件及运行状态 KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostart目录 ...
- Arduino UNO仿真开发环境设置和仿真运行
一. Proteus仿真平台简介 Proteus软件是英国Labcenter electronics公司出版的EDA工具软件(该软件中国总代理为广州风标电子技术有限公司).它不仅具有其它EDA工具软件 ...
- 闰年相关的问题v3.0——计算有多少闰年
# include<stdio.h>int main(){ int a,b,i; int sum = 0; printf("Input your birth year:" ...
- python是一门解释性语言吗?
其实这只能算说对了一半,准确来说是编译跟解释性语言.python跟java.C# 一样都是会预编译一部分代码(简称做了优化) 都知道java编译要先在cmd里敲 javac hello.world 是 ...
- 北京Uber优步司机奖励政策(12月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- CakePHP 查询总结
返回 $this->Post->buildQuery(); 返回: Array ( [conditions] => [fields] => [joins] => Arra ...