辣鸡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;
}

4410[Usaco2016 Feb]Fence in

#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]题解的更多相关文章

  1. BZOJ4411——[Usaco2016 Feb]Load balancing

    1.题意: 给出N个平面上的点.保证每一个点的坐标都是正奇数. 你要在平面上画两条线,一条是x=a,一条是y=b,且a和b都是偶数. 直线将平面划成4个部分,要求包含点数最多的那个部分点数最少. 2. ...

  2. [bzoj4411] [Usaco2016 Feb]Load balancing

    先离散化一下(也可以不用 枚举横坐标,用线段树维护两边纵坐标上的节点数. 每次在线段树上二分...(感觉似乎树状数组也行? #include<cstdio> #include<ios ...

  3. bzoj千题计划180:bzoj4411: [Usaco2016 Feb]Load balancing

    http://www.lydsy.com/JudgeOnline/problem.php?id=4411 用树状数组维护扫描线 一个树状数组维护扫描线之上的y<=i点,另一个维护扫描线之下y&l ...

  4. bzoj 4412: [Usaco2016 Feb]Circular Barn

    4412: [Usaco2016 Feb]Circular Barn Description 有一个N个点的环,相邻两个点距离是1.点顺时针标号为1..N.每一个点有ci头牛,保证∑ci=N.每头牛都 ...

  5. BZOJ4409 [Usaco2016 Feb]Circular barn 动态规划 斜率优化

    原文链接http://www.cnblogs.com/zhouzhendong/p/8724739.html 题目传送门 - BZOJ4409 题意 有一个N个点的环,相邻两个点距离是1.点顺时针标号 ...

  6. [bzoj4410] [Usaco2016 Feb]Fence in

    根据ccz181078大爷的题解可得(QAQ,每次肯定是断掉连续一行||一列的栅栏... 贪心地想,一个格子与外面联通,显然是先把短的边界断掉(就像mst那样 但是比较蛋疼的是,因为我们每次断的时候, ...

  7. USACO 2017 FEB Platinum mincross 可持久化线段树

    题意 上下有两个位置分别对应的序列A.B,长度为n,两序列为n的一个排列.当Ai == Bj时,上下会连一条边.你可以选择序列A或者序列B进行旋转任意K步,如 3 4 1 5 2 旋转两步为 5 2 ...

  8. USACO 2017 FEB Platinum nocross DP

    题目大意 上下有两个长度为n.位置对应的序列A.B,其中数的范围均为1~n.若abs(A[i]-B[j]) <= 4,则A[i]与B[j]间可以连一条边.现要求在边与边不相交的情况下的最大的连边 ...

  9. 【bzoj4412】[Usaco2016 Feb]Circular Barn

    先看成一条链 for一遍找位置 在for一遍算答案 #include<algorithm> #include<iostream> #include<cstring> ...

随机推荐

  1. 逗号分隔的字符串转换为行数据(collection)

    逗号分隔的字符串转换为行数据(collection) CREATE OR REPLACE FUNCTION "GET_STR_TAB" (v_str in varchar2) re ...

  2. java工程中的.classpathaaaaaaaaaaaaaaaa<转载>

    第一部分:classpath是系统的环境变量,就是说JVM加载类的时候要按这个路径下去找,当然这个路径下可以有jar包,那么就是jar包里所有的class. eclipse build path是ec ...

  3. win7的优化-1:隐藏我的电脑导航栏里的收藏等项目

    1. Type regedit in RUN or Start Menu search box and press Enter. It'll open Registry Editor. 2. Now ...

  4. php常见问题

    1,新安装的lamp在打开php文件的时候出现access forbid问题,这个出现的原因是directory的路径权限问题,解决方法 将httpd.conf中的 <Directory /&g ...

  5. Meet python: little notes 4 - high-level characteristics

    Source: http://www.liaoxuefeng.com/ ♥ Slice Obtaining elements within required range from list or tu ...

  6. Linux shell的输入输出

    echo --echo命令可以显示文本行或变量,或者把字符串输入到文件 --echo [option] string -e 解析转义字符 例如:echo -e "nimenhao\nasfd ...

  7. jquery选择器空格与大于号、加号与波浪号的区别

    空格:$('parent childchild')表示获取parent下的所有的childchild节点,所有的子孙. 大于号:$('parent > child')表示获取parent下的所有 ...

  8. jboss EAP 6.2+ 通过代码控制JNDI数据源

    通过Jboss提供的API,可以操控JBoss,效果跟在管理控制台手动操作完全一样,下面是示例代码: 一.pom.xml添加依赖项 <dependency> <groupId> ...

  9. 航空货运:运价类别Rate Class

    1.普通货物运价(1)基础运价(代号N -注:Normal的首字母)民航总局统一规定各航段货物基础运价为45公斤以下普通货物运价.(2)重量分界点运价(代号Q  -注:Quantity的首字母)国内航 ...

  10. GET请求参数为中文时乱码分析

    问题描述 近期做任务时,跟后端联调时遇到一个问题,前端发送get请求,当参数值有中文时,请求失败,请求参数变为乱码.(ps:一般当参数有中文时,很少使用get请求,而是使用post请求来传输数据,请求 ...