codeforces 1059 C. Sequence Transformation

题目:http://codeforces.com/contest/1059/problem/C

题意:给出n,n个数分别为1—n
1.求出所有数的最大公因数
2.删除一个数
直到输出n个公因数结束。使得答案的字典序最大

思路:明显可以看出需要先删除奇数,如果先删除偶数得到的1的数量一定比删除奇数多。
此时需要手动模拟几个
1
1 2
1 1 3
1 1 2 4
1 1 1 2 4
1 1 1 2 2 6
1 1 1 1 2 2 6
1 1 1 1 2 2 4 8

发现:当删除完所有奇数时,可以得出最大公因数为t=2。此时如果剩余数目大于3,继续提出公因数2,t*=2,一直到n<=3为止,从前面3个例子看出有所不同,得出最后3个数的答案
n=1 ans:t
n=2 ans:t t2
n=3 ans:t t t
3

#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> LP;
const ll inf = 1e17 + 10;
const int N = 1e6 + 10;
const ll mod = 1e9+7;
const int base=131;
const double pi=acos(-1);
map<string, int>ml;


map<ll,ll> mp;
map<int,int> vi;
priority_queue<P> q;
priority_queue<P> tq;



ll b[N], vis[N], dep[N],num[N], a[N],t, n, m,  k,x,y;
int ex, ey, cnt, ans, sum, flag;
ll l[N],r[N],po[N];
//vector<int> v[N];
vector<int> fac[N];
string s;
map<int,int> dp[N];

char v[1005][1005];



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	t=1;
	while(n>3)
	{
		for(int i=1;i<=n-(n>>1);i++) cout<<t<<" ";
		n>>=1;
		t<<=1;
	}
	if(n==1) cout<<t<<endl;
	else if(n==2) show2(t,t*2)
	else show3(t,t,t*3);


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值