1.油滴扩展(box)
搜索,注意精度。
#include<fstream> #include<cmath> #define pi 3.1415926575897932 using namespace std; ifstream cin("box.in"); ofstream cout("box.out"); int n; int x,y,xx,yy; double tot=0,ans=0; bool v[8]; struct list { int x,y; double r; }d[8]; void dfs(int a,double sum) { if (a==(n+1)) { if (sum>ans) ans=sum; return; } for (int j=1;j<=n;j++) if (!v[j]) { d[j].r=min(min(min(abs((double)(d[j].x-x)),abs((double)(d[j].x-xx))),abs((double)(d[j].y-y))),abs((double)(d[j].y-yy))); for (int i=1;i<=n;i++) if (v[i]) { double t=sqrt(abs((double)(d[j].x-d[i].x))*abs((double)(d[j].x-d[i].x))+abs((double)(d[j].y-d[i].y))*abs((double)(d[j].y-d[i].y))); t-=d[i].r; if (t<0) t=0; d[j].r<?=t; } v[j]=true; dfs(a+1,sum+pi*d[j].r*d[j].r); v[j]=false; } } int main() { cin>>n; cin>>x>>y>>xx>>yy; for (int i=1;i<=n;i++) cin>>d[i].x>>d[i].y; dfs(1,0); tot=abs((double)(x-xx))*abs((double)(y-yy)); int rest=(int)(tot-ans+0.5); cout<<rest<<endl; return 0; }
2.数列(sequence)
f[i,j]=max{f[i-1,j-1],f[i-1,j]+(a[i]=i-j)}
#include<fstream> using namespace std; ifstream cin("sequence.in"); ofstream cout("sequence.out"); int n,a[1100]; int f[1100][1100]={0}; int main() { int i,j; cin>>n; for (i=1;i<=n;i++) cin>>a[i]; for (i=1;i<=n;i++) for (j=1;j<=i;j++) { f[i][j]=max(f[i-1][j],f[i-1][j-1]); if (a[i]==(i-j+1)) f[i][j]=max(f[i][j],f[i-1][j]+1); } int ans=0; for (i=1;i<=n;i++) ans>?=f[n][i]; cout<<ans<<endl; return 0; }
3.SOFTWARE
二分答案,判断条件f[i,j+k]=max{f[i-1,j]+(mid-k*a[i])/b[i]} (k+j<=m&&mid>=a[i]*k)
#include<fstream> #include<cstdlib> using namespace std; ifstream cin("software.in"); ofstream cout("software.out"); int n,m,maxtime; struct list { int a,b; }d[110]; int f[110][110]; bool check(int mid) { memset(f,-1,sizeof(f)); f[0][0]=0; for (int i=1;i<=n;i++) for (int j=0;j<=m;j++) { if (f[i-1][j]<0) continue; for (int k=0;(j+k<=m) && (mid>=d[i].a*k);k++) f[i][j+k]>?=f[i-1][j]+((mid-k*d[i].a)/d[i].b); } return (f[n][m]>=m); } int main() { cin>>n>>m; for (int i=1;i<=n;i++) { cin>>d[i].a>>d[i].b; maxtime>?=d[i].a; maxtime>?=d[i].b; } int l=0,r=m*maxtime,mid; while (l<r) { mid=(l+r)>>1; if (!check(mid)) l=mid+1; else r=mid; } cout<<l<<endl; return 0; }
4.黑匣子(blackbox)
二分查找树
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
program blackbox;
type rec=^node;
node=record
num,tot:longint;
l,r:rec;
end;
var a,b:array[0..200000]of longint;
i,j,k,m,n,last:longint;
root:rec;
procedure add(var p:rec;x:longint);
begin
if p=nil then
begin
new(p);
p^.num:=x;
p^.tot:=1;
p^.l:=nil;
p^.r:=nil;
end
else
begin
inc(p^.tot);
if x<p^.num then add(p^.l,x)
else add(p^.r,x);
end;
end;
procedure dfs(p:rec;k:longint);
var tt:longint;
begin
if p^.l=nil then tt:=1
else tt:=p^.l^.tot+1;
if k=tt then writeln(p^.num)
else if k<tt then dfs(p^.l,k) else dfs(p^.r,k-tt);
end;
begin
assign(input,'blackbox.in');reset(input);
assign(output,'blackbox.out');rewrite(output);
readln(m,n);
for i:=1 to m do read(a[i]);
last:=1;
k:=0;
root:=nil;
for i:=1 to n do
begin
read(b[i]);
for j:=last to b[i] do add(root,a[j]);
inc(k);
dfs(root,k);
last:=b[i]+1;
end;
close(input);close(output);
end.