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:同问求x的算法~

Posted by zjut020 at 2008-12-18 16:55:52 on Problem 1723
In Reply To:Re:同问求x的算法~ Posted by:wpc0000 at 2006-12-30 11:03:55
> x: 要将所有的x1集中到某个x0。其他xi依次相间1排下去。
> 先将x排序,可以证明x的顺序一定就是最终的序列的顺序(因为交叉位置的话解更差)。
> 由于定了序,所以有xi = x0 + i - 1,则可以将问题转化为x'i = xi - (i - 1) = x0。
> x'就是与y同样的问题了,求xi - (i - 1)的中位数x0就可以了。
thx...一开始以为自己想的是对的..你这思路很好..

帖个刚ac代码:
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int absd(int n)
{
    if(n>=0)
    return n;
    return -n;    
}
int main()
{
   // ifstream cin("0.txt");
          int n,i,aa[10000],bb[10000];
          cin>>n;
          for(i=0;i<n;i++)
          cin>>aa[i]>>bb[i];
          sort(aa,aa+n);
          sort(bb,bb+n);
          for(i=0;i<n;i++)
          aa[i]-=i;
          sort(aa,aa+n);
          unsigned long long sum=0;
          for(i=0;i<n/2;i++)
             sum+=bb[n-1-i]-bb[i]+aa[n-1-i]-aa[i];       
          cout<<sum<<endl;
  //  system("pause");
    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