链接:

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. [转帖]详解oracle数据库唯一主键SYS_GUID()

    详解oracle数据库唯一主键SYS_GUID() https://www.toutiao.com/i6728736163407856139/ 其实 需要注意 这里满不能截取 因为截取了 就不一定唯一 ...

  2. Java与计算机常识

    DB2   IBM公司的数据库 Oracle  Orcle的数据库 Mysql    数据库(免费) 1.  jetty    小型服务器(类似于tomcat) Jetty 是一个开源的servlet ...

  3. 把cgrep mgrep集成到bashrc

    https://android.googlesource.com/platform/build/+/android-4.4.3_r1/envsetup.sh 在~/.bashrc里面增加: #Andr ...

  4. unicode 格式 转汉字

    function decodeUnicode($str){ return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function( ...

  5. I2C读写EEPROM—EEPROM简介

    EEPROM 是一种掉电后数据不丢失的存储器,常用来存储一些配置信息,以便系统重新上电的时候加载之.EEPOM 芯片最常用的通讯方式就是 I 2C 协议,本小节以 EEPROM 的读写实验为大家讲解如 ...

  6. JS 06 bom 框窗_页面_定时任务

    BOM(Broswer Object Model) 凡是 window 的属性和方法,均可以省略“window.” 方法: 框窗 1.警告框 window.alert("msg") ...

  7. java——数据类型和运算符

    强类型语言 Java语言是一门强类型语言.强类型包含两方面的含义:①所有的变量必须先声明.后使用:②指定类型的变量只能接受类型与之匹配的值.强类型语言可以在编译过程中发现源代码的错误,从而保证程序更加 ...

  8. javascript移动端 电子书 翻页效果

    1.后端给一长串的纯文本 2.前端根据屏幕的高度,将文本切割为 n 页 3.使用插件 turn.js 将切割好的每页,加上翻书效果 <!DOCTYPE html> <html lan ...

  9. 如何查看浏览器保存的密码——通过js代码的方式

    打开网站,在密码输入框内鼠标右击,选择“审查元素”(或者按F12),浏览器底部弹出网页的代码,并自动定位到密码框的代码段. 1. 第一种方法 选中元素后,直接在 Console 控制台中输入以下命令( ...

  10. (五)Hibernate的增删改查操作(2)

    接上一章节 HQL的预编译语句 HIbernate中的预编译与Spring的预编译的处理差不多.    1:使用标准的?  2:使用命名参数   2.1:使用名称逐个设置.   2.2:使用Map(k ...