题意

有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;
}

转载于:https://www.cnblogs.com/Friends-A/p/10324318.html

Codeforces 977D: Divide by three, multiply by two(暴力)相关推荐

  1. 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 ...

  2. 【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 boar ...

  3. Divide by three, multiply by two(dfs)

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

  4. Codeforces Round #323 (Div. 1) B. Once Again... 暴力

    B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...

  5. Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解

    A. Help Farmer 题目连接: http://www.codeforces.com/contest/142/problem/A Description Once upon a time in ...

  6. Codeforces Round #359 (Div. 2) C. Robbers' watch 暴力枚举

    题目链接 题意是真的烦,到最后才知道是n个m其实就是限定表的两个时区的位数,所以所当数不够填满时区的时候前边自动补零 思路:首先来说不能有重复的数字的话,小时和分钟的总位数大于7肯定不行. 7的7次方 ...

  7. CodeForces - 387D George and Interesting Graph(二分图最大匹配+暴力)

    题目链接:点击查看 题目大意:给出n个点和m条边组成的有向图,现在我们需要找出一个点作为中心点,然后增加或减少边的条数以达到下面的目标: 除了中心点外,其他的每个点的入度为2且出度为2 中心点和每个点 ...

  8. 【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或)

    题干: Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-i ...

  9. codeforces Gargari and Bishops(很好的暴力)

    1 /* 2 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 3 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 4 ...

最新文章

  1. android+布局分块,android的List View的Item布局问题
  2. ClickHouse之Distributed Query Execution
  3. 第二章 向量(d2)有序向量:二分查找
  4. angular-js资料收集
  5. matlab的讲稿ppt,Matlab初步(讲稿200508)之四
  6. UFLDL教程:Exercise:Softmax Regression
  7. iOS警告-This block declaration is not a prototype
  8. springmvc环境搭建以及常见问题解决
  9. 重磅快讯:CCF发布最新版推荐中文科技期刊目录
  10. 求职时这样回答问题你就输了!来自IT类面试官视角的深度解读
  11. Percona PT-kill重构版(PHP)
  12. Alibaba内部713页Java程序性能优化实战手册首次开放,大受好评
  13. 别再用Excel了!用帆软报表做营收报表效率高十倍!
  14. Teechart 的用法详解:在VC6.0 跟Visual Studio 2005及之后版本的区别
  15. buctoj2021年ACM竞赛班训练(四)全题解
  16. 计算机音乐第二十首,二十首励志歌曲
  17. Java异常处理中throw与throws的用法区别
  18. 关于实习、校招的科普
  19. 仿微信/支付宝的自定义提现密码输入(二)
  20. 苹果电脑/macbookpro 拔出电源充电器但还是显示充电的解决办法

热门文章

  1. 【OpenCV】OpenCV函数精讲之 -- 格式化输出方法
  2. Python | Numpy核心语法和代码整理汇总!
  3. 机器学习面试之偏差方差
  4. maven打包忽略注解_maven打包后pom.properties中的注释问题-阿里云开发者社区
  5. @scheduled注解配置时间_@Scheduled注解
  6. 服务器项目有哪些,怎么部署项目到服务器?服务器的特性有哪些?
  7. 第四届CocoaChina开发者大会官网上线
  8. python常用的绘图库_Python3绘图库Matplotlib(01)
  9. python 自动获取所有设备信息-使用Python脚本来获取Cisco设备信息的示例
  10. jQuery 中$('.classname').on('click',function(){});与$(document).on('click','.classname',function(){});