话说比较简单.除了第三题不会写平衡树啊你妹!!边做边写吧.
仍然是机智的链接
第一题:
题目的数据范围非常小,来个 大法狮 吧.$6^6$只有$46656$,加上浮点运算的超大常数也不多嘛 ╮(╯_╰)╭
实现有点恶心,暴力你懂得.
#include <cstdio> #include <cmath> #define PI 3.1415926535897932384626 inline double ab(double x){ return (((x)>=0)?(x):(-x)); } inline double mi(double x,double y){ y=ab(y); return (x<y?x:y); } inline double ma(double x,double y){ y=ab(y); return (x>y?x:y); } int n; double x[8],y[8],r[8],s[8],minLeft; bool f[8]; void dfs(int p,int d,double si){ double a,b,c; int i; b=ab(x[p]-x[0]); b=mi(b,x[p]-x[1]); b=mi(b,y[p]-y[1]); b=mi(b,y[p]-y[0]); for(i=2;i<=n;++i){ if(f[i]) b=mi(b,hypot(x[p]-x[i],y[p]-y[i])-r[i]); } f[p]=true; si+=PI*b*b; r[p]=b; if(d==n-1){ si=s[0]-si; if(si<minLeft){ minLeft=si; } r[p]=0.0; f[p]=false; return; } for(i=2;i<=n;++i){ if(!f[i]){ dfs(i,d+1,si); } } r[p]=0.0; f[p]=false; } int main(){ freopen("box2.in","r",stdin); freopen("box2.out","w",stdout); scanf("%d%lf%lf%lf%lf",&n,x,y,x+1,y+1); minLeft=s[0]=s[1]=ab((x[1]-x[0])*(y[1]-y[0])); ++n; int i; for(i=2;i<=n;++i) scanf("%lf%lf",x+i,y+i); for(i=2;i<=n;++i){ dfs(i,1,0.0); } printf("%.0lf",minLeft); return 0; }
~!~!@~!@@!@!##@@#@!@##@@@#@#%^&^%##@!@@我是机智的分割线~~~
第二题:
简单的动规.DP方程:
DP F[i,j]=max(F[i-1,j]+same(c[i],i-j),F[i-1,j-1])
# F[i,j]表示前i个数删去j个的最大匹配数,c[i]表示第i个数字
# same(a,b)=(a==b?1:0)
return MaxAmong(F,lengthof F)
#include <cstdio> int f[2000][2000],c[2000],n,i,j; inline int max(int a,int b){ return a>b?a:b; } int main(){ freopen("sequence.in","r",stdin); freopen("sequence.out","w",stdout); scanf("%d",&n); for(i=1;i<=n;++i){ scanf("%d",c+i); } for(i=1;i<=n;++i){ for(j=0;j<=i;++j){ f[i][j]=max(f[i-1][j]+(c[i]==i-j),f[i-1][j-1]); } } j=0; for(i=0;i<=n;++i){ if(f[n][i]>j) j=f[n][i]; } printf("%d ",j); return 0; }
真的很 短啊.
第三题:
不会写BST啊神犇滚粗!!!
好吧今天边学习边写,应该SBT比较方便实现吧.
妈旦谁骗我SBT好实现的???
贴代码:
#include <cstdio> #include <algorithm> struct node{ int key , size; node *c[2]; node(int k){ key = k; size = 1; }; void t(){size=c[0]->size+c[1]->size+1;} }; class SBT{ private: node * root , * nil; inline void insert(node * &x , int & k){ if(x->size == 0){ x = new node(k); x->c[0] = nil; x->c[1] = nil; }else{ bool l = k > x->key; x->size++; insert(x->c[l] , k); maintain(x , l); }; }; inline void rot(node * & x , bool l){ node * y = x->c[!l]; x->c[!l] = y->c[l]; y->c[l] = x; y->size = x->size; x->t(); x = y; }; inline void maintain(node * &x , bool l){ if(x->size == 0) return; if(x->c[l]->c[l]->size > x->c[!l]->size){ rot(x , !l); }else{ if(x->c[l]->c[!l]->size > x->c[!l]->size){ rot(x->c[l] , l); rot(x , !l); }else{ return; }; }; maintain(x->c[1] , 1); maintain(x->c[0] , 0); maintain(x , 1); maintain(x , 0); }; int select(int n){ node* p=root; while(n){ if(n<=p->c[0]->size){ p=p->c[0]; }else{ if(n==p->c[0]->size+1) break; n-=p->c[0]->size+1; p=p->c[1]; } } return p->key; } public: SBT(){ nil = new node(0); nil->size = 0; nil->c[0] = nil; nil->c[1] = nil; root = nil; }; inline void Insert(int k){ insert(root , k); }; inline int Select(int n){ return select(n); } }; int a,i,j,b,k,c; struct nod{ int a,id; bool f; } ned[600000]; bool cmp(nod a,nod b){ if(a.id<b.id){ return true; }else{ if(a.id>b.id){ return false; }else{ return a.f<b.f; } } } SBT sbt; int pp; int main(int argc, char const *argv[]){ freopen("blackbox.in","r",stdin); freopen("blackbox.out","w",stdout); scanf("%d%d",&a,&b); for(i=0;i<a;++i){ scanf("%d",&ned[i].a); ned[i].id=i+1; ned[i].f=false; } for(b+=a,j=a;j<b;++j){ scanf("%d",&ned[j].id); ned[j].f=true; } std::sort(ned,ned+j,cmp); c=a; a=0; for(i=0;i<j;++i){ //printf(" %d : %d %d ",i,ned[i].f,ned[i].a); if(ned[i].f){ printf("%d ",sbt.Select(++a)); }else{ sbt.Insert(ned[i].a); ++pp; } } return 0; }
这调试真爽啊!!tm花了我2天!!
还借鉴了Nocow上的代码!!
真乃 毒!品德芳香!大师!学习了! 烤焦了!太锐利了!犹如奶油一般绵延细长!在我的脑海里化开成为挥之不去的阴影!