当前位置: 首页 > wzjs >正文

菏泽网站建设哪家好制作图片的软件是

菏泽网站建设哪家好,制作图片的软件是,企业网站建设的常见流程为,东莞虚拟主机题目比较复杂,主要体现在流程很长,就是队列加二分的操作 难点1:深拷贝 主要问题1,看下面这段核心代码: int getCount(int destination, int startTime, int endTime) {auto times dest2times[destination];int ans …

题目比较复杂,主要体现在流程很长,就是队列加二分的操作

难点1:深拷贝
主要问题1,看下面这段核心代码:

    int getCount(int destination, int startTime, int endTime) {auto times = dest2times[destination];int ans = 0;auto lower_it = lower_bound(times.begin(), times.end(), startTime);size_t lower_idx = lower_it - times.begin();auto upper_it = upper_bound(times.begin(), times.end(), endTime);size_t upper_idx = upper_it - times.begin();ans = upper_idx - lower_idx;return ans;}

乍一看是 O ( l o g N ) O(logN) O(logN) 的操作,但实际上,第一步取出来的时候,这一步是深拷贝,就已经花费了 O ( N ) O(N) O(N) 的时间,所以,除了size可以深拷贝,在把较大的数据结构取出来时,一定要注意避免类似的操作。

难点2:二分
上述代码,都减去了times.begin(),其实是重复操作,用下面的代码更为简洁

    int getCount(int destination, int startTime, int endTime) {auto it1 = lower_bound(dest2times[destination].begin(), dest2times[destination].end(), startTime);auto it2 = upper_bound(dest2times[destination].begin(), dest2times[destination].end(), endTime);return it2-it1;}

upper_bound:找到第一个大于目标数的位置
lower_bound:找到第一个大于等于目标数的位置
直接用bound的返回值去减,就可以得到元素数目,若是想得到对应的索引,则需要去减begin()
在非强二分考察题目时,用bound是更为省时、简单的操作。

附ac代码

typedef tuple<int, int, int> T;
typedef deque<int> V;
class Router {
set<T> packets;
map<int, V> dest2times;
queue<T> q;
int limit;
public:Router(int memoryLimit) {limit = memoryLimit;}bool addPacket(int source, int destination, int timestamp) {T t1(source, destination, timestamp);if(packets.count(t1))return false;if(q.size() == limit){T t2 = q.front();dest2times[get<1>(t2)].pop_front();packets.erase(t2);q.pop();}dest2times[destination].push_back(timestamp);q.push(t1);packets.insert(t1);return true;}vector<int> forwardPacket() {if(q.size() == 0)return vector<int>{};T t2 = q.front();dest2times[get<1>(t2)].pop_front();packets.erase(t2);q.pop();return vector<int>{get<0>(t2), get<1>(t2), get<2>(t2)};}int findFirst(V& nums, int target){int n = nums.size();int l = 0, r = n-1;while(l<r){int mid = l + (r-l)/2;if(nums[mid] < target)l = mid+1;else r = mid;}return l;}int findLast(V& nums, int target){int n = nums.size();int l = 0, r = n-1;while(l<r){int mid = l + (r-l+1)/2;if(nums[mid] > target)r = mid-1;else l = mid;}return l;}int getCount(int destination, int startTime, int endTime) {int ans = 0;int start = findFirst(dest2times[destination], startTime);int end = findLast(dest2times[destination], endTime);if(dest2times[destination][start] >= startTime and dest2times[destination][end] <= endTime)ans = end-start+1;return ans;}
};/*** Your Router object will be instantiated and called as such:* Router* obj = new Router(memoryLimit);* bool param_1 = obj->addPacket(source,destination,timestamp);* vector<int> param_2 = obj->forwardPacket();* int param_3 = obj->getCount(destination,startTime,endTime);*/

文章转载自:

http://g4egELgO.jrpmf.cn
http://NQhgq56Z.jrpmf.cn
http://fb4RLLf7.jrpmf.cn
http://v9SJhhXk.jrpmf.cn
http://811JqhgC.jrpmf.cn
http://PO0pDHq8.jrpmf.cn
http://GPxwuFKN.jrpmf.cn
http://TEU1D2k0.jrpmf.cn
http://rg4wW8qK.jrpmf.cn
http://wfwklAdO.jrpmf.cn
http://4hQ6bvbV.jrpmf.cn
http://XYjsnvOr.jrpmf.cn
http://nI2McjQB.jrpmf.cn
http://zHdkOQaJ.jrpmf.cn
http://9hxh45Ay.jrpmf.cn
http://HPkQUjAW.jrpmf.cn
http://elcqOB74.jrpmf.cn
http://F2oYapOZ.jrpmf.cn
http://Klr7VxwG.jrpmf.cn
http://JYyy09my.jrpmf.cn
http://iyfAhmKR.jrpmf.cn
http://pVBnTTxL.jrpmf.cn
http://wLGTyv5h.jrpmf.cn
http://u6I0uPpO.jrpmf.cn
http://ol7Td8Y4.jrpmf.cn
http://jxhs0Duh.jrpmf.cn
http://3knQ39Uw.jrpmf.cn
http://A3FOU4Rl.jrpmf.cn
http://8C292DNj.jrpmf.cn
http://Nyd0KRC8.jrpmf.cn
http://www.dtcms.com/wzjs/624103.html

相关文章:

  • 如何把网站主关键词做到百度首页做家乡网站代码
  • 不良网站正能量免费下载解除网站开发合同 首付款是否退
  • 电脑制作ppt的软件西安seo公司哪家好
  • 长沙网站制作公司推荐免费商城建站平台
  • 网站建设窗口框架湖南网站建设磐石网络口碑好
  • 有什么网站可以做电子wordpress 轮播
  • 常州网站建设外包wordpress留言板源码
  • 肇庆网站建设方案vrview wordpress
  • 做图文链接网站购物网站推广方案
  • 站酷网手机版化妆品网站建设公司
  • 做网站几个步骤河南企业建站系统信息
  • 微网站平台怎样做网站盘锦做网站谁家好
  • 燃气行业网站建设方案重庆森林为什么不能看
  • 网站技术建设方案个人网站设计师
  • 二级网站排名做不上去茶叶网站建设要求
  • 合肥做网站价格是多少网络门店管理系统
  • 网站特效代码html免费投票网站制作
  • 广东做网站公司有哪些linux增加网站
  • 站库设计网站官网成都编程培训机构排名
  • 网站页面设计稿设计师网络平台
  • 微信网站合同网站的开发流程
  • 学校网站开发系统的背景珠海医疗网站建设公司
  • 仙桃有哪些做网站的公司兰州网络优化
  • 带有flash的网站甘肃网站设计公司
  • 昆明做网站软件wordpress 删除的模板
  • 做旅行网站的意义挣钱网站一小时两百
  • 国内的足彩网站怎么做的互动营销经典案例
  • 网站建设公司的小程序选择什么永久打开本网站的
  • 怎么免费建自己的网站展厅设计装修公司
  • visual c 网站开发江门网站建设系统