Codeforces 977D: Divide by three, multiply by two(暴力)
题意
有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(暴力)的更多相关文章
- 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, ...
- 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= ...
- codeforces 792C. Divide by Three
题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧. ...
- 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 ...
- 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,遍历这个序列 ...
- 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 ...
- CodeForces - 792C Divide by Three (DP做法)
C. Divide by Three time limit per test: 1 second memory limit per test: 256 megabytes input: standar ...
- Codeforces 1176A Divide it!
题目链接:http://codeforces.com/problemset/problem/1176/A 思路:贪心,对第二个操作进行俩次等于将n变成n/3,第三个操作同理,我们将n不断除以2,再除以 ...
- Codeforces 1270E - Divide Points(构造+奇偶性)
Codeforces 题目传送门 & 洛谷题目传送门 显然,直接暴力枚举是不可能的. 考虑将点按横纵坐标奇偶性分组,记 \(S_{i,j}=\{t|x_t\equiv i\pmod{2},y_ ...
随机推荐
- 生成git,ssh的key
git clone ssh 代码: 报错: Warning: Permanently added 'gitee.com,120.55.226.24' (ECDSA) to the list of kn ...
- ubuntu安装smartGit
1.首先安装jdk:(http://www.cnblogs.com/xiaochou/p/install_mint.html 评论区) 2.下载和安装smartGit: http://www.synt ...
- rebar3自动编译
功能:修改完代码可以自动编译加载到VM中 必须安装的软件: Linux: inotify 链接https://github.com/rvoicilas/inotify-tools/wiki 配置: ...
- add
前台 <input id="Button1" type="button" value="button" onclick="a ...
- 五、Vi和Vim编辑器
1. Vim编辑器: 在Linux下一般使用vi编辑器来编辑文件.vi既可以查看文件也可以编辑文件.三种模式: 命令行.插入.底行模式 切换到命令行模式:按Esc键: 切换到插入模式:按 i .o.a ...
- gateway 配置
server: port: spring: application: name: api-gateway eureka: client: service-url: defaultZone: http: ...
- 201671010142 2017-2 《java第八章学习感悟》
泛型程序设计 学会如何定义简单泛型类,引入了一个变量T,用<>,并放在类名的后面. 如何定义一个带有类型参数的简单方法.当调用一个泛型方法时,在方法名前的尖括号中放入具体的类型.
- fastreport窗口重置(适用于属性、数据等窗口显示不出来)
找到如下路径: C:/Users/账户名/AppData/Local/FastReport/FastReport.config 删除即可. 记得先退出使用FastReport的程序,再删除
- javascript学习笔记_1
1.JSON的遍历 for(var i in json){ alert(json[i]; }2.arguments 可以理解为是一个数组,并且建有json的部分能力 css(obj,attr,val ...
- Docker数据卷持久化
Docker提供三种不同的方式将数据从宿主机挂载到容器中:volumes,bind mounts和tmpfs. volumes:Docker管理宿主机文件系统的一部分(/var/lib/docker/ ...