zoukankan      html  css  js  c++  java
  • 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

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define rd read()
     5 using namespace std;
     6 
     7 const int N = 1e6 + 100; 
     8 
     9 int ans[N], n, m, len, a[N], b[N];
    10 
    11 int read() {
    12     int X = 0, p = 1; char c = getchar();
    13     for (; c > '9' || c < '0'; c = getchar())
    14         if (c == '-') p = -1;
    15     for (; c >= '0' && c <= '9'; c = getchar())
    16         X = X * 10 + c - '0';
    17     return X * p;
    18 }
    19 
    20 int main()
    21 {
    22     n = rd;
    23     for (int i = 1; i <= n; ++i)
    24         a[i] = rd;
    25     m = rd;
    26     for (int i = 1; i <= m; ++i)
    27         b[i] = rd;
    28     for (int i = 1, up = max(n, m) + 10; i <= up; ++i) {
    29         ans[i] += a[i] + b[i];
    30         if (ans[i] && ans[i - 1])
    31             ans[i]--, ans[i - 1]--, ans[i + 1]++;
    32         if (ans[i] > 1) {
    33             if (i > 1)
    34                 ans[i - 2]++;
    35             ans[i + 1]++;
    36             ans[i] -= 2;
    37         }
    38     }
    39     for (int flag = 1; flag;) {
    40         flag = 0;
    41         for (int i = max(n, m) + 10; i; --i) {
    42             if (ans[i] && ans[i - 1])
    43                 flag = 1, ans[i]--, ans[i- 1]--, ans[i + 1]++;
    44             if (ans[i] > 1)
    45                 flag = 1, ans[i - 2]++, ans[i + 1]++, ans[i] -= 2;
    46             if (ans[0] && !ans[1])
    47                 ans[1] += ans[0], ans[0] = 0;
    48         }
    49     }
    50     int up = max(n, m) + 10;
    51     while (!ans[up]) up--;
    52     printf("%d", up);
    53     for (int i = 1; i <= up; ++i)
    54         printf(" %d", ans[i]);
    55 }
    View Code
  • 相关阅读:
    OpenCV2.4.4 图像旋转和缩放
    Python+OpenCV:图片无损旋转90°且无黑边的处理方法
    python 怎样去除图片中的多余物体
    goland 无法解析符号
    go mod init 报错
    比较有用的
    Gorm 学习笔记
    Gorm 更新 0 值
    Java Lambda 表达式,Java Lambda 函数接口
    Java 单例模式,Java Singleton单例模式
  • 原文地址:https://www.cnblogs.com/cychester/p/9707979.html
Copyright © 2011-2022 走看看