本题枚举每多一个球需要多少个柱子,可以边加边边计算,每次只需要判断$i-Dinic()$即可;特别注意边界。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <queue> using namespace std; template<const int _n>
struct Edge
{
struct Edge_base { int to,w,next; }e[_n];
int cnt,p[_n];
Edge() { clear(); }
void clear() { cnt=,memset(p,,sizeof(p)); }
int start(const int x) { return p[x]; }
Edge_base& operator[](const int x) { return e[x]; }
void insert(const int x,const int y,const int z)
{ e[++cnt].to=y; e[cnt].next=p[x]; e[cnt].w=z; p[x]=cnt; return ; }
}; int n,level[],cur[],SSS,TTT,Ans;
Edge<> e; bool Bfs(const int S)
{
int i,t;
queue<int> Q;
memset(level,,sizeof(level));
level[S]=;
Q.push(S);
while(!Q.empty())
{
t=Q.front(),Q.pop();
for(i=e.start(t);i;i=e[i].next)
{
if(!level[e[i].to] && e[i].w)
{
level[e[i].to]=level[t]+;
Q.push(e[i].to);
}
}
}
return level[TTT];
} int Dfs(const int S,const int bk)
{
if(S==TTT)return bk;
int rest=bk;
for(int &i=cur[S];i;i=e[i].next)
{
if(level[e[i].to]==level[S]+ && e[i].w)
{
int flow=Dfs(e[i].to,min(rest,e[i].w));
e[i].w-=flow;
e[i^].w+=flow;
if((rest-=flow)<=)break;
}
}
if(rest==bk)level[S]=;
return bk-rest;
} int Dinic()
{
while(Bfs(SSS))
{
memcpy(cur,e.p,sizeof(cur));
Ans+=Dfs(SSS,0x3f3f3f3f);
}
return Ans;
} int Build()
{
SSS=,TTT=SSS+;
int j;
e.insert(SSS,,);
e.insert(,SSS,);
e.insert(,TTT,);
e.insert(TTT,,);
for(j=;j-Dinic()<=n;)
{
j++;
e.insert(SSS,j,),e.insert(j,SSS,);
e.insert(j+,TTT,),e.insert(TTT,j+,);
for(int i=;i<j;++i)
{
int t=i+j;
for(int k=;k*k<=t;++k)
if(t==k*k)
{
e.insert(i,j+,);
e.insert(j+,i,);
break;
}
}
}
return j;
} int main()
{
freopen("balla.in","r",stdin);
freopen("balla.out","w",stdout);
int mid;
scanf("%d",&n); mid=Build(); printf("%d\n",mid-); return ;
}

最新文章

  1. [CentOs7]搭建ftp服务器(3)——上传,下载,删除,重命名,新建文件夹
  2. Python时区转换
  3. Perl重命名当前目录下的文件
  4. 黑盒测试用例设计方法&amp;理论结合实际 -&gt; 因果图法
  5. Altium Designer完美双屏显示方法演示
  6. 【腾讯Bugly干货分享】RecyclerView 必知必会
  7. cas改造随笔
  8. 不错的轮播插件flexslider
  9. js+dom开发第十六天
  10. 小菜学习Lucene.Net(更新3.0.3版本使用)
  11. Android Weekly Notes Issue #250
  12. ServiceFabric极简文档-1.0 Service Fabric 自定义集群部署
  13. Swift基础之音乐播放随机变换着色板
  14. python爬虫数据解析之BeautifulSoup
  15. JS 超类和子类
  16. Openvswitch手册(4): Mirror
  17. [转]Hive开发经验问答式总结
  18. ajax代码整理
  19. # 2017-2018-1 20155224 加分项-实现mypwd
  20. pta 习题集 5-15 数组循环左移

热门文章

  1. Android Studio笔记
  2. E20170627-hm
  3. 能够完成qq信息提醒的代码
  4. [Swift通天遁地]四、网络和线程-(1)线程的锁和解锁
  5. python抢票开发——设备预约助手实现
  6. RAP接口文档的安装
  7. 如何解决error LNK2001(转载)
  8. Codeforces 771C
  9. Java系列学习(三)-基础语法
  10. C#——工厂模式