http://community.topcoder.com/stat?c=problem_statement&pm=12822&rd=15707

第一次用C++提交,艰辛。
首先想到可以从尾往前扫,只有最后覆盖的颜色才有效;
然后是想到用线段来做,用map记录线段;
然后学到了lower_bound是找到元素插入的位置,返回的*it>=该元素,也可能是end。cp博士一般得到lower后处理边界,同时用+-来做。
但这里用map不好,因为先前一道题是不用merge。这里如果要merge,可能一个很大的线段要连续merge很多小线段。
然后看了题解发现根本不用线段,每个小球就用一个A[i]表示,然后用朴素的线段表示染色就行了。
最后用1LL<<count来做pow。

#include <set>
#include <vector>
using namespace std;
class LittleElephantAndIntervalsDiv1
{
public:
long long getNumber(int M, vector <int> L, vector <int> R);
}; long long LittleElephantAndIntervalsDiv1::getNumber(int M, vector <int> L, vector <int> R)
{
vector<int> color(M+1, -1);
for (int i = 0; i < L.size(); i++)
{
for (int j = L[i]; j <= R[i]; j++)
{
color[j] = i;
}
}
set<int> result;
for (int i = 1; i <= M; i++)
{
if (color[i] != -1)
{
result.insert(color[i]);
}
}
return 1LL << result.size();
}

原来DIV 1的250题也是挺值得做的。

*[topcoder]LittleElephantAndIntervalsDiv1的更多相关文章

  1. TopCoder kawigiEdit插件配置

    kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...

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

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

  3. TopCoder比赛总结表

    TopCoder                        250                              500                                 ...

  4. Topcoder几例C++字符串应用

    本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...

  5. TopCoder

    在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...

  6. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  7. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  8. TopCoder SRM 590

     第一次做TC,不太习惯,各种调试,只做了一题...... Problem Statement     Fox Ciel is going to play Gomoku with her friend ...

  9. Topcoder Arena插件配置和训练指南

    一. Arena插件配置 1. 下载Arena 指针:http://community.topcoder.com/tc?module=MyHome 左边Competitions->Algorit ...

随机推荐

  1. 收藏2个mongodb connector网址

    https://github.com/plaa/mongo-spark https://github.com/mongodb/mongo-hadoop http://codeforhire.com/2 ...

  2. 20160507-hibernate入门

    关联映射 多对一(Employee - Department) 一对多(Department-Employee) 一对一(Person - IDCard) 多对多(teacher - student) ...

  3. hiveserver2 后台运行

    启动hivemetastore  hive --service metastore 启动hiveserver2   hive --service  hiveserver2 beeline !conne ...

  4. Oracle Split Partitions

    1. 创建分离分区的存储过程 CREATE OR REPLACE Procedure SP_Split_Partition( v_table_name_in in varchar2, v_part_n ...

  5. JAVA如何解析多层json数据

    1. 使用标准的Json对象,如org.json.JSONObject json = new org.json.JSONObject(yourJsonString);然后通过get(keyString ...

  6. 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.

    Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1. ...

  7. Unable to make the session state request to the session state server处理方法

    Server Error in '/' Application. Unable to make the session state request to the session state serve ...

  8. Redis与Memcached的比较

    网络IO模型 Memcached 是多线程,非阻塞IO复用的网络模型,分为监听主线程和worker子线程,监听线程监听网络连接,接受请求后,将连接描述字pipe 传递给worker线程,进行读写IO, ...

  9. php查询ip地址来源归属地的脚本

    <?php header('Content-Type:text/html;charset=utf-8'); if($_GET['sub']){ $ip = $_GET['ip']; $msg = ...

  10. Linux主机在LNMP环境中同时运行多个PHP版本

    这次遇到的问题是,客户网站已经使用PHP5.4运行多个网站程序,但是新安装的程序需要使用PHP5.3. 从我之前的经验来看,给网站更换PHP版本,可能会带来意想不到的后果.比如,之前某客户Discuz ...