题意

有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. ntopng网络流量实时监控

    ntopng is the next generation version of the original ntop, a network traffic probe that monitors ne ...

  2. Centos7 Firewall

    1.1 firewall启停设置 [root@tomcat ~]# systemctl stop firewalld.service #关闭firewall [root@tomcat ~]# syst ...

  3. Spring _day01_下载、概述、监听器

    Spring:SE/EE开发的一站式框架. ​ .一站式框架:有EE开发的每一层解决方案. ​ . WEB层 :SpringMVC ​ . Service层 :Spring的Bean管理,Spring ...

  4. idea找不到tools.jar下的内容的解决方法

    今天学习javac编译原理时,发现找不到tools.jar. 解决办法:将D:\Program Files\Java\jdk1.8.0_151\lib目录下的tools.jar复制到D:\Progra ...

  5. vue+uwsgi+nginx部署路飞学城

    vue+uwsgi+nginx部署路飞学城   有一天,老男孩的苑日天给我发来了两个神秘代码,听说是和mjj的结晶 超哥将这两个代码,放到了一个网站上,大家可以自行下载 路飞学城django代码 ht ...

  6. Apache代理转发http到https

    site.conf ProxyPass /maps https://maps.googleapis.com/maps LoadModule proxy_module modules/mod_proxy ...

  7. jsp页面传中文到后台乱码怎么办?

    一般从前台传值到后腰如果传的值是中文的话,又不用post传值方式,到后台显示会显示成乱码的形式.所以以下方法亲测有效防止乱码. 前台jsp页面: var taskTitle = $('#taskTit ...

  8. firefox 屏蔽Backspace按键的后退功能

    直接上图

  9. oracle入门之对表数据查询(二)

    oracle表复杂查询 在实际应用中经常需要执行复杂的数据统计,经常需要显示多张表的数据,现在我们给大家介绍较为复杂的select语句 数据分组-max,min,avg,sum,count 如何显示所 ...

  10. js隐藏字符串中间部分

    在进行web前端页面开发中,有时需要从后台获取用户数据来显示在前台页面,但是考虑到用户信息安全的问题,就需要对这些信息进行处理,使其不完全显示出来,例如姓名,两个字的显示姓,名字用*代替,电话前三位和 ...