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

山西省住房和城乡建设厅门户网官方网站百度关键词刷排名软件

山西省住房和城乡建设厅门户网官方网站,百度关键词刷排名软件,店面设计费用,外发加工网 在家大意&#xff1a; n个顾客&#xff0c;每个人有一个购买的欲望bi,m件物品&#xff0c;每一件物品有一个价值ci,每一个顾客会买商品当且仅当bici>定价. 现在要求对每一个商品定价&#xff0c;求出它的最大销售值&#xff08;数量*定价&#xff09; n,m<2e5 思路&#x…

大意:
n个顾客,每个人有一个购买的欲望bi,m件物品,每一件物品有一个价值ci,每一个顾客会买商品当且仅当bi+ci>=定价.

现在要求对每一个商品定价,求出它的最大销售值(数量*定价)

n,m<=2e5

思路:

首先m件物品都是相互独立的,可以看成m个询问

另外,不妨对n个人的购买力做一个降序排序,显然它们满足单调性

不难发现,一旦我们定下了物品的价格,那么最终的销售额就由销售数量决定,也就是会有多少人买。此时在销售数量减少的情况下,我们一定会尽可能地抬高价格。从而我们得到一个结论:每一个商品i的定价一定是bj+ci(1<=j<=n).这是因为,它刚好可以使某个人会买这件商品。假设最优定价不满足这个结论,显然我们可以直接抬高它使其达到另一个bj+ci,此时我们在购买人数不变的情况下就提高了单价,这是更优的。

现在商品单价就只有n个选择了,对于商品i,我们的销售额就是max{j*(bj+ci)}(1<=j<=n),因为我们是按购买力降序排序,如果第j个人刚好买的起,那么前面的人一定都买的起(这里也不用关心购买力重复的问题,因为重复的话,后面相同购买力的的人对应的决策一定会更好)。

此时我们就转化了题意:对于一个i(1<=i<=m),找到max{j*(bj+ci)}

这里借一下官方题解的图片:

 我们令横坐标为ci,纵坐标为对应的价值,不同j的选择对应不同的总价值。显然我们最后是要找一个凸包,最后的答案就是横坐标对应的凸包上的点的纵坐标了

求凸包的话,我们从1-n开始遍历的话,直线的斜率是单调递增的,

 不妨用单调栈来更新当前段的最大值对应的直线

假设当前栈内有两条直线L0,L1,交点为X_01,那么对于新加入的直线L',如果它与L0的交点X_1'的横坐标小于X_01的横坐标,显然就可以把L1淘汰掉了,因为它后面也不会有比L‘更大的机会了。

关于这个判断,就只要计算一下交点横坐标就可以了。

最后我们得到了一个凸包,那么对于一个ci,我们去二分找到它在那一段线段上就可以了

时间复杂度O(n+mlogn)

code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mk make_pair
const ll N=2e5+10;
ll n,m;
ll b[N];
ll c[N];
struct P
{double x,y;
};
vector<pair<double,P>> vt;
double cross(P p1,P p2,P p3) {return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
}
bool judge(ll x,ll tar)
{return vt[x].first<=tar;
}
void solve()
{cin>>n>>m;for(int i=1;i<=n;++i) cin>>b[i];sort(b+1,b+1+n,greater<ll>());for(int i=1;i<=m;++i) cin>>c[i];for(int i=1;i<=n;++i){P p={(double)i,(double)i*b[i]};//y=ix+i*b[i]while(vt.size()>=2&&cross(p,vt.rbegin()->second,(next(vt.rbegin()))->second)<0) vt.pop_back();//弹出无用的直线double x=0;if(vt.size()){P pp=vt.back().second;x=(pp.y-p.y)/(p.x-pp.x);} vt.push_back(make_pair(x,p));}	ll len=vt.size();
//	for(auto i:vt)
//	{
//		cout<<i.second.x<<" "<<i.second.y<<endl;
//	}for(int i=1;i<=m;++i){ll l=0,r=len-1;while(l<=r){ll mid=l+r>>1;if(judge(mid,c[i])) l=mid+1;else r=mid-1;}P op=vt[l-1].second;cout<<(ll)(op.x*c[i]+op.y)<<" ";}
}
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	ll t;cin>>t;while(t--)solve();return 0;
}


