题意

有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. ie11~ie9兼容的布局写法。bootsteap的12栅格,栅格化就可以实现。

    全局 CSS 样式 设置全局 CSS 样式:基本的 HTML 元素均可以通过 class 设置样式并得到增强效果:还有先进的栅格系统. 概览 深入了解 Bootstrap 底层结构的关键部分,包括我们 ...

  2. 面向对象DAO模式

    DAO模式编写数据访问层代码步骤? 1.  接口 增.删.改.查的方法 方法的返回类型为泛型集合 Int rows=select语句的条数 If(rows>0) 方法的返回类型为泛型集合 If( ...

  3. phthon--------异常处理

    一 什么是异常 异常就是程序运行时发生错误的信号(在程序出现错误时,则会产生一个异常,若程序没有处理它,则会抛出该异常,程序的运行也随之终止),在python中,错误触发的异常如下 而错误分成两种 # ...

  4. What to do when you have small dataset - 拥有小型数据集时该怎么办

    I'm trying to train a classifier with neural network, but I've got too small datasets. Each class ha ...

  5. XE 使用记录

    project的选项是分编译版本的,debug,release,上层还有一个base 通用的设置值,最好放base里,比如Search path里 自己添加的路径,免得2个环境分别添加.

  6. git push后出错

    参考链接: 1,https://blog.csdn.net/shiren1118/article/details/7761203 2,http://www.cnblogs.com/xwdreamer/ ...

  7. 代码规范mark一下

    转自于:https://github.com/zh-google-styleguide/zh-google-styleguide/blob/master/google-python-styleguid ...

  8. 实训任务05 MapReduce获取成绩表的最高分记录

    实训任务05  MapReduce获取成绩表的最高分记录 实训1:统计用户纺问次数 任务描述: 统计用户在2016年度每个自然日的总访问次数.原始数据文件中提供了用户名称与访问日期.这个任务就是要获取 ...

  9. JAVA中接口与抛出异常的相关知识

    1.接口概念:接口可以理解为一种特殊的类,由全局常量和公共的抽象方法所组成. 类是一种具体实现体,而接口定义了某一批类所需要遵守的规范,接口不关心这些类的内部数据,也不关心这些类里方法的实现细节,它只 ...

  10. uboot中往s5p6818的emmc刷写内容

    建立分区: fdisk :: : fdisk Partition Map -- Partition Type: DOS Part Start Sector Num Sectors UUID Type ...