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;
}

  

原文地址:https://www.cnblogs.com/ttttttttrx/p/9906579.html

时间: 2024-08-30 10:22:25

Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造的相关文章

Codeforces Round #514 (Div. 2) C. Sequence Transformation(递归)

C. Sequence Transformation 题目链接:https://codeforces.com/contest/1059/problem/C 题意: 现在有1~n共n个数,然后执行下面操作: 1.求出余下数的gcd,然后将gcd加入答案队列: 2.从中任意删除一个数,如果余下数的个数大于0,回到步骤1. 问答案队列字典序最大是什么. 题解: 这明明是递归在做极其方便,我偏偏用for循环来搞,加各种判断... 首先对于1,2,3...n来说,我们每次删去一个数时,肯定首先删去的是奇数

贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

题目传送门 1 /* 2 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 3 */ 4 /************************************************ 5 Author :Running_Time 6 Created Time :2015-8-3 9:14:02 7 File Name :B.cpp 8 *************************************************/ 9 10 #include

Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列其中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造可以根据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i

Codeforces Round #514 (Div. 2)

1059A - Cashier #include<cstdio> const int N=1e5+5; int l[N],t[N]; int main(){ int n,L,a,ans=0; scanf("%d%d%d",&n,&L,&a); for(int i=1;i<=n;++i) scanf("%d%d",&t[i],&l[i]); if(l[1]) ans+=t[1]/a; t[n+1]=L; for

Codeforces Round #514 (Div. 2) D. Nature Reserve

http://codeforces.com/contest/1059/problem/D 最大值: 最左下方和最右下方分别有一个点 r^2 - (r-1)^2 = (10^7)^2 maxr<0.5*10^14 Way1: 二分. difference: 如果使用 5*10^13 -> 10^-6,2^ 60~70区间,pow,sqrt运算,实测超时. 实际上是,使用. time of a case:-> Code: 1 #include <bits/stdc++.h> 2

Codeforces Round #153 (Div. 1) C Number Transformation bfs

//到达2 , 3 ... k的最小公倍数为lcm //当x到达lcm的倍数时,x只能减一 //又从a到b一定会过lcm的倍数 //我们将a,b以lcm分割 //那么完整的lcm段的最小数是相同的,所以我们只需要计算一个lcm段的最小值乘以完整lcm段的个数 //以及首尾的不全的lcm段的和即为答案 #include<cstdio> #include<cstring> #include<iostream> #include<queue> using name

CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation

题目描述 We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name ss can transform to another superhero with name tt if ss can be made equal to tt by chan

Codeforces Round #629 (Div. 3) D. Carousel(思维/贪心?)

The round carousel consists of nn figures of animals. Figures are numbered from 11 to nn in order of the carousel moving. Thus, after the nn -th figure the figure with the number 11 follows. Each figure has its own type — the type of the animal corre

Codeforces Round #423 Div. 2 C-String Reconstruction(思维)

题目大意:告诉你n个字符串以及这些字符串在字符串s中出现的位置(x1,x2.....xn),要求在满足上述条件的情况下,求出字典序最小的字符串s. 解题思路:主要问题是,如果直接模拟是会超时的,比如vvvvvvvvvv 3 1 2 3这样就有大量重复(因为题目说了这些字符串位置不会相互矛盾,所以已经有了字符的地方可以不用管了),每次都重复了len-1的长度,如果这段字符串长度为1e6那很容易就超时了.所以这里添加一个pre记录上一次字符串的末尾位置(因为题目说了给出的位置时递增的),每次比较一下