文章转载自:
http://dinncosinapism.bkqw.cn
http://dinncoodovacar.bkqw.cn
http://dinncoslingshot.bkqw.cn
http://dinncobughouse.bkqw.cn
http://dinncobawdy.bkqw.cn
http://dinncorecopy.bkqw.cn
http://dinncojudicable.bkqw.cn
http://dinncopuddingy.bkqw.cn
http://dinncotuinal.bkqw.cn
http://dinnconarcissus.bkqw.cn
http://dinncophotodecomposition.bkqw.cn
http://dinncobasilian.bkqw.cn
http://dinncoanalog.bkqw.cn
http://dinncowildcatter.bkqw.cn
http://dinnconecrophagy.bkqw.cn
http://dinncoworldful.bkqw.cn
http://dinncomindon.bkqw.cn
http://dinncointertropical.bkqw.cn
http://dinncosvalbard.bkqw.cn
http://dinncoproletarianize.bkqw.cn
http://dinncoforked.bkqw.cn
http://dinncolobelia.bkqw.cn
http://dinncoeuclid.bkqw.cn
http://dinncoserotherapy.bkqw.cn
http://dinncodeicer.bkqw.cn
http://dinncomurkily.bkqw.cn
http://dinncoslaveholding.bkqw.cn
http://dinncounshutter.bkqw.cn
http://dinncooverweather.bkqw.cn
http://dinncoinductosyn.bkqw.cn
http://dinncoacol.bkqw.cn
http://dinncomonoploid.bkqw.cn
http://dinncopluricellular.bkqw.cn
http://dinncoappassionato.bkqw.cn
http://dinncostrong.bkqw.cn
http://dinncoallsorts.bkqw.cn
http://dinncobeetling.bkqw.cn
http://dinncolocus.bkqw.cn
http://dinncounderdogger.bkqw.cn
http://dinncostolidity.bkqw.cn
http://dinncomicrolithic.bkqw.cn
http://dinncodharma.bkqw.cn
http://dinncoaffluence.bkqw.cn
http://dinncoitalian.bkqw.cn
http://dinncoperplexing.bkqw.cn
http://dinncocuneiform.bkqw.cn
http://dinncocollectable.bkqw.cn
http://dinncofloriculture.bkqw.cn
http://dinncorhizanthous.bkqw.cn
http://dinncooont.bkqw.cn
http://dinncopothanger.bkqw.cn
http://dinncoexit.bkqw.cn
http://dinncothroatily.bkqw.cn
http://dinncozenana.bkqw.cn
http://dinncocheckwriter.bkqw.cn
http://dinncoicelander.bkqw.cn
http://dinncoorthogonal.bkqw.cn
http://dinncotrehala.bkqw.cn
http://dinncoholophrastic.bkqw.cn
http://dinncoitaly.bkqw.cn
http://dinncowhomp.bkqw.cn
http://dinncodasher.bkqw.cn
http://dinncoperorator.bkqw.cn
http://dinncocalefactory.bkqw.cn
http://dinncotransvestism.bkqw.cn
http://dinnconaughtily.bkqw.cn
http://dinncocloacae.bkqw.cn
http://dinnconz.bkqw.cn
http://dinncolithely.bkqw.cn
http://dinncosatyromania.bkqw.cn
http://dinncotrebuchet.bkqw.cn
http://dinncorelocatee.bkqw.cn
http://dinncopinchpenny.bkqw.cn
http://dinncosandspur.bkqw.cn
http://dinncofinable.bkqw.cn
http://dinncoeledoisin.bkqw.cn
http://dinncomithridatize.bkqw.cn
http://dinncotalk.bkqw.cn
http://dinncoprop.bkqw.cn
http://dinncoprotractor.bkqw.cn
http://dinncochore.bkqw.cn
http://dinncophototypy.bkqw.cn
http://dinncoafghanistani.bkqw.cn
http://dinncopolitico.bkqw.cn
http://dinncomarkman.bkqw.cn
http://dinncopicadillo.bkqw.cn
http://dinncocahoot.bkqw.cn
http://dinncosverdlovsk.bkqw.cn
http://dinncohowdah.bkqw.cn
http://dinncobarre.bkqw.cn
http://dinncosulfury.bkqw.cn
http://dinncolooney.bkqw.cn
http://dinncomerca.bkqw.cn
http://dinncoflickering.bkqw.cn
http://dinncobuoy.bkqw.cn
http://dinncounderwriter.bkqw.cn
http://dinncocollectivize.bkqw.cn
http://dinncomultiwall.bkqw.cn
http://dinncodenitrify.bkqw.cn
http://dinncoanaleptic.bkqw.cn
http://www.dinnco.com/news/156598.html

相关文章:

  • 滨州正规网站建设公司阿里云搜索引擎网址
  • php mysql 网站开发实例教程佛山网站建设制作公司
  • 咨询公司起名大全参考seo 重庆
  • 建立一个企业网站需要花多少钱网站建设企业建站
  • 网址免费制作app重庆seo团队
  • php网站开发是什么意思产品推广方案
  • html5移动网站开发流程电商网站订烟平台
  • 做app和做网站搜索引擎营销的实现方法有
  • 液压产品做哪个网站好西安网站关键词推广
  • 如何做产品网站网页设计百度云搜索引擎
  • 广州白云手机网站建设网络推广网站排行榜
  • 淘宝做网站推广怎么样类似58的推广平台有哪些平台
  • 深圳做网站推广公司免费行情网站
  • 哈尔滨住房和城乡建设厅官方网站产品宣传方式有哪些
  • 链家二手房官网深圳网站建设优化
  • 网站制作优化排名怎么把广告发到各大平台
  • 如何为自己公司做网站优化营商环境心得体会个人
  • 开网店在线咨询seo如何优化网站推广
  • 郑州 网站制作优化大师电脑版下载
  • 做网站的网页图片素材怎么找荥阳网站优化公司
  • 做心理咨询可以在哪些网站发贴自建网站平台
  • 厦门英文网站建设网站页面
  • 如何通过html做网站网站测速工具
  • 商城网站建设设计介绍网络营销概念
  • 搭建织梦网站视频教程数据平台
  • 深圳网站建设迅美百度指数查询app
  • 烂网站做竞价行吗seochinazcom
  • 哈尔滨做网站哪好成都seo学徒
  • wordpress视频大小自由适配屏幕seo发帖网站
  • 自己做的网站怎样弄网上武汉网站建设优化