【题目链接】:http://codeforces.com/contest/534/problem/A

【题意】



给你n个人,要求任意两个编号相邻的人不能相邻;

让你安排座位方案,使得最多人的可以入座

【题解】



对于前4个特殊一点判断一下就好;

n=4的时候也是4->即2 4 1 3

到5之后就可以用前面n/2个位置是奇数,后面n/2个位置是偶数了

比如

1 3 5 7 2 4 6

就对应了n=7的情况



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 5000 + 100; int n, num, a[N]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
while (cin >> n)
{
num = 0;
if (n == 4)
{
puts("4");
printf("2 4 1 3\n");
}
else
{
for (int i = 1; i <= n; i += 2)
a[++num] = i;
for (int i = 2; i <= n; i += 2)
if (abs(a[num] - i) > 1)
{
a[++num] = i;
}
else
break;
printf("%d\n", num);
for (int i = 1; i <= num; i++)
{
printf("%d", a[i]);
if (i == num)
puts("");
else
putchar(' ');
}
}
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 534A】Exam的更多相关文章

  1. 【Codeforces 1185C2】Exam in BerSU (hard version)

    [链接] 我是链接,点我呀:) [题意] 要让前i个数字的和小于等于M. 问你最少要删掉前i-1个数字中的多少个数字,每个询问都是独立的. [题解] ti的范围很小. 所以N*MAX(TI)暴力枚举就 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【22.73%】【codeforces 606D】Lazy Student

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. cdn缓存

    1:缓存是什么? 首先.看看没有站点没有接入CDN时.用户浏览器与server是怎样交互的: 假设中间加上一层CDN,那么用户浏览器与server的交互例如以下: client浏览器先检查是否有本地缓 ...

  2. Android RxJava基本流程和lift源码分析

    基本结构 我们先来看一段最基本的代码,分析这段代码在RxJava中是如何实现的. Observable.OnSubscribe<String> onSubscriber1 = new Ob ...

  3. 最短路算法详解(Dijkstra/SPFA/Floyd)

    新的整理版本版的地址见我新博客 http://www.hrwhisper.me/?p=1952 一.Dijkstra Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkst ...

  4. 读文件头数据判断 PE 文件格式和类型

    namespace X.Reflection { using System; using System.IO; public static partial class ReflectionX { pu ...

  5. FindBug:Call to static DateFormat

    今天在重构代码的过程中碰到了一个问题.使用SimpleDateFormat的问题. 本人今天写了一个类,主要是提供很多静态的方法由其他接口调用,过程中多个方法使用到了日期的格式化,所以我讲Simple ...

  6. codeforces Round 246 D. Prefixes and Suffixes (后缀数组 || KMP)

    题目大意: 求一个子串,子串既是前缀又是后缀. 然后再求出它在整个串中出现的次数. 思路分析: 能够非常easy想到怎样推断一个串既是前缀又是后缀. 仅仅须要它与 sa[0] 的lcp 等于 整个串的 ...

  7. 学习redis--安装(二)

    安装前准备,我是在虚拟机中安装centos,然后安装redis. 安装 1.安装VMware,并安转centos系统 2.将redis的压缩包,上传到linux系统中(将下载到pc中的文件,拖到cen ...

  8. 一起学JAVA之《spring boot》03 - 开始spring boot基本配置及项目结构(转)

    <div class="markdown_views"> <h3 id="一导航"><a name="t0"& ...

  9. Java与模式:装饰(Decorator)模式

    装饰模式使用被装饰类的一个子类的实例.把client的调用委派到被装饰类,装饰模式的关键在于这样的扩展是全然透明的.   装饰模式在Java种使用也非常广泛,比方我们在又一次定义button.对话框等 ...

  10. javascript 调用C++函数

    分3步: 一>实现IDispatch 接口 #ifndef _IDISPIMP_H_ #define _IDISPIMP_H_ // idispimp.h class CImpIDispatch ...