Hdu5429, math + high precision + equal-ratio sequence to judge __ Math

Source: Internet
Author: User

Meaning

Give n high precision numbers to determine whether the equal ratio sequence.

Range: 0<n<=100, each value is no more than 100 length.

Analysis:

According to the question, this problem must be solved with high precision, using the array simulation multiplication calculation process.

Determine whether the equal-ratio sequence method: a[i],a[i+1],a[i+2], for arbitrary I, have a[i]*a[i+2]=a[i+1]*a[i+1].

Therefore, a high-precision simulation of the multiplication calculation, to determine whether the adjacent three items are satisfied with the above relational formula.

Attention:

The number given in the ① topic may have a leading 0;

The ② ratio of the equal-ratio sequence is nonzero; but when the sequence is all zero, it is also the equal-ratio sequence.

such as: 0 0 0 0 is the equal-ratio sequence, because the ratio can be 1,2 ...,

And: 1 0 0 0 is not the equal ratio sequence, the male ratio is 0.

Notice the two things, the specific code is relatively simple, pay attention to the high-precision multiplication of the writing details.

Specific code:

#include <cstdio> #include <algorithm> #include <iostream> #include <vector> #include <
Cstring> #include <cmath> using namespace std;
typedef long Long LL;
int t,n;
Char s[110][110],str[110][110];
int res[300];
Char res[300]; String product (char A[],char b[]) {//cout<< "***************************" <<endl;//COUT&LT;&LT;A&LT;&L t; '
    ' <<b<<endl;
    int Len1=strlen (a);
    int Len2=strlen (b);
    memset (res,0,sizeof (res));
    memset (res,0,sizeof (Res));
            for (int i=0;i<len1;i++)//2 {for (int j=0;j<len2;j++)//1 {int c,d;
            c=a[i]-' 0 ';
            d=b[j]-' 0 ';
            Res[i+j]+=c*d;
            res[i+j+1]+= (RES[I+J]/10);
            res[i+j]%=10;
        printf ("%d%d%d%d\n", c,d,res[i+j],res[i+j+1]);
    for (int i=0;i<len1+len2-1;i++) res[i]=res[i]+ ' 0 ';
if (res[len1+len2-1]) res[len1+len2-1]=res[len1+len2-1]+ ' 0 '; Cout<<res<<endl;
return Res; BOOL Judge (string A,string B) {//cout<<a<< ' <<b<<endl;/cout<< '---------------
    -----------"<<endl;
    int len1=a.size ();
    int len2=b.size ();
    if (LEN1!=LEN2) return false;
    for (int i=0;i<len1;i++) {if (A[i]!=b[i]) return false;
return true;
    int main () {scanf ("%d", &t);
        while (t--) {scanf ("%d", &n);
        for (int i=0; i<n; i++) {scanf ("%s", Str[i]);
        int e=0;
            for (int i=0;i<n;i++) {int Len=strlen (str[i]);
            for (int j=len-1;j>=0;j--) {s[i][len-1-j]=str[i][j];
            while ((s[i][len-1]== ' 0 ') && (len>1)) {len-=1;
            } s[i][len]= ';
            if ((len==1) && (s[i][len-1]== ' 0 ')) {e++; }//Cout<<s[i]<<eNdl
            } if (e>0) {if (e<n) cout<< "No" <<endl;
            else cout<< "Yes" <<endl;
        Continue
        BOOL Flag=true;
String a,b;
        Char a[200],b[200]; for (int i=1;i<n-1;i++) {a=product (s[i-1],s[i+1]);//cout<< "a=" <<A<<
            Endl
B=product (S[i],s[i]);
            cout<< "b=" <<B<<endl;
            BOOL F=judge (A,B);
            if (!f) {flag=false;
        } if (flag) cout<< "Yes" <<endl;
    else cout<< "No" <<endl;
return 0;

 }/* 10 1 0 3 1 1 1 3 1 4 2 5 16 8 4 2/1 * *


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.