zoukankan      html  css  js  c++  java
  • 洛谷P2320 [HNOI2006]鬼谷子的钱袋

    https://www.luogu.org/problem/show?pid=2320#sub

    题目描述全是图

    数学思维,分治思想

    假设总数为n

    从n/2+1到n的数都可以用1~n的数+n/2表示出来

    1~n/2的数也可以这样拆分成两份。

    一路拆下去即可。

    例如n=12时:

    {1 2 3 4 5 6}+6={7,8,9,10,11,12}

    {1,2,3}+3={4,5,6}

    {1,2}+3={4,5}

    {1}+2={3}

    所以只需要1 2 3 6

     1 /*by SilverN*/
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 #include<vector>
     8 using namespace std;
     9 const int mxn=100010;
    10 int a[mxn];
    11 int n;
    12 int main(){
    13     cin>>n;
    14     int cnt=0;
    15     while(n){
    16         a[++cnt]=(n+1)/2;
    17         n/=2;
    18     }
    19     printf("%d
    ",cnt);
    20     for(int i=cnt;i;i--)printf("%d ",a[i]);
    21     return 0;
    22 }
  • 相关阅读:
    瀑布流
    轮播图
    封装动画的函数
    回到顶部带动画
    动画setInterval
    模拟滚动条
    放大镜
    刷新
    cookie
    拖拽
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6040002.html
Copyright © 2011-2022 走看看