bzoj4409&&bzoj4410&&bzoj4411[Usaco2016 Feb Platinum]题解
辣鸡wyz最近状态奇差,于是想用usaco题找找手感,万万没想到被虐了一脸TAT
先贴代码,有空再填坑
4409[Usaco2016 Feb]Circular barn
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #define ll long long
- #define N 2333
- using namespace std;
- inline int read(){
- int ret=0;char ch=getchar();
- while (ch<'0'||ch>'9') ch=getchar();
- while ('0'<=ch&&ch<='9'){
- ret=ret*10-48+ch;
- ch=getchar();
- }
- return ret;
- }
- ll s[N][N];
- int n,m,a[N];
- ll dp[10][N];
- int p[10][N];
- int sl[N],sr[N],stk[N],top;
- int main(){
- n=read();m=read();
- for (int i=1;i<=n;++i) a[i+n]=a[i]=read();
- for (int i=1;i<=n;++i){
- s[n+i][0]=s[i][0]=0;
- for (int j=1;j<=n;++j)
- s[n+i][j]=s[i][j]=s[i][j-1]+(ll)a[i+j-1]*(j-1);
- }
- top=1;sl[0]=0;sr[0]=n+1;
- for (int i=0;i<top;++i){
- stk[i]=(sl[i]+sr[i])/2;
- if (sl[i]+1<stk[i]){
- sl[top]=sl[i];
- sr[top]=stk[i];
- ++top;
- }
- if (stk[i]+1<sr[i]){
- sl[top]=stk[i];
- sr[top]=sr[i];
- ++top;
- }
- }
- ll ans=(1LL<<60);
- for (int st=1;st<=n;++st){
- for (int i=0;i<=n;++i) dp[1][i]=s[st][i],p[1][i]=0;
- for (int k=2;k<=m;++k) p[k][n+1]=n,p[k][0]=0,dp[k][0]=0;
- for (int k=2;k<=m;++k)
- for (int i=0;i<top;++i){
- int now=stk[i];
- dp[k][now]=(1LL<<60);
- for (int j=p[k][sl[i]];j<=p[k][sr[i]]&&j<=now;++j)
- if (dp[k][now]>dp[k-1][j]+s[st+j][now-j]){
- dp[k][now]=dp[k-1][j]+s[st+j][now-j];
- p[k][now]=j;
- }
- }
- ans=min(ans,dp[m][n]);
- }
- printf("%lld\n",ans);
- return 0;
- }
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #define ll long long
- #define N 25003
- using namespace std;
- inline int read(){
- int ret=0;char ch=getchar();
- while (ch<'0'||ch>'9') ch=getchar();
- while ('0'<=ch&&ch<='9'){
- ret=ret*10-48+ch;
- ch=getchar();
- }
- return ret;
- }
- int n,m,a[N],b[N];
- int main(){
- a[0]=read();b[0]=read();n=read();m=read();
- for (int i=n;i;--i) a[i]=read();
- sort(a,a+n+1,greater<int>());
- for (int i=0;i<=n;++i) a[i]=a[i]-a[i+1];
- sort(a,a+n+1);
- for (int i=m;i;--i) b[i]=read();
- sort(b,b+m+1,greater<int>());
- for (int i=0;i<=m;++i) b[i]=b[i]-b[i+1];
- sort(b,b+m+1);
- int p=1,q=1;
- ll ans=(ll)a[0]*m+(ll)b[0]*n;
- while (p<=n&&q<=m)
- if (a[p]<b[q])
- ans+=(ll)a[p++]*(m-q+1);
- else
- ans+=(ll)b[q++]*(n-p+1);
- printf("%lld\n",ans);
- return 0;
- }
4411[Usaco2016 Feb]Load balancing
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #define N 100005
- using namespace std;
- inline int read(){
- int ret=0;char ch=getchar();
- while (ch<'0'||ch>'9') ch=getchar();
- while ('0'<=ch&&ch<='9'){
- ret=ret*10-48+ch;
- ch=getchar();
- }
- return ret;
- }
- int n;
- int c[2][40*N];
- void modify(int id,int pos,int delta){
- for (int x=1,l=1,r=1e6;;){
- c[id][x]+=delta;
- if (l==r) break;
- int mid=(l+r)/2;
- if (pos<=mid) x=(x<<1),r=mid;
- else x=(x<<1^1),l=mid+1;
- }
- }
- int query(){
- int ds[2]={0,0},us[2]={0,0};
- for (int x=1,l=1,r=1e6;;){
- int ls=x<<1,rs=x<<1^1,mid=(l+r)/2;
- if (l==r) ls=rs=x;
- if (max(ds[0]+c[0][ls],ds[1]+c[1][ls])<max(us[0]+c[0][rs],us[1]+c[1][rs])){
- ds[0]+=c[0][ls];ds[1]+=c[1][ls];x=rs;l=mid+1;
- }
- else{
- us[0]+=c[0][rs];us[1]+=c[1][rs];x=ls;r=mid;
- }
- if (ls==rs) return max(max(ds[0],ds[1]),max(us[0],us[1]));
- }
- }
- struct point{
- int x,y;
- } a[N];
- inline bool operator <(const point &u,const point &v){
- return u.x<v.x;
- }
- int main(){
- n=read();
- memset(c,0,sizeof(c));
- for (int i=1;i<=n;modify(1,a[i++].y=read(),1)) a[i].x=read();
- sort(a+1,a+n+1);
- int ans=query();
- for (int i=1;i<=n;++i){
- modify(0,a[i].y,1);
- modify(1,a[i].y,-1);
- if (i<n&&a[i].x==a[i+1].x) continue;
- ans=min(ans,query());
- }
- printf("%d\n",ans);
- return 0;
- }
bzoj4409&&bzoj4410&&bzoj4411[Usaco2016 Feb Platinum]题解的更多相关文章
- BZOJ4411——[Usaco2016 Feb]Load balancing
1.题意: 给出N个平面上的点.保证每一个点的坐标都是正奇数. 你要在平面上画两条线,一条是x=a,一条是y=b,且a和b都是偶数. 直线将平面划成4个部分,要求包含点数最多的那个部分点数最少. 2. ...
- [bzoj4411] [Usaco2016 Feb]Load balancing
先离散化一下(也可以不用 枚举横坐标,用线段树维护两边纵坐标上的节点数. 每次在线段树上二分...(感觉似乎树状数组也行? #include<cstdio> #include<ios ...
- bzoj千题计划180:bzoj4411: [Usaco2016 Feb]Load balancing
http://www.lydsy.com/JudgeOnline/problem.php?id=4411 用树状数组维护扫描线 一个树状数组维护扫描线之上的y<=i点,另一个维护扫描线之下y&l ...
- bzoj 4412: [Usaco2016 Feb]Circular Barn
4412: [Usaco2016 Feb]Circular Barn Description 有一个N个点的环,相邻两个点距离是1.点顺时针标号为1..N.每一个点有ci头牛,保证∑ci=N.每头牛都 ...
- BZOJ4409 [Usaco2016 Feb]Circular barn 动态规划 斜率优化
原文链接http://www.cnblogs.com/zhouzhendong/p/8724739.html 题目传送门 - BZOJ4409 题意 有一个N个点的环,相邻两个点距离是1.点顺时针标号 ...
- [bzoj4410] [Usaco2016 Feb]Fence in
根据ccz181078大爷的题解可得(QAQ,每次肯定是断掉连续一行||一列的栅栏... 贪心地想,一个格子与外面联通,显然是先把短的边界断掉(就像mst那样 但是比较蛋疼的是,因为我们每次断的时候, ...
- USACO 2017 FEB Platinum mincross 可持久化线段树
题意 上下有两个位置分别对应的序列A.B,长度为n,两序列为n的一个排列.当Ai == Bj时,上下会连一条边.你可以选择序列A或者序列B进行旋转任意K步,如 3 4 1 5 2 旋转两步为 5 2 ...
- USACO 2017 FEB Platinum nocross DP
题目大意 上下有两个长度为n.位置对应的序列A.B,其中数的范围均为1~n.若abs(A[i]-B[j]) <= 4,则A[i]与B[j]间可以连一条边.现要求在边与边不相交的情况下的最大的连边 ...
- 【bzoj4412】[Usaco2016 Feb]Circular Barn
先看成一条链 for一遍找位置 在for一遍算答案 #include<algorithm> #include<iostream> #include<cstring> ...
随机推荐
- Android RecyclerView 动画展开item显示详情
stackoverflow上看到这个问题,答主给了个demo http://stackoverflow.com/questions/27446051/recyclerview-animate-item ...
- 深入理解Linux修改hostname(转载)
http://www.cnblogs.com/kerrycode/p/3595724.html http://www.centoscn.com/CentOS/config/2014/1031/4039 ...
- performSelector的原理以及用法
一.performSelector调用和直接调用区别下面两段代码都在主线程中运行,我们在看别人代码时会发现有时会直接调用,有时会利用performSelector调用,今天看到有人在问这个问题,我便做 ...
- 微信小程序 开发 微信开发者工具 快捷键
微信小程序已经跑起来了.快捷键设置找了好久没找到,完全凭感觉.图贴出来.大家看看. 我现在用的是0.10.101100的版本,后续版本更新快捷键也应该不会有什么变化. 现在貌似不能修改.如果有同学找到 ...
- matlab jet color mapping C / C++ / VC 实现
在matlab中调用imagesc()将一幅灰阶图像以彩色显示时,默认使用的color mapping是Jet,其color bar 为: Jet的color mapping图为: Color map ...
- 判断 JS 中对象的类型
1.typeof 形如 var x = "xx"; typeof x == 'string' typeof(x) 返回类型有:'undefined' “string” 'numbe ...
- Theano1.1-安装
之前一直想弄theano,可是python不是很懂,在学习了一段时间之后开始安装theano.当然官网上的安装资料是全,可是也太繁琐了.这里介绍的是最简单,最方面的安装theano的方法.官网首页:h ...
- ASP.NET MVC 关闭 客户端 xss 检查
为防止 XSS 攻击,asp.net 机制 会默认检测 请求报文 内是否有包含html标签,以提醒开发人员处理,报错如下:"从客户端中检测到有潜在危险的Request...值"当我 ...
- c8051f320学习,单片机不外乎时钟、IO、串口、USB等外设用法
时钟 IO(输入.输出,如何配置) IO 数字和模拟资源可以通过25个I/O 引脚(C805 1F3 2 0 ),每个端口引脚都可以被定义为 通用I/O(GPIO)或 0 模拟输入 所有端口I ...
- UWP 拉勾客户端
前些天, 用 Xamarin.Forms (XF) 将就着写了个拉勾的 UWP 和 Android 的客户端. XF 对 Android 和 IOS 的支持做的很到位, 但是对 UWP 的支持目前仅 ...