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
北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

看我的这个呢

Posted by xjh_hyz_lovers at 2019-03-14 13:15:24 on Problem 2718
In Reply To:贴份c++暴搜AC代码,要找到合适的搜索方式 Posted by:a280920481 at 2018-11-19 22:17:07
#include <cstdio>
#define s(n) scanf ("%d" ,&(n))
int qkpow(int b)
{
    int x = 10 ,ans = 1;
    while (b)
    {
        if (b % 2)
            ans *= x;
        x *= x;
        b >>= 1;
    }
    return ans;
}
int T ,a[15];
int main()
{
    s(T);
    while (T--)
    {
        int k = 0;
        while (scanf ("%d" ,&a[++k]) != EOF);
        k--;
        if (k % 2)
        {
            int t1 = 0 ,t2 = 0;
            if (!a[1])
            {
                int t = a[1];
                a[1] = a[2];
                a[2] = t;
            }
            int m = k / 2 ,cnt = k;
            while (m)
            {
                t2 += qkpow(m - 1) * a[cnt--];
                m--;
            }
            m = k / 2 + 1 ,cnt = 1;
            while (m)
            {
                t1 += qkpow(m - 1) * a[cnt++];
                m--;
            }
            printf ("%d\n" ,t1 - t2);
        }
        else
        {
            int t1 = 0 ,t2 = 0;
            if (!a[1])
            {
                int t = a[1];
                a[1] = a[2];
                a[2] = a[3];
                a[3] = t;
            }
            int m = k / 2;
            t1 += qkpow(m - 1) * a[1];
            t2 += qkpow(m - 1) * a[2];
            m--;
            int cnt = k;
            while (m)
            {
                t1 += qkpow(m - 1) * a[cnt--];
                m--;
            }
            cnt = 3;
            m = k / 2 - 1;
            while (m)
            {
                t2 += qkpow(m - 1) * a[cnt++];
                m--;
            }
            printf ("%d\n" ,t2 - t1);
        }
    }
    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