【非原创】codeforces 1070C Cloud Computing 【线段树树状数组】
题目:戳这里
学习博客:戳这里
题意:有很多个活动,每个活动有持续天数,每个活动会在每天提供C个CPU每个CPU价格为P,问需要工作N天,每天需要K个CPU的最少花费。
解题思路:遍历每一天,维护当前天K个cpu的最小花费。具体方法是维护两个线段树(树状数组也可以),维护每一天可以使用的cpu数和价格*cpu数的前缀和。注意数组下标是价格(1e6的数组。
(不明白的话可以看代码,代码思路很清晰
附学习博客的代码:
1 #include <iostream> 2 3 #include <algorithm> 4 5 #include <string.h> 6 7 #include <vector> 8 9 #include <memory.h> 10 11 #include <bitset> 12 13 #include <map> 14 15 #include <deque> 16 17 #include <math.h> 18 19 #include <stdio.h> 20 21 using namespace std; 22 23 typedef long long int ll; 24 25 const int MAXN = 1000005; 26 27 28 29 ll num[MAXN<<2]; 30 31 ll sum[MAXN<<2]; 32 33 int N; 34 35 void pushup(int rt){ 36 37 num[rt]=num[rt<<1]+num[rt<<1|1]; 38 39 sum[rt]=sum[rt<<1]+sum[rt<<1|1]; 40 41 } 42 43 44 45 void update(int P,int C,int l,int r,int rt){ 46 47 if(l==r){ 48 49 num[rt]+=C; 50 51 sum[rt]+=1ll*P*C; 52 53 return; 54 55 } 56 57 58 59 int m=(l+r)/2; 60 61 62 63 if(P<=m) 64 65 update(P,C,l,m,rt<<1); 66 67 else 68 69 update(P,C,m+1,r,rt<<1|1); 70 71 pushup(rt); 72 73 } 74 75 76 77 ll query(int K,int l,int r,int rt){ 78 79 80 81 if(l==r){ 82 83 //不到K个 84 85 if(l==MAXN){ 86 87 return 0; 88 89 } 90 91 if(K>0) 92 93 { 94 95 return 1ll*K*l; 96 97 } 98 99 else 100 101 return 0; 102 103 } 104 105 int m=(l+r)/2; 106 107 if(num[rt<<1]>=K){ 108 109 return query(K,l,m,rt<<1); 110 111 } 112 113 else{ 114 115 return sum[rt<<1]+query(K-num[rt<<1],m+1,r,rt<<1|1); 116 117 } 118 119 } 120 121 122 123 vector<pair<int,int> > C[MAXN];//第i天加入的活动 124 125 vector<pair<int,int> > O[MAXN];//第i天结束的活动 126 127 128 129 int main() 130 131 { 132 133 int K,M; 134 135 scanf("%d%d%d",&N,&K,&M); 136 137 138 139 int l,r,c,p; 140 141 for(int i=0;i<M;i++){ 142 143 scanf("%d%d%d%d",&l,&r,&c,&p); 144 145 C[l].push_back(make_pair(p,c));//加入的活动 146 147 O[r].push_back(make_pair(p,c));//退出的活动 148 149 } 150 151 152 153 ll ans=0; 154 155 for(int i=1;i<=N;i++){ 156 157 //新活动加入 158 159 for(int j=0;j<C[i].size();j++) 160 161 update(C[i][j].first,C[i][j].second,1,MAXN,1); 162 163 ans+=query(K,1,MAXN,1); 164 165 //活动结束 166 167 for(int j=0;j<O[i].size();j++) 168 169 update(O[i][j].first,-O[i][j].second,1,MAXN,1); 170 171 } 172 173 cout<<ans<<endl; 174 175 176 177 return 0; 178 179 }
View Code
转载于:https://www.cnblogs.com/zmin/p/9886297.html
【非原创】codeforces 1070C Cloud Computing 【线段树树状数组】相关推荐
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组
http://codeforces.com/contest/869/problem/E 题意:n*m的矩阵,q次操作,三种类型 类型1:给指定矩阵加上围栏 类型2:给指定矩阵去掉围栏 类型3:查询两点 ...
- CodeForces - 1311F Moving Points(线段树+离散化)
题目链接:点击查看 题目大意:给出 x 轴上的 n 个点,每个点都有一个位置和一个速度,每个点会根据速度在 x 轴上移动,现在规定dis( x , y )为点 x 和点 y 在移动过程中的最小距离,我 ...
- *【CodeForces - 799C】Fountains (线段树 或 树状数组,类似二元组问题)
题干: Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available ...
- 【论文翻译】Recent security challenges in cloud computing 近代云计算面临的安全挑战
Recent security challenges in cloud computing Nalini Subramanian Research Scholar⁎ , Andrews Jeyaraj ...
- 怎么获取codeforces的数据_原创 | codeforces 1417C,逆向思考的数据结构题
点击上方蓝字,关注并星标,和我一起学技术. 大家好,欢迎阅读周末算法题专题. 今天我们选择的是codeforces contest 1417的C题k-Amazing Numbers.这是一道经典的数据 ...
- CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段)
CodeForces 390E Inna and Large Sweet Matrix(树状数组改段求段) 树状数组仅仅能实现线段树区间改动和区间查询的功能,能够取代不须要lazy tag的线段树.且 ...
- Cloud Computing:云网端融合的简介、层次、典型代表、未来趋势之详细攻略
Cloud Computing:云网端融合的简介.层次.典型代表.未来趋势之详细攻略 导读:云网端融合,站在行业的角度,就是IT企业和通信企业互相掐架.抢饭碗. 目录 云网端融合的简介.层次.未来趋势 ...
- CodeForces - 641ELittle Artem and Time Machine——map+树状数组
[题目描述] CodeForces - 641ELittle Artem and Time Machine [题目分析] 题目的意思大概是有三种操作 1.在时间t加入一个数字x 2.在时间t删除一个数 ...
- Codeforces 216D Spider#39;s Web 树状数组+模拟
题目链接:http://codeforces.com/problemset/problem/216/D 题意: 对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色.否则为绿色, ...
- VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 线段树 or 树状数组+二分
http://codeforces.com/problemset/problem/159/C 题意: 给你一个字符串s,给出一个数k,k倍的s串组成新串str.然后给出n个操作,每个操作对应着pi,c ...
最新文章
- 重磅 | 中国工程院提出新一代智能制造【附下载】
- 库克的下沉,何同学的上升
- 优化网站设计(七):避免在CSS中使用表达式
- Action访问Servlet API的三种方法
- stm32启动文件ld md hd cl vl xl分析及选择
- 前后端分离项目,后端是如何处理前端传递的token?
- python更新数据库表的时间字段_python更新数据库中某个字段的数据(方法详解)
- (72)信号发生器DDS方波设计 (二)(第15天)
- android学习笔记---52_发送状态栏通知
- 自动化测试【用例设计秘籍】
- matlab求解集合覆盖问题,Set Cover Problem (集合覆盖问题)
- Python + Selenium 自动发布文章(一):开源中国
- Python数据挖掘实战-唐宇迪-专题视频课程
- 软件开发生命周期及文档
- 驱动精灵w8ndows xp sp2,独家率先支持Win8 驱动精灵2011 SP2发布
- Android 原生GPS定位 判断室内室外
- 如何掌握UI设计精髓 Logo设计有哪些基本要素
- 汉白玉产地在哪里_汉白玉产地在哪里?
- Linux 命令(217)—— iptables-restore 命令
- 随笔-OC获取系统时间,获取绝对时间,获得真实时间
热门文章
- PingInfoView,中文,以及ping包+描述的使用。
- 帆软 JS给填报控件(单元格)赋值 包含扩展单元格赋值
- java异步处理rest服务_异步处理rest服务
- 客服机器人代码_企业微信群机器人如何快速集成?无需开发连接微信公众号,表单系统,钉钉,推广,CRM,客服系统和数据库...
- python做自动化控制postman_Python自动化学习笔记(1)认识接口测试以及postman、Charles工具简单应用...
- CUPS-Centos6-dockerfile
- Golang QRCode 生成实现
- React Native vs. Cordova.
- Weblogic开启managed server报错java.lang.OutOfMemoryEr
- Java文件的写入与读出