链接:

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的更多相关文章

  1. Codeforces Round #584 C. Paint the Digits

    链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...

  2. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  3. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  4. Codeforces Round #131 (Div. 1) B. Numbers dp

    题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...

  5. Educational Codeforces Round 13 A. Johny Likes Numbers 水题

    A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...

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

  7. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  8. Codeforces Round #584 D. Cow and Snacks

    链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...

  9. Codeforces Round #584 B. Koala and Lights

    链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...

随机推荐

  1. 【学习笔记】RMQ-Range Minimum/Maximum Query (区间最小/最大值)

    RMQ是一类询问区间最小/最大值的问题. 这类问题一般分成两类:静态区间(无修改),动态区间(带修改). 对于动态区间查询最大/最小,我们显然可以用线段树来解决…… 那么对于静态区间查询最大/最小的问 ...

  2. LC 21. Merge Two Sorted Lists

    题目描述 Merge two sorted linked lists and return it as a new list. The new list should be made by splic ...

  3. 使用redis和thread告警并避免重复告警

    spring cloud使用redis 增加监控,微服务的监控体系特别重要,这里增加了告警(使用thread异步告警),同时不能短时间内不能重复告警(使用redis避免重复) 1.增加依赖       ...

  4. PHP正则 正向预查&反向预查

    了解正向预查&反向预查前,我们先要知道正则的2个函数:preg_match_all . preg_replace preg_match_all 可以看文章:点击查看 preg_replace ...

  5. React-intl相关使用介绍

    React-intl用于国际化react组件,提供react组件和api来格式化日期.数字,字符等等.其中一个很重要的功能是实现文本翻译,将你所做的中文版应用所有文字转为英文. 关于配置什么的,请参照 ...

  6. 涛哥:Qt安卓-5.12环境搭建

    简介 Qt for android 环境搭建,以Windows平台 Qt5.12为基准. 因为有不少人问相关问题,所以写篇文章汇总一下. 安装Qt 需要先安装Android版的Qt. 一般在Qt的安装 ...

  7. awesome-javascript

    一系列令人敬畏的浏览器端JavaScript库,资源和闪亮的东西. 令人敬畏的JavaScript 包管理员 装载机 捆扎机 测试框架 QA工具 MVC框架和库 基于节点的CMS框架 模板引擎 文章/ ...

  8. 转------深入理解--Java按值传递和按引用传递

    引言 最近刷牛客网上的题目时碰到不少有关Java按值传递和按引用传递的问题,这种题目就是坑呀,在做错了n次之后,查找了多方资料进行总结既可以让自己在总结中得到提高,又可以让其他人少走弯路.何乐而不为? ...

  9. HTTP协议探究(六):H2帧详解和HTTP优化

    一 复习与目标 1 复习 HTTP1.1存在的问题 HTTP2.0要兼容HTTP1.1 HTTP2.0的重要概念 分帧层 二进制:流 消息 帧 流的状态.优先级和并发 流量控制 服务器推送 首部压缩 ...

  10. JS中的原型对象与构造器

    在Javascript中:原型对象是属于构造函数的,不属于实例:实例只能共享原型对象中的属性和方法(当然也可以有自己的属性和方法,或者覆盖原型中同名的属性和方法):构造器constructor属于原型 ...