题目链接: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. UVA.10066 The Twin Towers (DP LCS)

    UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化 ...

  2. redux的bindActionCreators

    bindActionCreators是redux的一个API,作用是将单个或多个ActionCreator转化为dispatch(action)的函数集合形式. 开发者不用再手动dispatch(ac ...

  3. 平衡二叉树 (牛客国庆day2)解锁二叉树打表姿势&&找规律套路

    链接:https://www.nowcoder.com/acm/contest/202/F来源:牛客网 平衡二叉树,顾名思义就是一棵“平衡”的二叉树.在这道题中,“平衡”的定义为,对于树中任意一个节点 ...

  4. G. Trace ACM-ICPC 2018 徐州赛区网络预赛 线段树写法

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy  ...

  5. HDU 4303 树形DP

    Hourai Jeweled Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 163840/163840 K (Java/Others) ...

  6. Mybatis(3) 映射文件-增删改查

    映射文件: 映射文件是根据数据库模型生成的编写sql脚本xml文件, mapper标签中namespace属性值为对应模型实体类的全类名. <?xml version="1.0&quo ...

  7. JS判断内容为空方法总结

    HTML代码: 用户名:<input type="text" id="username"> <p style="color:red& ...

  8. flask-login源码梳理

  9. cocos2dx中启用lua脚本

    AppDelegate 的 applicationDidFinishLaunching 方法中加载Lua引擎 bool AppDelegate::applicationDidFinishLaunchi ...

  10. dot.js使用心得

    一.dot.js介绍 最近用到的数据模板引擎有很多,今天讲的doT.js也是其中一种. doT.js的特点是体积小,速度快,并且不依赖其他插件. 官网下载:http://olado.github.io ...