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 ...
随机推荐
- sql server 2012 链接服务器不能链接sql server 2000的解决方案 ,
本数据源来自 https://www.kafan.cn/edu/922556.html 目的为了备忘 把原来的sql server 2005直接装成了2012,然后在建立链接服务器链接一台sql s ...
- Hadoop学习(6)-HBASE的安装和命令行操作和java操作
使用HABSE之前,要先安装一个zookeeper 我以前写的有https://www.cnblogs.com/wpbing/p/11309761.html 先简单介绍一下HBASE HBASE是一个 ...
- redis实战---读书笔记
第一章 初识redis redis 是一个远程内存数据库,性能强劲,具有复制特性以及为解决问题而生的独一无二的数据模型. 1. redis 简介 redis 是一种非关系型数据库(NOSQL) r ...
- Python_OpenCV视频截取并保存
在图像处理之前,我们需要对拿到手的数据进行筛选,对于视频,我们需要从中截取我们需要的一段或几段 整体思路比较简单,通过设定截取视频的起止时间(帧数),可以将该时间段内的图像保存为新的视频 直接上代码: ...
- 文件操作之打开文件与读写文件——C语言
一.fopen 函数原型:FILE *fopen( const char *filename, const char *mode ); 返回值:返回值类型为FILE *,打开文件成功返回指向打开文件的 ...
- UPUPW Apache5.5系列本地开发环境配置
UPUPW Apache5.5系列 1. 在官网下载 Apache5.5系列,选择云端下载. 官网地址: http://www.upupw.net/aphp55/n110.html 2. 下载后,将压 ...
- asp.net mvc抓取微信文章里面所有的图片
/// <summary> /// 下载指定URL下的所有图片 /// </summary> public class WebPageImage { /// <summa ...
- linux时间同步ntpdate
1.安装ntpdate,执行以下命令 yum install ntpdate -y 2.手工同步网络时间,执行以下命令,将从time.nist.gov同步时间 ntpdate 0.asia.pool. ...
- hdu 4857 反向拓扑问题
尤其要注意拓扑的分层问题 不难理解 就是不怎么好想到 拓扑的思路这里就不累述了 #include <iostream> #include <cstdio> #include & ...
- sping+redis实现消息队列的乱码问题
使用spring支持redis实现消息队列,参考官方样例:https://spring.io/guides/gs/messaging-redis/ 实现后在运行过程中发现消费者在接收消息时会出现乱码的 ...