Codeforces Round #584 A. Paint the Numbers
链接:
https://codeforces.com/contest/1209/problem/A
题意:
You are given a sequence of integers a1,a2,…,an. You need to paint elements in colors, so that:
If we consider any color, all elements of this color must be divisible by the minimal element of this color.
The number of used colors must be minimized.
For example, it's fine to paint elements [40,10,60] in a single color, because they are all divisible by 10. You can use any color an arbitrary amount of times (in particular, it is allowed to use a color only once). The elements painted in one color do not need to be consecutive.
For example, if a=[6,2,3,4,12] then two colors are required: let's paint 6, 3 and 12 in the first color (6, 3 and 12 are divisible by 3) and paint 2 and 4 in the second color (2 and 4 are divisible by 2). For example, if a=[10,7,15] then 3 colors are required (we can simply paint each element in an unique color).
思路:
暴力枚举.
代码:
#include <bits/stdc++.h>
using namespace std;
int a[110];
int vis[110];
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
sort(a+1, a+1+n);
int col = 0;
for (int i = 1;i <= n;i++)
{
if (vis[i] == 0)
{
col++;
for (int j = i;j <= n;j++)
{
if (a[j]%a[i] == 0)
vis[j] = 1;
}
}
}
cout << col << endl;
return 0;
}
Codeforces Round #584 A. Paint the Numbers的更多相关文章
- Codeforces Round #584 C. Paint the Digits
链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...
- Codeforces Round #584
传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Educational Codeforces Round 13 A. Johny Likes Numbers 水题
A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...
- Educational Codeforces Round 23 C. Really Big Numbers 暴力
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #584 E2. Rotate Columns (hard version)
链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...
- Codeforces Round #584 D. Cow and Snacks
链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...
- Codeforces Round #584 B. Koala and Lights
链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...
随机推荐
- Navicat通过跳板机连接MySQL(2层跳转)
情景描述,公司开发数据库部署在内网,而且这个开发数据库有连接需要有IP验证,就是只能在内网的某个IP才能连接,所以每次连接都会先连接外网能访问的跳板机,在从跳板机上ssh到内网上的A机器,在从A机 ...
- COleVariant类
COleVariant本质上是一个枚举,用同一种类型来表达不同的子类型.如同boost中的variant. COLeVariant类是对VARIANT结构的封装. VARIANT结构包含两部分.其一是 ...
- centos7无网络环境下创建基于scratch镜像的Linux镜像,并带有Java运行环境
一.准备 将下载好的jdk以及scratch镜像放在同一文件夹下:这里放在linux:2.0 二.导入scratch镜像 #docker load -i scratch.tar 三.创建dockerf ...
- JDBC(Java项目使用Oracle数据库)
Java项目中使用Oracle数据库(Eclipse) 前言 这学期选了Oracle数据库这门课,于是自己下载了Oracle11gR2版本的数据库.在这之前我一直用的是MySQL.虽然两者教程差不多, ...
- java中如何测试一段代码的运行时间
一.以毫秒为单位.long startTime = System.currentTimeMillis(); //获取开始时间 doSomething(); //测试的代码段 long endTime ...
- win7+cuda+anaconda python+tensorflow-gpu+keras安装成功版本匹配汇总
win7+cuda+anaconda python+tensorflow-gpu+keras安装成功版本匹配汇总 2019-09-20 15:06:03 wyx100 阅读数 38更多 分类专栏: M ...
- ORA-07445: exception encountered: core dump [opiaba()+639] [SIGSEGV] [ADDR:0x0] [PC:0x1858C3F] [SI_KERNEL(general_protection)] []
开发反馈应用无法连接数据库,发现数据库实例崩溃,且数据库为11.2.0.4 单实例. 数据库告警日志发现,数据库崩溃之前出现ORA- ORA-: exception encountered: core ...
- MyBatis 源码篇-MyBatis-Spring 剖析
本章通过分析 mybatis-spring-x.x.x.jar Jar 包中的源码,了解 MyBatis 是如何与 Spring 进行集成的. Spring 配置文件 MyBatis 与 Spring ...
- jquery 获取滚动条高度
获取浏览器显示区域的高度 : $(window).height(); 获取浏览器显示区域的宽度 :$(window).width(); 获取页面的文档高度 :$(document).height(); ...
- cmd查找端口占用情况
查找端口占用情况:netstat -ano|findstr 4848 查看使用指定端口的应用程序:tasklist|findstr xxxx,xxxx指的是pid 结束指定进程:taskkill /p ...