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;}