题目链接:http://codeforces.com/problemset

题目大意:有n个格子,某些格子里可能有一个或多个坦克,但不知道具体位置,每个坦克被轰炸一次就会移动到相邻的格子里(第1个格子只能往第2个格子移动,第n个格子只能往第n-1个格子移动),被轰炸两次就会报废,问最少需要轰炸几次才能保证所有坦克全部报废,请输出轰炸的位置。

解题思路:其实就是先把1~n所有的偶数输出,再输出所有的奇数,再输出所有的偶数。因为通过题意可以知道我们需要让坦克出现在任意格子中都要被轰炸两次,才能保证摧毁所有坦克,也就是我们要轰炸每个格子,在每个被轰炸格子之后还要有两个相邻的格子被轰炸(1,n后只要一个),然后可以发现奇数的格子后需要两个偶数格子,偶数格子后需要一个奇数和一个偶数格子,所以得到规律按偶、奇、偶规律输出即可。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e5+; int main(){
int n;
scanf("%d",&n);
printf("%d\n",n/*+(n-n/));
for(int i=;i<=n;i+=){
printf("%d ",i);
}
for(int i=;i<=n;i+=){
printf("%d ",i);
}
for(int i=;i<=n;i+=){
printf("%d ",i);
}
return ;
}

Codeforces 877C Slava and tanks(思维)的更多相关文章

  1. Codeforces 877 C. Slava and tanks

    http://codeforces.com/problemset/problem/877/C   C. Slava and tanks time limit per test 2 seconds me ...

  2. Slava and tanks 877C

    C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 【Codeforces Round #442 (Div. 2) C】Slava and tanks

    [链接] 我是链接,点我呀:) [题意] 有n个位置,每个位置都可能有不定数量的tank; 你每次可以选择一个位置投掷炸弹. 并且,这个位置上的所有tank都会受到你的攻击. 并且失去一点体力. 然后 ...

  4. CodeForces - 877C

    Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very speci ...

  5. CodeForces - 427A (警察和罪犯 思维题)

    Police Recruits Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  6. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

  7. codeforces 893D Credit Card 贪心 思维

    codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...

  8. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)

    Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...

随机推荐

  1. SAPI 包含sphelper.h编译错误解决方案

    原文连接地址:http://blog.csdn.net/believenow_notfuture/article/details/52191229 [转]SAPI 包含sphelper.h编译错误解决 ...

  2. some of the properties associated with the solution could not be read解决方法

    基于TFS管理的解决方案打开时提示:“some of the properties associated with the solution could not be read”,并不影响项目加载,O ...

  3. Indexing GROUP BY

    SQL databases use two entirely different group by algorithms. The first one, the hash algorithm, agg ...

  4. HDU 5651 逆元

    xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  5. mysql的时间函数整理

      转:这里总结的非常齐全: http://fengbin2005.iteye.com/blog/1999763   Mysql时间函数 对于每个类型拥有的值范围以及并且指定日期何时间值的有效格式的描 ...

  6. syslog大小限制

    位置 /etc/logrotate.d/rsyslog 相关配置信息察看man logrotate size k/M/G /var/log/syslog { rotate daily missingo ...

  7. ES6 利用集合Set解决数组 交集 并集 差集的问题

    根据阮一峰老师的ES6教程自己体会而写的,希望能给一些朋友有帮助到 let a = new Set([1,2,3,4]) let b = new Set([2,3,4,5,]) 并集 let unio ...

  8. MongoDB入门(4)- MongoDB日常操作

    MongoDB客户端 MongoDB有很多客户端 MongoVue Robomongo MongoDB命令行 启动mongo shell 在windows下,双击mongo.exe可以启动mongo ...

  9. 深度解析Java多线程的内存模型

    内部java内存模型 硬件层面的内存模型 Java内存模型和硬件内存模型的联系 共享对象的可见性 资源竞速 Java内存模型很好的说明了JVM是如何在内存里工作的,JVM可以理解为java执行的一个操 ...

  10. async和await关键词用于定义原生的协程

    #python为了将语义变得更加明确,就引入了async和await关键词用于定义原生的协程 # async def downloader(url): # return "xxxx" ...