20162017-ct-s03e02-codeforces-trainings-season-3-episode-2-en-I Painting the natural numbers
来源:互联网 发布:淘宝一元拍是真的吗 编辑:程序博客网 时间:2024/04/30 09:00
题意:用10种颜色染1-n这n个数字,染色需满足:a,b(a可以等于b)同一种颜色,则a+b必须是另一种颜色(n<=25000)
题解:若当前已用k种颜色染好n个数字,则可以扩展成3n+1个数字:
{n个数字,k种颜色}{n+1个,第(k+1)种颜色}{n个数字,k种颜色}
用这种方法10种颜色可以达到29000
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;const int N=30000;int n;int a[N];int main(){ int Now=1;a[1]=0; for (int K=1;K<10;K++){ for (int i=Now+1;i<=Now+Now+1;i++)a[i]=K; for (int i=2*Now+2;i<=Now*3+1;i++)a[i]=a[i-Now*2-1]; Now=3*Now+1; } cin>>n; for (int i=1;i<=n;i++)printf("%d",a[i]); return 0;}
0 0
- 20162017-ct-s03e02-codeforces-trainings-season-3-episode-2-en-I Painting the natural numbers
- 20162017-ct-s03e02-codeforces-trainings-season-3-episode-2-en-A HHPaint
- 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6 The Baguette Master
- 2016-2017 CT S03E01: Codeforces Trainings Season 3 Episode 1 J Wrong Answer 最大独立集
- 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 J
- 2016-2017 CT S03E08: Codeforces Trainings Season 3 Episode 8 K1 gcd
- CodeForces Gym Trainings Season 3 Episode 5 A题
- gym I. Painting the natural numbers
- CF Trainings Season 1 Episode 6 I (dp)
- 2014-2015 Codeforces Trainings Season 2 Episode 7 G Gophers --线段树
- Painting The Wall CodeForces
- Friend, Season 1, episode 1
- Codeforces 12E Start of the season
- Lost - Season 03 Episode 13 - The Man from Tallahassee - March, 21
- Codeforces 398B Painting The Wall(dp)
- 《Friends Season 04, Episode 01》---笔记
- 《Friends Season 04, Episode 02》---笔记
- CodeForces 398B Painting The Wall 概率DP
- C++箴言:理解typename的两个含义
- javaweb三大组件之Servlet
- hdu 2222 Keywords Search (AC自动机)
- 集合转数组
- Java内存泄露的原因
- 20162017-ct-s03e02-codeforces-trainings-season-3-episode-2-en-I Painting the natural numbers
- 编写Js SDK获取网页信息(包含10多项内容)
- Elasticsearch2.x Doc values
- 优酷上不错的最优化教学视频地址
- Cocos2dx 菜单项控件-Menu
- bzoj3697(点分治)
- 深度学习的学习流程之基础
- shell程序设计的流程控制及其命令分组
- HashMap的工作原理