Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:pku3214总是wa.那位大牛能给我程序?谢谢!

Posted by smcdfeng at 2007-12-11 21:46:41 on Problem 3214
In Reply To:pku3214总是wa.那位大牛能给我程序?谢谢! Posted by:wubin_s1 at 2007-04-03 22:14:29
> 以下是我的程序:
> #include<cstdio>
> #define maxn 1048600
> #define none 2000000000
> 
> int D[maxn],V[maxn],N,upd,ans=0,nn=0;
> void solve(int);
> int find(int);
> int main(){
> 
>   scanf("%d",&N); 
>   int i,k,r; nn=1;
>   for (i=1;i<=N;i++) nn*=2;
>   N=0; --nn;
>   while (1){
> 	if (scanf("%d",&r)==EOF) break;
> 	if (N+1>nn) break;
> 	D[++N]=r;
>   }
>   nn=0; upd=0; solve(1); D[0]=-none;
>   for (i=1;i<=N+1;i++) D[i]=none;
>   for (i=1;i<=N;i++){
> 	k=find(V[i]);
> 	D[k]=V[i];
> 	if (k>ans) ans=k;
>   }
>   printf("%d\n",N-ans);
> }
> void solve(int r){
>   if (r>N) return;
>   solve(r*2);
>   solve(r*2+1);
>   V[++nn]=D[r]-upd;
>   if (r%2==0) ++upd;
> }
> int find(int p){
>   int l=0,m=N+1,r=(l+m)/2,x=N*2;
>   while (l<=m){
> 	if (D[r]<=p) l=r+1; else { if (r<x) x=r; m=r-1; }
> 	r=(l+m)/2;
>   }
>   return x;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator