【Codeforces 776B】Sherlock and his girlfriend
【题目链接】
【算法】
将所有质数染成1,合数染成2即可
【代码】
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000 int i,N,x;
bool b1,b2;
int b[MAXN+]; template <typename T> inline void read(T &x) {
int f=; x=;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = x * + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline bool prime(int x) {
int i;
if (x == ) return false;
for (i = ; i <= sqrt(x); i++) {
if (!(x % i))
return false;
}
return true;
} int main() { read(N);
for (i = ; i <= N + ; i++) {
b[i] = prime(i);
if (b[i]) b1 = true;
else b2 = true;
}
if (b1 && b2) puts("");
else puts(""); for (i = ; i <= N + ; i++) {
if ((b1 && !b2) || (!b1 && b2)) write();
else write(b[i]?:);
if (i <= N) putchar(' ');
}
puts(""); return ; }
【Codeforces 776B】Sherlock and his girlfriend的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- Effective Java P2 Creating and Destroying Objects
This chapter concerns creating and destorying objects : when and how to create them, when and how to ...
- 转:CEF嵌入到单文档mfc
1.下载: http://www.magpcss.net/cef_downloads/下载cef binary 1.1364.1123 windows.zip(可能要FQ,百度goagent教程,最好 ...
- Spring MVC集成Spring Data Reids和Spring Session实现Session共享
说明:Spring MVC中集成Spring Data Redis和Spring Session时版本是一个坑点,比如最新版本的Spring Data Redis已经不包含Jedis了,需要自行引入. ...
- Spring中Bean的定义继承
以下内容引用自http://wiki.jikexueyuan.com/project/spring/bean-definition-inheritance.html: Bean定义继承 bean定义可 ...
- SpringMVC拦截器详解[附带源码分析](转)
本文转自http://www.cnblogs.com/fangjian0423/p/springMVC-interceptor.html 感谢作者 目录 前言 重要接口及类介绍 源码分析 拦截器的配置 ...
- jquery 获取浏览器窗口的可视区域高度 宽度 滚动条高
原文:http://www.open-open.com/code/view/1421827925437 alert($(window).height()); //可视区域高度 alert($(docu ...
- NSTimer与NSRunLoop的关系分析
NSTimer与NSRunLoop的关系分析 发表于 2013 年 6 月 27 日 由 bluev | 6 次浏览 最近关于NSTimer和NSRunLoop的关系,做了一个小试验.代码地址:htt ...
- How to fill the background with image in landscape in IOS? 如何使image水平铺满屏幕
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:self.view.frame]; [backgroundIm ...
- stl之multiset容器的应用
与set集合容器一样,multiset多重集合容器也使用红黑树组织元素数据,仅仅是multiset容器同意将反复的元素健值插入.而set容器则不同意. set容器所使用的C++标准头文件set.事实上 ...
- C#压缩或解压(rar和zip文件)
/// <summary> /// 解压RAR和ZIP文件(需存在Winrar.exe(只要自己电脑上可以解压或压缩文件就存在Winrar.exe)) /// </summary&g ...