SRM 581 D2 L2:SurveillanceSystem,重叠度
题目来源: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,重叠度的更多相关文章
- SRM 588 D2 L2:GUMIAndSongsDiv2,冷静思考,好的算法简洁明了
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12707 算法决定一切,这道题目有很多方法解,个人认为这里 ve ...
- SRM 581 D2 L3:TreeUnionDiv2,Floyd算法
题目来源:http://community.topcoder.com//stat?c=problem_statement&pm=12587&rd=15501 这道题目开始以为是要在无向 ...
- SRM 620 DIV1 L2
题意:有n个等长的string(设string的长度为m),string中的字符从'A'到'Z',容许对m列执行稳定的排序操作,问说是否能通过这m种操作将这n个string调整成对应的顺序. 题解: ...
- SRM 585 DIV1 L2
记录dp(i, j)表示前i种卡片的排列,使得LISNumber为j的方法数. #include <iostream> #include <vector> #include & ...
- SRM 588 D2 L3:GameInDarknessDiv2,DFS
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12710 采用DFS搜索,第一次写的时候忘了加访问标志,结果状态 ...
- Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1
据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...
- 高效求幂取余 算法,复杂度 log(n)
做TopCoder SRM 576 D2 L3 题目时,程序有个地方需要对一个数大量求幂并取余,导致程序运行时间很长,看了Editoral之后,发现一个超级高效的求幂并取余的算法,之前做System ...
- 利用opencv作透明重叠人群密度热度图
在作热度图的时候我们经常需要将热度图调整透明度后叠加在原图上达到更好的展示效果.比如检测人气密度的热度图: (来自sensetime) 一般作图的时候会第一时间想到matplotlib,因为可以很方便 ...
- py_faster_rcnn识别出来的结果好多红框重叠
py_faster_rcnn识别出来的结果好多红框重叠, 可以通过调节demo.py中的NMS_THRESH的值进行限制. NMS_THRESH表示非极大值抑制,这个值越小表示要求的红框重叠度越小,0 ...
随机推荐
- SQL Server sp_configure 控制内存使用
背景知识: sp_configure 显示或更改当前服务器的全局配置设置(使用 sp_configure 可以显示或更改服务器级别的设置.) 查看 全局配置值 方法 1.execute sp_co ...
- 常用的IO流
常用的IO流 •根据处理数据类型的不同分为:字节流和字符流 •根据数据流向不同分为:输入流和输出流 字节流:字节流以字节(8bit)为单位,能处理所有类型的数据(如图片.avi等). 字节输入流:In ...
- 经典CSS颜色混合模式
转自:http://www.webhek.com/css-blend-mode/ 注意:只有使用最新版的谷歌浏览器.火狐浏览器,才能正确的显示本文中的演示. Photoshop里最没有用处的一种功能— ...
- 【LeetCode练习题】Copy List with Random Pointer
Copy List with Random Pointer A linked list is given such that each node contains an additional rand ...
- MS SQL 当记录不存在时插入insert INTO not exists
INSERT INTO dbo.[T_DabaoTemp] ([PType] ,[pID] ,[NewVersion] ,[ParentC ...
- last reboot
last reboot是一个linux命令,查看上次重启时间等相关信息
- cassandra命令
压力测试:cassandra-stress [command] -node [nodes] -mode thrift user=[user] password=[password] example: ...
- 每个人应该知道的NVelocity用法
NVelocity是一个基于.NET的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由.NET代码定义的对象.从而使得界面设 ...
- NSRangeFromString(<#NSString * _Nonnull aString#>) 和rangeOfString
NSRangeFromString NSString *str1 = @"abcdef"; NSString *str2 = @"1-105"; NSStrin ...
- c# 另存为excel
去网上找了一下 看了一个比较简单的新建excel然后另存为. 要引用Microsoft.Office.Interop.Excel命名空间,如果没有的话 ,百度比我懂. 直接付代码: Microsof ...