辣鸡wyz最近状态奇差,于是想用usaco题找找手感,万万没想到被虐了一脸TAT

先贴代码,有空再填坑

4409[Usaco2016 Feb]Circular barn

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <algorithm>
  7. #define ll long long
  8. #define N 2333
  9.  
  10. using namespace std;
  11. inline int read(){
  12. int ret=0;char ch=getchar();
  13. while (ch<'0'||ch>'9') ch=getchar();
  14. while ('0'<=ch&&ch<='9'){
  15. ret=ret*10-48+ch;
  16. ch=getchar();
  17. }
  18. return ret;
  19. }
  20.  
  21. ll s[N][N];
  22. int n,m,a[N];
  23. ll dp[10][N];
  24. int p[10][N];
  25. int sl[N],sr[N],stk[N],top;
  26.  
  27. int main(){
  28. n=read();m=read();
  29. for (int i=1;i<=n;++i) a[i+n]=a[i]=read();
  30. for (int i=1;i<=n;++i){
  31. s[n+i][0]=s[i][0]=0;
  32. for (int j=1;j<=n;++j)
  33. s[n+i][j]=s[i][j]=s[i][j-1]+(ll)a[i+j-1]*(j-1);
  34. }
  35. top=1;sl[0]=0;sr[0]=n+1;
  36. for (int i=0;i<top;++i){
  37. stk[i]=(sl[i]+sr[i])/2;
  38. if (sl[i]+1<stk[i]){
  39. sl[top]=sl[i];
  40. sr[top]=stk[i];
  41. ++top;
  42. }
  43. if (stk[i]+1<sr[i]){
  44. sl[top]=stk[i];
  45. sr[top]=sr[i];
  46. ++top;
  47. }
  48. }
  49.  
  50. ll ans=(1LL<<60);
  51. for (int st=1;st<=n;++st){
  52. for (int i=0;i<=n;++i) dp[1][i]=s[st][i],p[1][i]=0;
  53. for (int k=2;k<=m;++k) p[k][n+1]=n,p[k][0]=0,dp[k][0]=0;
  54. for (int k=2;k<=m;++k)
  55. for (int i=0;i<top;++i){
  56. int now=stk[i];
  57. dp[k][now]=(1LL<<60);
  58. for (int j=p[k][sl[i]];j<=p[k][sr[i]]&&j<=now;++j)
  59. if (dp[k][now]>dp[k-1][j]+s[st+j][now-j]){
  60. dp[k][now]=dp[k-1][j]+s[st+j][now-j];
  61. p[k][now]=j;
  62. }
  63. }
  64. ans=min(ans,dp[m][n]);
  65. }
  66. printf("%lld\n",ans);
  67. return 0;
  68. }

4410[Usaco2016 Feb]Fence in

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <algorithm>
  7. #define ll long long
  8. #define N 25003
  9.  
  10. using namespace std;
  11. inline int read(){
  12. int ret=0;char ch=getchar();
  13. while (ch<'0'||ch>'9') ch=getchar();
  14. while ('0'<=ch&&ch<='9'){
  15. ret=ret*10-48+ch;
  16. ch=getchar();
  17. }
  18. return ret;
  19. }
  20.  
  21. int n,m,a[N],b[N];
  22.  
  23. int main(){
  24. a[0]=read();b[0]=read();n=read();m=read();
  25. for (int i=n;i;--i) a[i]=read();
  26. sort(a,a+n+1,greater<int>());
  27. for (int i=0;i<=n;++i) a[i]=a[i]-a[i+1];
  28. sort(a,a+n+1);
  29. for (int i=m;i;--i) b[i]=read();
  30. sort(b,b+m+1,greater<int>());
  31. for (int i=0;i<=m;++i) b[i]=b[i]-b[i+1];
  32. sort(b,b+m+1);
  33.  
  34. int p=1,q=1;
  35. ll ans=(ll)a[0]*m+(ll)b[0]*n;
  36. while (p<=n&&q<=m)
  37. if (a[p]<b[q])
  38. ans+=(ll)a[p++]*(m-q+1);
  39. else
  40. ans+=(ll)b[q++]*(n-p+1);
  41. printf("%lld\n",ans);
  42. return 0;
  43. }

