题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12588

在判断 ‘+’ 的时候使用了 重叠度 的概念,跟一般的 “先去掉这个位置,看剩下的位置能不能符合条件” 方法不太一样。

代码如下:

#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional> #include <iostream>
#include <sstream> #include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map> #include <cstdio>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring> using namespace std; /************** Program Begin *********************/
const int MAX = 50;
int flag[MAX];
class SurveillanceSystem {
public:
string getContainerInfo(string containers, vector <int> reports, int L) {
string res(containers.size(), '-');
vector < vector<int> > pos( containers.size()+1 );
// pos[c]表示能够监视到c个'X'的所有的位置的起始处
vector <int> rep_count( L+1 ); // rep_count[c]表示,reports中c出现的次数 for (int i = 0; i <= containers.size()-L; i++) {
int c = count(&containers[i], &containers[i]+L, 'X');
// 计算各个位置能监视到的'X'
pos[c].push_back(i);
}
for (int i = 0; i < reports.size(); i++) {
++rep_count[ reports[i] ];
} for (int i = 0; i <= L; i++) {
int rc = rep_count[i];
if (rc == 0) {
continue;
} // 表示i在reports中出现rc次,而满足可以监视到i个'X'的段保存在pos[i]中,
// 一共有pos[i].size个这样的段,也就是要从中选出rc个段,使用每个位置的
// 重叠度来判断该位置是否一定会被监视到。位置的重叠度表示该位置在
// pos[i].size个段中出现的次数。如果其出现次数大于pos[i].size-rc,则
// 这个位置一定会被监视到。因为如果这个位置没有被监视的话,那么找不符合
// 条件的rc个段。
memset(flag, 0, sizeof(flag));
for (int j = 0; j < pos[i].size(); j++) {
for (int k = 0; k < L; k++) {
if ('-' == res[ pos[i][j] + k ]) {
// 在段中出现的位置置为'?'
res[ pos[i][j] + k ] = '?';
}
++flag[ pos[i][j]+k ]; // 该位置重叠度加1
}
}
for (int j = 0; j < containers.size(); j++) {
if (flag[j] > pos[i].size() - rc) {
//判断重叠度,判断该位置是否必定被监视
res[j] = '+';
}
}
} return res;
}
}; /************** Program End ************************/

SRM 581 D2 L2:SurveillanceSystem,重叠度的更多相关文章

  1. SRM 588 D2 L2:GUMIAndSongsDiv2,冷静思考,好的算法简洁明了

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12707 算法决定一切,这道题目有很多方法解,个人认为这里 ve ...

  2. SRM 581 D2 L3:TreeUnionDiv2,Floyd算法

    题目来源:http://community.topcoder.com//stat?c=problem_statement&pm=12587&rd=15501 这道题目开始以为是要在无向 ...

  3. SRM 620 DIV1 L2

    题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...

  4. SRM 585 DIV1 L2

    记录dp(i, j)表示前i种卡片的排列,使得LISNumber为j的方法数. #include <iostream> #include <vector> #include & ...

  5. SRM 588 D2 L3:GameInDarknessDiv2,DFS

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12710 采用DFS搜索,第一次写的时候忘了加访问标志,结果状态 ...

  6. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

  7. 高效求幂取余 算法,复杂度 log(n)

    做TopCoder SRM 576 D2 L3 题目时,程序有个地方需要对一个数大量求幂并取余,导致程序运行时间很长,看了Editoral之后,发现一个超级高效的求幂并取余的算法,之前做System ...

  8. 利用opencv作透明重叠人群密度热度图

    在作热度图的时候我们经常需要将热度图调整透明度后叠加在原图上达到更好的展示效果.比如检测人气密度的热度图: (来自sensetime) 一般作图的时候会第一时间想到matplotlib,因为可以很方便 ...

  9. py_faster_rcnn识别出来的结果好多红框重叠

    py_faster_rcnn识别出来的结果好多红框重叠, 可以通过调节demo.py中的NMS_THRESH的值进行限制. NMS_THRESH表示非极大值抑制,这个值越小表示要求的红框重叠度越小,0 ...

随机推荐

  1. createDocumentFragment

    http://www.cnblogs.com/myjavascript/p/3708920.html 对于循环批量操作页面的DOM有很大帮助!利用文档碎片处理,然后一次性append,并且使用原生的j ...

  2. thinkphp中的_get,_post,_request

    ThinkPHP没有改变原生的PHP系统变量获取方式,所以依然可以通过$_GET. $_POST.$_SERVER.$_REQUEST 等方式 来获取系统变量,不过系统的Action类提供了对系统变量 ...

  3. php排序算法之选择排序

    /** * 选择排序 * 不稳定排序 *工作原理: 首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾.以此类推 ...

  4. UIScrollView 与 UIPageView 的联合使用

       @interface ViewController : UIViewController<UIScrollViewDelegate> { UIScrollView * scrollV ...

  5. 创建和使用RMAN存储脚本

    创建和使用RMAN存储脚本:1.连接恢复目录(可以不连接到目标库):C:\Users\Administrator>rman target sys/rusky@rusky catalog=rcat ...

  6. .net通用权限框架B/S(一)

    一直做软件实施,用过一些二次开发平台,最近看了一些大神写的框架,于是参考写了一个B/S通用权限框架,项目使用MVC4+EF5+EASYUI(.net framework4),开发环境vs2010+sq ...

  7. c# 自定义位数生成激活码

    Random random = new Random(~unchecked((int)DateTime.Now.Ticks));private string CreateAndCheckCode(Ra ...

  8. Ubuntu 12.04 wireless networks : devices not ready (firmware missing)解决办法

    今天装了Ubuntu12.04之后,发现无线不能用. 用iwconfig查看,wlan0 项后面有内容,但是在本该显示无线列表的地方显示的是 “ wireless networks : devices ...

  9. jquery实现div垂直居中

    <html> <head> <meta charset="UTF-8"> <title></title> <scr ...

  10. Android.Hacks.01_Centering views using weights

    Android.Hacks读书笔记01 #1#权重布局之解析: LinearLayout ’s android:weightSum      LinearLayout ’s child android ...