题意

有nnn个无序的数,对这些数进行排列,要求ai=3×ai+1a_i=3\times a_{i+1}ai​=3×ai+1​或2×ai=ai+12\times a_i=a_{i+1}2×ai​=ai+1​,保证这些数有解,输出排序后的数

AC代码

/*************************************************************************
> File Name: DD.cpp
> Author: WZY
> QQ: 2697097900
> Created Time: 2018年12月09日 星期日 16时53分40秒
************************************************************************/ #include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
ll a[maxn];
int ne[maxn];
int vis[maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)
continue;
if(a[i]==a[j]*3||a[j]==a[i]*2)
{
ne[i]=j;
vis[j]=1;
}
}
}
for(int i=1;i<=n;i++)
{
if(!vis[i])
{
while(i)
{
cout<<a[i]<<" ";
i=ne[i];
}
cout<<endl;
break;
}
}
return 0;
}

Codeforces 977D: Divide by three, multiply by two(暴力)的更多相关文章

  1. Codeforces 977D Divide by three, multiply by two(拓扑排序)

      Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, ...

  2. Codeforces Round #479 (Div. 3) D. Divide by three, multiply by two

    传送门 D. Divide by three, multiply by two •题意 给你一个数 x,有以下两种操作,x 可以任选其中一种操作得到数 y 1.如果x可以被3整除,y=x/3 2.y= ...

  3. codeforces 792C. Divide by Three

    题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧. ...

  4. Divide by three, multiply by two CodeForces - 977D (思维排序)

    Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, a ...

  5. Codeforces Round #479 (Div. 3) D. Divide by three, multiply by two (DFS)

    题意:给你一个长度为\(n\)的序列\(a\).对它重新排列,使得\(a_{i+1}=a_{i}/3\)或\(a_{i+1}=2*a_{i}\).输出重新排列后的序列. 题解:经典DFS,遍历这个序列 ...

  6. Divide by three, multiply by two(DFS+思维)

    Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, an ...

  7. CodeForces - 792C Divide by Three (DP做法)

    C. Divide by Three time limit per test: 1 second memory limit per test: 256 megabytes input: standar ...

  8. Codeforces 1176A Divide it!

    题目链接:http://codeforces.com/problemset/problem/1176/A 思路:贪心,对第二个操作进行俩次等于将n变成n/3,第三个操作同理,我们将n不断除以2,再除以 ...

  9. Codeforces 1270E - Divide Points(构造+奇偶性)

    Codeforces 题目传送门 & 洛谷题目传送门 显然,直接暴力枚举是不可能的. 考虑将点按横纵坐标奇偶性分组,记 \(S_{i,j}=\{t|x_t\equiv i\pmod{2},y_ ...

随机推荐

  1. centos6.8安装mysql5.5

    在使用阿里云的时候发现centos6.8系统自带的源当中没有mysql5.5,在网易这些源里面也是5.1的版本.这里安装mysql5.5的话需要另外添加一个源. 1.查看是否已经安装了MySQL rp ...

  2. 笨办法41学会说面向对象【pyinstaller安装使用

    urllib库安装 先切换到pip所在目录 D:\Program Files\JetBrains\PyCharm 2017.3.3\untitled>cd /d c:\ c:\>cd c: ...

  3. 学习poisson.c

    static char help[] = "A structured-grid Poisson problem with DMDA+KSP.\n\n"; #include < ...

  4. python 常用网站

    https://www.tutorialgateway.org/python-tutorial/

  5. 机器学习 xgboost 笔记

    一.数据预处理.特征工程 类别变量 labelencoder就够了,使用onehotencoder反而会降低性能.其他处理方式还有均值编码(对于存在大量分类的特征,通过监督学习,生成数值变量).转换处 ...

  6. python笔记24-os模块

    import osprint(os.getcwd())#取当前工作目录#os.chmod('/usr/local',7)#给文件目录加权限,7是最高权限print(os.chdir(r"e: ...

  7. 待实验的socketserver

    # -*- coding:utf-8 -*-# Author: Dennis Huang__Author__ = "Dennis" import socketserver clas ...

  8. 2.Servlet 请求、响应及重定向

    PS:以下仅为个人学习笔记,涩及方面略窄  #######################     Request     ####################### /** *    reque ...

  9. MyBatis通过Mapper动态代理来实现curd操作

    MyBatis官方推荐使用mapper代理方法开发mapper接口,程序员不需要编写mapper实现类,使用mapper代理方法时,输入参数可以使用pojo包装对象或者map对象,保证dao的通用性 ...

  10. SqlServer 游标逐行更新数据,根据上一行的数据来更新当前行

    工作中用到的记录一下,游标的详细定义及说明请百度 --游标格式化数据 DECLARE cursor_jxsmb CURSOR FOR --定义一个游标 SELECT F0 FROM dbo.JXSMB ...