CF1209A Paint the Numbers
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).
The first line contains an integer n (1≤n≤100), where n is the length of the given sequence.
The second line contains n integers a1,a2,…,an (1≤ai≤100). These numbers can contain duplicates.
Print the minimal number of colors to paint all the given numbers in a valid way.
6
10 2 3 5 4 2
3
4
100 100 100 100
1
8
7 6 5 4 3 2 2 3
4
In the first example, one possible way to paint the elements in 3 colors is:
- paint in the first color the elements: a1=10 and a4=5,
- paint in the second color the element a3=3,
- paint in the third color the elements: a2=2, a5=4 and a6=2.
In the second example, you can use one color to paint all the elements.
In the third example, one possible way to paint the elements in 4 colors is:
- paint in the first color the elements: a4=4 a6=2 and a7=2,
- paint in the second color the elements: a2=6, a5=3 and a8=3,
- paint in the third color the element a3=5,
- paint in the fourth color the element a1=7.
题意解释:输入n个数,对一个数进行涂色时,被涂色的数的倍数也会被涂色。输出最少涂几次可以涂完所有的数
思路和筛法是一样的,从小的往大的筛,直到筛完为止。
#include <bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n;
cin>>n;
for(int i=;i<n;++i)
{
int t;
cin>>t;
a[t]=t;
}
int ans=;
for(int i=;i<=;++i)
{
if(a[i])
{
for(int j=i;j<=;j+=i)
{
a[j]=;
}
ans++;
}
}
cout<<ans;
return ;
}
CF1209A Paint the Numbers的更多相关文章
- Codeforces Round #584 A. Paint the Numbers
链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...
- The Unreasonable Effectiveness of Recurrent Neural Networks (RNN)
http://karpathy.github.io/2015/05/21/rnn-effectiveness/ There’s something magical about Recurrent Ne ...
- 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< ...
- gym101090 I Painting the natural numbers
题目地址:http://codeforces.com/gym/101090 题目: The H&H company currently develops AI (artificial inte ...
- Codeforces 196 C. Paint Tree
分治.选最左上的点分给根.剩下的极角排序后递归 C. Paint Tree time limit per test 2 seconds memory limit per test 256 megaby ...
- [CodeForces - 197E] E - Paint Tree
E - Paint Tree You are given a tree with n vertexes and n points on a plane, no three points lie on ...
- Codeforces Round #124 (Div. 1) C. Paint Tree(极角排序)
C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring
链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...
随机推荐
- 记录一次Git远程仓库版本回退
操作过程: 首先查看远程仓库版本,如下图所见,最近一次提交为2018-03-19 22:16:25 第一步:使用git log命令查看历史提交记录,选择要回退的版本号,commit后面一串字符,这里我 ...
- jQuery Validation Engine(二) checkHello data-errormessage
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- Vue二次精度随笔(1)
1.button.input标签的disabled属性 该标签可以控制按钮是否可用,如果他的值为以上几种的话,则他都不会在标签上渲染出这个属性,一旦这个属性出现的话,就说明他是禁用的 2.移除动态绑定 ...
- Linux CentOS7 VMware 文件和目录权限chmod、更改所有者和所属组chown、umask、隐藏权限lsattr/chattr
一.文件和目录权限chmod u User,即文件或目录的拥有者:g Group,即文件或目录的所属群组:o Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围:a All,即全部 ...
- ActivePerl 安装
下载 https://www.activestate.com/products/activeperl/downloads/ 链接:https://pan.baidu.com/s/1IXPdYFd5bD ...
- 3(计算机网络)ifconfig:最熟悉又陌生的命令行
当面试听到这个问题的时候,面试者常常会觉得走错了房间.我面试的是技术岗位啊,怎么问这么简单的问题? 的确,即便没有专业学过计算机的人,只要倒腾过电脑,重装过系统,大多也会知道这个问题的答案:在 Win ...
- 十五 JSP开发模式&MVC设计模式
JSP开发模式: JavaBean + JSP : 缺点:页面代码过多,不利于维护,JSP页面代码变得臃肿 Servlet + JavaBean + JSP :MVC设计模式 M:model 模 ...
- SciPy 图像处理
章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...
- k8s 各种网络方案【转】
网络模型有了,如何实现呢? 为了保证网络方案的标准化.扩展性和灵活性,Kubernetes 采用了 Container Networking Interface(CNI)规范. CNI 是由 Core ...
- GNS3 模拟icmp重定向
网关实质上是一个网络通向其他网络的IP地址.比如有网络A和网络B,网络A的IP地址范围为“192.168.1.1~192. 168.1.254”,子网掩码为255.255.255.0:网络B的IP地址 ...