Luogu 3424 [POI2005]SUM-Fibonacci Sums
Solution
没有任何算法, 只要会$for$ 就能AC。。。
我们观察到, 如果有一个位置 的$F_i$ 的系数$b_i$ 为2, 那么只需要把 $b_{i-2}+1,b_{i+1}+1$即可。
$b_i = 1, b_{i-1}=1$,那么把$b_{i+1}+1$即可,
所以我们一直枚举过去, 直到没有可以更新的位置 , 就结束循环
Code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
using namespace std; const int N = 1e6 + ; int ans[N], n, m, len, a[N], b[N]; int read() {
int X = , p = ; char c = getchar();
for (; c > '' || c < ''; c = getchar())
if (c == '-') p = -;
for (; c >= '' && c <= ''; c = getchar())
X = X * + c - '';
return X * p;
} int main()
{
n = rd;
for (int i = ; i <= n; ++i)
a[i] = rd;
m = rd;
for (int i = ; i <= m; ++i)
b[i] = rd;
for (int i = , up = max(n, m) + ; i <= up; ++i) {
ans[i] += a[i] + b[i];
if (ans[i] && ans[i - ])
ans[i]--, ans[i - ]--, ans[i + ]++;
if (ans[i] > ) {
if (i > )
ans[i - ]++;
ans[i + ]++;
ans[i] -= ;
}
}
for (int flag = ; flag;) {
flag = ;
for (int i = max(n, m) + ; i; --i) {
if (ans[i] && ans[i - ])
flag = , ans[i]--, ans[i- ]--, ans[i + ]++;
if (ans[i] > )
flag = , ans[i - ]++, ans[i + ]++, ans[i] -= ;
if (ans[] && !ans[])
ans[] += ans[], ans[] = ;
}
}
int up = max(n, m) + ;
while (!ans[up]) up--;
printf("%d", up);
for (int i = ; i <= up; ++i)
printf(" %d", ans[i]);
}
Luogu 3424 [POI2005]SUM-Fibonacci Sums的更多相关文章
- [CF126D]Fibonacci Sums/[BJOI2012]最多的方案
[CF126D]Fibonacci Sums/[BJOI2012]最多的方案 题目大意: 将\(n(n\le10^9)\)表示成若干个不同斐波那契数之和的形式,求方案数. 思路: 如果不考虑\(0\) ...
- Codeforces 126D Fibonacci Sums 求n由随意的Sum(fib)的方法数 dp
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq574857122/article/details/34120269 题目链接:点击打开链接 题意 ...
- Codeforces Beta Round #93 (Div. 1 Only) D. Fibonacci Sums
先考虑一个斐波那契数能分成其他斐波那契数的方案,假如f[i]表示第i个斐波那契数,那么只要对他进行拆分,f[i-1]这个数字必定会存在.知道这一点就可以进行递推了.先将数字分成最少项的斐波那契数之和, ...
- Luogu 3421 [POI2005]SKO-Knights - Exgcd
Description 给出一个骑士的 $N$种 中行走的方式 $(a_i, b_i)$, 可以使骑士的坐标$(-a,-b)$或$(+a,+b)$. 我们需要找出 第二个骑士的 两种行走方式 $(c_ ...
- CF(D. Fibonacci Sums)dp计数
题目链接:http://codeforces.com/contest/126/problem/D 题意:一个数能够有多种由互不同样的斐波那契数组成的情况: 解法:dp,easy证明:每一个数通过贪心能 ...
- Luogu 4868 Preprefix sum
类似于树状数组维护区间的方法. 每一次询问要求$\sum_{i = 1}^{n}\sum_{j = 1}^{i}a_j$. 展开一下: $\sum_{i = 1}^{n}\sum_{j = 1}^{i ...
- luogu P3420 [POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...
- [LeetCode] Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- [Swift]LeetCode209. 长度最小的子数组 | Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contigu ...
随机推荐
- Java中for循环中的的try-catch
异常处理 当for循环遇上try-catch @Test public void forThrow(){ final int size = 6; for (int i=0; i<size; i+ ...
- linux下mysql升级
最近漏洞扫描,扫描出了数据库存在中高危漏洞,于是迫切需要进行数据库升级.上网查了各种资料,说法很多,也到自己虚拟机上试了好多方法,终于倒腾出来,做下小总结记录一下. 升级操作: 1.到mysql官网h ...
- javolution学习--介绍
javolution提供一个高性的Java集合(collection )类库和一些实用的工具类.虽然这个类包只提供非常少的几个集合类,但是这些类就能够代替大部分java.util类.javolutio ...
- tomcat启动时引用非JAVA_HOME的指定路径
参考 https://jingyan.baidu.com/article/066074d62d371cc3c21cb0ec.html 先查看bin/catalina.bat 再查看bin/setcla ...
- mro具体解释
你真的理解Python中MRO算法吗? [前言] MRO(Method Resolution Order):方法解析顺序.Python语言包含了很多优秀的特性,其中多重继承就是其中之一,但是多重继承会 ...
- c++中的类(class)-----笔记(类简介)
1, class 和 struct 都可以定义一个类,区别是两者在所支持的 默认信息隐藏方式不同:c++ 中默认为 private 类型,而 struct 中默认为 public 类型. 2,类的私有 ...
- Linux服务器安装配置Nginx服务器
Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务 ...
- Python+Selenium学习--启动及关闭浏览器
场景 页面上弹出的对话框是自动化测试经常会遇到的一个问题:很多情况下对话框是一个iframe,如之前iframe介绍的例子,处理起来稍微有点麻烦:但现在很多前端框架的对话框是div 形式的,这就让我们 ...
- oracle中取得当前日期,前一天,当前月,前一个月
当前日:select TRUNC(SYSDATE) from dual; 前一天: select TRUNC(SYSDATE - 1) from dual; 前一天转换为日期格式: select ...
- oracle 中从某天到某天一天一次执行某个函数
DECLAREv_days INTEGER;v_start VARCHAR2(10);v_end VARCHAR2(10);v_3 INTEGER;v_enddays date;begin v_sta ...