【题目链接】: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. NHibernate3剖析:Mapping篇之集合映射基础(2):Bag映射

    系列引入 NHibernate3.0剖析系列分别从Configuration篇.Mapping篇.Query篇.Session策略篇.应用篇等方面全面揭示NHibernate3.0新特性和应用及其各种 ...

  2. DC中检查脚本错误

    dcprocheck    +     要检查的tcl文件

  3. StackExchange.Redis 官方文档

    原文:StackExchange.Redis 官方文档 时隔多年的翻译终于完成了第六个,也是很重要的的官方文档,是介绍有关链接管理,管道流水线和多路复用的 官方地址在这里:官方文档 下面做个汇总: S ...

  4. Redis笔记---set

    1.redis set的介绍 集合中的数据是不重复且没有顺序,集合类型和列表类型的对比. 集合类型:存储的是的是最多2的32次方减一个字符串,数据是没有顺序的,但是数据是唯一的 列表类型:最多存储内容 ...

  5. Java学习很好的笔记

    http://www.cnblogs.com/vamei/archive/2013/03/31/2991531.html

  6. ArcSDE中空间数据的备份与恢复

    在采用文件形式空间数据的时代,空间数据的备份仅仅是操作系统中的文件拷贝.备份和归档的过程:而空间数据的恢复也不过是复制.覆盖的操作:在基于ArcSDE和关系型数据库的空间数据库时代,空间数据的备份更多 ...

  7. Android学习笔记之GridView的使用具体解释

    (1)创建布局代码例如以下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&quo ...

  8. Oracle内存管理(之四)

    [深入解析--eygle]学习笔记 1.3 SGA管理 SGA指系统全局区(System Global Area),是一块用于载入数据.对象并保存执行状态和数据库控制信息的一块内存区域,在数据库实例启 ...

  9. nslookup详解(name server lookup)( 域名查询)

    nslookup详解(name server lookup)( 域名查询) 一.总结 1.爬虫倒是很方便拿到页面数据:a.网页的页面源码我们可以轻松获得  b.比如cnsd博客,文章的正文内容全部放在 ...

  10. matplotlib学习之函数积分图

    # coding:utf-8 import numpy as np from matplotlib import pyplot as plt from matplotlib.patches impor ...