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

鸽巢原理。

Posted by yygy at 2014-07-22 10:26:16
In Reply To:2796_Feel good 。一直wa,拿可以ac的程序对拍了好久,昨天搞到现在了。大神们帮帮忙,看看,为什么一直老哇? Posted by:GDUT_LV at 2014-07-22 10:25:42
> #include <iostream>
> #include <cstdio>
> #include <algorithm>
> #include <cstring>
> #define maxn 100100
> using namespace std;
> typedef long long ll;
> ll l,r,a[maxn]={0},t[maxn]={0};
> 
> typedef struct
> {
> 	ll res;
> 	ll l;
> 	ll r;
> } cao;
> cao ans;
> ll sum[maxn]={0};
> cao fenzi(ll left,ll right)
> {
>   if(right-left==1)
>   {
>   	cao gan={a[left]*a[left],left,left};
>   	return gan;
>   }
>   ll m=(left+right)/2;
>   cao maxl=fenzi(left,m);
>   cao maxr=fenzi(m,right);
>   cao maxf;
>   if(maxl.res>maxr.res)
> 	memcpy(&maxf,&maxl,sizeof(cao));
>   else
> 	memcpy(&maxf,&maxr,sizeof(cao));
>   ll v=0,s=0;
>   ll p=m-1,q=m,l=m-1,r=m;
>   v=a[l]+a[r];
>   s=v*(a[l]<a[r]?a[l]:a[r]);
>   for(ll i=1;p-i>=left||q+i<right;i++)
>   {
>     if(p-i>=left)
> 	{
> 	  v=sum[r]-sum[p-i-1];
> 	  sort(t+p-i,t+r+1);
> 	  if(v*t[p-i]>s)
> 	  {
> 	  	s=v*t[p-i];
>         l=p-i;
> 	  }
> 	  memcpy(t+p-i,a+p-i,sizeof(ll)*(r-p+i+1));
> 	}
>     if(q+i<right)
> 	{
> 	  v=sum[q+i]-sum[l-1];
> 	  sort(t+l,t+q+i+1);
>       if(v*t[l]>s)
> 	  {
> 	  	r=q+i;
> 	  	s=v*t[l];
> 	  }
> 	  memcpy(t+l,a+l,sizeof(ll)*(q+i-l+1));
> 	}
>   }
>   cao nimei={s,l,r};
>   if(nimei.res>maxf.res)
> 	return nimei ;
>   else
> 	return maxf;
> }
> int main()
> {
>     ll n;
>    while( scanf("%lld",&n)!=EOF)
> {
> 
>     for(int i=1;i<=n;i++)
> 	scanf("%lld",a+i),sum[i]=a[i]+sum[i-1];
>     memcpy(t+1,a+1,sizeof(ll)*n);
>     ans=fenzi(1,n+1);
>     printf("%lld\n",ans.res);
>     printf("%lld %lld\n",ans.l,ans.r);
> }
>     return 0;
> }

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