4411[Usaco2016 Feb]Load balancing

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <algorithm>
  7. #define N 100005
  8.  
  9. using namespace std;
  10. inline int read(){
  11. int ret=0;char ch=getchar();
  12. while (ch<'0'||ch>'9') ch=getchar();
  13. while ('0'<=ch&&ch<='9'){
  14. ret=ret*10-48+ch;
  15. ch=getchar();
  16. }
  17. return ret;
  18. }
  19.  
  20. int n;
  21. int c[2][40*N];
  22.  
  23. void modify(int id,int pos,int delta){
  24. for (int x=1,l=1,r=1e6;;){
  25. c[id][x]+=delta;
  26. if (l==r) break;
  27. int mid=(l+r)/2;
  28. if (pos<=mid) x=(x<<1),r=mid;
  29. else x=(x<<1^1),l=mid+1;
  30. }
  31. }
  32.  
  33. int query(){
  34. int ds[2]={0,0},us[2]={0,0};
  35. for (int x=1,l=1,r=1e6;;){
  36. int ls=x<<1,rs=x<<1^1,mid=(l+r)/2;
  37. if (l==r) ls=rs=x;
  38. if (max(ds[0]+c[0][ls],ds[1]+c[1][ls])<max(us[0]+c[0][rs],us[1]+c[1][rs])){
  39. ds[0]+=c[0][ls];ds[1]+=c[1][ls];x=rs;l=mid+1;
  40. }
  41. else{
  42. us[0]+=c[0][rs];us[1]+=c[1][rs];x=ls;r=mid;
  43. }
  44. if (ls==rs) return max(max(ds[0],ds[1]),max(us[0],us[1]));
  45. }
  46. }
  47.  
  48. struct point{
  49. int x,y;
  50. } a[N];
  51. inline bool operator <(const point &u,const point &v){
  52. return u.x<v.x;
  53. }
  54.  
  55. int main(){
  56. n=read();
  57. memset(c,0,sizeof(c));
  58. for (int i=1;i<=n;modify(1,a[i++].y=read(),1)) a[i].x=read();
  59. sort(a+1,a+n+1);
  60. int ans=query();
  61. for (int i=1;i<=n;++i){
  62. modify(0,a[i].y,1);
  63. modify(1,a[i].y,-1);
  64. if (i<n&&a[i].x==a[i+1].x) continue;
  65. ans=min(ans,query());
  66. }
  67. printf("%d\n",ans);
  68. return 0;
  69. }

  

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. Android RecyclerView 动画展开item显示详情

    stackoverflow上看到这个问题,答主给了个demo http://stackoverflow.com/questions/27446051/recyclerview-animate-item ...

  2. 深入理解Linux修改hostname(转载)

    http://www.cnblogs.com/kerrycode/p/3595724.html http://www.centoscn.com/CentOS/config/2014/1031/4039 ...

  3. performSelector的原理以及用法

    一.performSelector调用和直接调用区别下面两段代码都在主线程中运行,我们在看别人代码时会发现有时会直接调用,有时会利用performSelector调用,今天看到有人在问这个问题,我便做 ...

  4. 微信小程序 开发 微信开发者工具 快捷键

    微信小程序已经跑起来了.快捷键设置找了好久没找到,完全凭感觉.图贴出来.大家看看. 我现在用的是0.10.101100的版本,后续版本更新快捷键也应该不会有什么变化. 现在貌似不能修改.如果有同学找到 ...

  5. matlab jet color mapping C / C++ / VC 实现

    在matlab中调用imagesc()将一幅灰阶图像以彩色显示时,默认使用的color mapping是Jet,其color bar 为: Jet的color mapping图为: Color map ...

  6. 判断 JS 中对象的类型

    1.typeof 形如 var x = "xx"; typeof x == 'string' typeof(x) 返回类型有:'undefined' “string” 'numbe ...

  7. Theano1.1-安装

    之前一直想弄theano,可是python不是很懂,在学习了一段时间之后开始安装theano.当然官网上的安装资料是全,可是也太繁琐了.这里介绍的是最简单,最方面的安装theano的方法.官网首页:h ...

  8. ASP.NET MVC 关闭 客户端 xss 检查

    为防止 XSS 攻击,asp.net 机制 会默认检测 请求报文 内是否有包含html标签,以提醒开发人员处理,报错如下:"从客户端中检测到有潜在危险的Request...值"当我 ...

  9. c8051f320学习,单片机不外乎时钟、IO、串口、USB等外设用法

      时钟 IO(输入.输出,如何配置) IO   数字和模拟资源可以通过25个I/O 引脚(C805 1F3 2 0 ),每个端口引脚都可以被定义为 通用I/O(GPIO)或 0 模拟输入 所有端口I ...

  10. UWP 拉勾客户端

    前些天, 用 Xamarin.Forms (XF) 将就着写了个拉勾的 UWP 和 Android 的客户端. XF 对 Android  和 IOS 的支持做的很到位, 但是对 UWP 的支持目前仅 ...