zoukankan      html  css  js  c++  java
  • Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造

    题意 给出一个1-n的集合   gcd 集合里面的所有数  得到的 一个 数   然后自己选择删去一个数   要使得到的数 构成的数列 的字典序最大

    思路: gcd所有数 那gcd得到的数肯定要小于数组中最小的数  所以 刚开始都是1   所以优先删去1  那就要使gcd所有数经可能快得到 2  

    如何快速到2 呢 那就是把奇数全部删掉  那剩下得数最小就为2 了  此时为 2 4 6 8 10。。。。  此刻就从2开始删   当n==3时 有

    x ,2x,3x  此时 只有 删 x 2 x   3x 才有最大得字典序  x,x,3x  处理一下就好

    (看起来好多人过了,但没看题解就是不会,数学都忘光了,太菜了TAT)

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
      int n;
      cin>>n;
      int cnt=1;
      while(n){
    	  if(n==3){
    		  printf("%d %d %d",cnt,cnt,cnt*3);
    		  break;
    	  }
    	  for(int i=1;i<=n/2+n%2;i++){
               printf("%d ",cnt);
    	  }
    	  cnt*=2;
    	  n/=2;
      }
    	return 0;
    }
    

      

  • 相关阅读:
    [Leetcode]@python 89. Gray Code
    [Leetcode]@python 88. Merge Sorted Array.py
    [Leetcode]@python 87. Scramble String.py
    [Leetcode]@python 86. Partition List.py
    [leetcode]@python 85. Maximal Rectangle
    0523BOM
    0522作业星座
    0522dom
    0520
    0519作业
  • 原文地址:https://www.cnblogs.com/ttttttttrx/p/9906579.html
Copyright © 2011-2022 走看看