CSUOJ 1165 Enumeration

Source: Internet
Author: User

Question

In fact, this question is not intended to be written. I read the question at night and found that it is the same as the code of me at that time.

Later I found out that I initialized the minimum value ans:

long long ans=(long long)1<<60;int index=0;

The minimum value is not large enough, so the number multiplication is greater than the minimum value. As a result, the index is not updated, and the index is 0. In my three if values, it slipped through... sorry...

This leads to an endless loop... too boring ....

Question:

There are three rows of numbers, one in each row, and the difference is squared. Minimum. You can define Policy Enumeration for this question.

#include<iostream>#include<cstdio>#include<algorithm>template<class T> void inline checkmin( T &a,T b ){ if( a>b||a==-1 ) a=b; }using namespace std;typedef long long ll;int a[1<<20],b[1<<20],c[1<<20];inline ll getans( ll a,ll b,ll c ){   return (a-b)*(a-b)+(a-c)*(a-c)+(b-c)*(b-c);}inline ll min(ll x, ll y){    return x<y?x:y;}int main(){    int na,nb,nc;    while( scanf("%d%d%d",&na,&nb,&nc)!=EOF )    {           for( int i=0;i<na;i++ )                scanf( "%d",&a[i] );           for( int i=0;i<nb;i++ )                scanf( "%d",&b[i] );           for( int i=0;i<nc;i++ )                scanf( "%d",&c[i] );                           ll mind=((ll)1<<63)-1;           int s1=0,s2=0,s3=0;           ll aa,bb,cc;           while( s1<na&&s2<nb&&s3<nc )           {                  checkmin( mind,getans(a[s1],b[s2],c[s3]) );                  ll k=(1ll<<63)-1;int index=0;                  aa=getans(a[s1+1],b[s2],c[s3]);                  bb=getans(a[s1],b[s2+1],c[s3]);                  cc=getans(a[s1],b[s2],c[s3+1]);                  /*  if( aa<bb && aa<cc )s1++;                  else if( bb<cc ) s2++;                  else s3++;                  */                  if( k>aa ) index=1,k=aa;                  if( k>bb ) index=2,k=bb;                  if( k>cc ) index=3,k=cc;                  if( index==1 ) s1++;                  else if( index==2 ) s2++;                  else s3++;           }           printf( "%lld\n",mind );    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.