选择一个数x会删去x+1和x-1,问可以最多选多少次。

显然,对于一段连续的数列,贪心的从左向右选取是最优的。

然后就可以贪心的统计答案了。

#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) class SRMCards{
public:
int maxTurns(vector <int> cards)
{
sort(cards.begin(),cards.end());
int cnt=1,ans=0;
for (int i=1;i<cards.size();++i)
{
if (cards[i]==cards[i-1]+1) cnt++;
else
{
ans+=(cnt+1)/2;
cnt=1;
}
}
ans+=(cnt+1)/2;
return ans;
}
};

  

Topcoder SRMCards ——贪心的更多相关文章

  1. TopCoder SRM502 Div1 500 贪心 01背包

    原文链接https://www.cnblogs.com/zhouzhendong/p/SRM502-500.html SRM502 Div1 500 好题. 首先,如果已经确定了解决所有问题的优先级, ...

  2. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  3. TopCoder比赛总结表

    TopCoder                        250                              500                                 ...

  4. *[topcoder]IncrementingSequence

    http://community.topcoder.com/stat?c=problem_statement&pm=12107 此题想了半天,当时瞥到了Greedy,所以就想着贪心,最后的方法 ...

  5. *[topcoder]JumpFurther

    http://community.topcoder.com/stat?c=problem_statement&pm=12300&rd=15699 题意:有一个无限长的阶梯,i从1到N, ...

  6. *[topcoder]GUMIAndSongsDiv1

    http://community.topcoder.com/stat?c=problem_statement&pm=12706&rd=15700 这题有意思.首先要观察到,如果选定一些 ...

  7. *[topcoder]HexagonalBoard

    http://community.topcoder.com/stat?c=problem_statement&pm=12784 真心觉得tc的div1 250不少好题,对我来说比较适合.这道题 ...

  8. [topcoder]ActivateGame

    http://community.topcoder.com/stat?c=problem_statement&pm=10750&rd=14153 http://apps.topcode ...

  9. [topcoder]NinePuzzle

    http://community.topcoder.com/stat?c=problem_statement&pm=11225&rd=14427 http://apps.topcode ...

随机推荐

  1. [学习笔记] Markdown语法备忘

    Markdown语法总结 标题 # 这是一级标题 ## 这是二级标题 ### 这是三级标题 #### 这是四级标题 ##### 这是五级标题 ###### 这是六级标题 注意#后面要加空格 字体 ** ...

  2. ansible 任务委派 delegate_to

    ansible 任务委派功能delegate_to run_noce: true  在一个主机上面只执行一次一个任务. ,如果没有这个参数的话,每个playbook中的组的主机都会执行一次. 我们有的 ...

  3. 香港城大:首创3D打印磁控微型机器人技术推动人体送药研究发展

    香港城市大学研究团队全球首创由磁力推动.3D打印的微型机器人技术,能于生物体内精确地运载细胞到指定位置,预料可用作人体送药,为癌症治疗.细胞层面的治疗.再生医学等方面的应用,带来革命性改变. 近年,再 ...

  4. js 去除数组中的空值以及数组判断是否有重复数据

    1.判断是否有重复数据 function isRepeat(array){ var hash = {}; for(var i in array) { if(array[i]!="" ...

  5. python实现单链表翻转

    题目描述: 翻转一个链表 您在真实的面试中是否遇到过这个题? Yes 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null 挑 ...

  6. centos7 python3 Saltstack配置

    Python安装完毕后,提示找不到ssl模块 pip is configured with locations that require TLS/SSL, however the ssl module ...

  7. jq封装插件,简单dome

    (function($) { $.fn.extend({ bold: function() { this.css({ fontWeight: "bold", color: 'red ...

  8. 66. Plus One@python

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The ...

  9. C语言输出多位小数

    #include<stdio.h>#include<stdlib.h>int main(){int i=0;int m=19;int n=3;int s=0;s=m/n;pri ...

  10. logback写日志

    https://blog.csdn.net/u010128608/article/details/76618263 https://blog.csdn.net/zhuyucheng123/articl ...