洛谷P2320 [HNOI2006]鬼谷子的钱袋
生活随笔
收集整理的這篇文章主要介紹了
洛谷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\n",cnt); 20 for(int i=cnt;i;i--)printf("%d ",a[i]); 21 return 0; 22 }?
轉載于:https://www.cnblogs.com/SilverNebula/p/6040002.html
總結
以上是生活随笔為你收集整理的洛谷P2320 [HNOI2006]鬼谷子的钱袋的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在MSP432 LaunchPad上运行
- 下一篇: 爱立信:5G将加速物联网发展