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;
}
转载于:https://www.cnblogs.com/Friends-A/p/10324318.html
Codeforces 977D: Divide by three, multiply by two(暴力)相关推荐
- 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 - 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 暴力枚举
题目链接 题意是真的烦,到最后才知道是n个m其实就是限定表的两个时区的位数,所以所当数不够填满时区的时候前边自动补零 思路:首先来说不能有重复的数字的话,小时和分钟的总位数大于7肯定不行. 7的7次方 ...
- CodeForces - 387D George and Interesting Graph(二分图最大匹配+暴力)
题目链接:点击查看 题目大意:给出n个点和m条边组成的有向图,现在我们需要找出一个点作为中心点,然后增加或减少边的条数以达到下面的目标: 除了中心点外,其他的每个点的入度为2且出度为2 中心点和每个点 ...
- 【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 ...
- codeforces Gargari and Bishops(很好的暴力)
1 /* 2 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 3 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 4 ...
最新文章
- android+布局分块,android的List View的Item布局问题
- ClickHouse之Distributed Query Execution
- 第二章 向量(d2)有序向量:二分查找
- angular-js资料收集
- matlab的讲稿ppt,Matlab初步(讲稿200508)之四
- UFLDL教程:Exercise:Softmax Regression
- iOS警告-This block declaration is not a prototype
- springmvc环境搭建以及常见问题解决
- 重磅快讯:CCF发布最新版推荐中文科技期刊目录
- 求职时这样回答问题你就输了!来自IT类面试官视角的深度解读
- Percona PT-kill重构版(PHP)
- Alibaba内部713页Java程序性能优化实战手册首次开放,大受好评
- 别再用Excel了!用帆软报表做营收报表效率高十倍!
- Teechart 的用法详解:在VC6.0 跟Visual Studio 2005及之后版本的区别
- buctoj2021年ACM竞赛班训练(四)全题解
- 计算机音乐第二十首,二十首励志歌曲
- Java异常处理中throw与throws的用法区别
- 关于实习、校招的科普
- 仿微信/支付宝的自定义提现密码输入(二)
- 苹果电脑/macbookpro 拔出电源充电器但还是显示充电的解决办法
热门文章
- 【OpenCV】OpenCV函数精讲之 -- 格式化输出方法
- Python | Numpy核心语法和代码整理汇总!
- 机器学习面试之偏差方差
- maven打包忽略注解_maven打包后pom.properties中的注释问题-阿里云开发者社区
- @scheduled注解配置时间_@Scheduled注解
- 服务器项目有哪些,怎么部署项目到服务器?服务器的特性有哪些?
- 第四届CocoaChina开发者大会官网上线
- python常用的绘图库_Python3绘图库Matplotlib(01)
- python 自动获取所有设备信息-使用Python脚本来获取Cisco设备信息的示例
- jQuery 中$('.classname').on('click',function(){});与$(document).on('click','.classname',function(){});