zoukankan      html  css  js  c++  java
  • poj 2718 又超时了 跪了 到底咋优化呢????????????

    #include <stdio.h>
    #include <cmath>
    #include <cstring>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>

    using namespace std;
    int a[11];
    int testnum=0;
    int n = 0;
    int z1 = 999999999;


    void solve(){
    int x = 0, y = 0, z = 0;
    int middle = n/2;
    for (int i = 0; i < n; i++){
    if (i < middle){
    x += a[i]*pow(10.0, middle - i - 1);
    }
    else y += a[i]*pow(10.0, n - i - 1);
    }
    z = abs(x - y);
    if(z1>z)z1=z;
    }

    int main(){
    char ch;
    scanf("%d ",&testnum);
    for (int i = 0; i < testnum; i++){
    while ((ch = getchar()) != ' '){
    if (ch == ' ')continue;
    a[n] = ch - '0';
    n++;
    }
    do{
    if(a[0] == 0||a[n/2]== 0)continue;
    solve ();
    }while (next_permutation (a, a + n));
    cout << z1;
    }
    return 0;
    }

    ***************************

  • 相关阅读:
    linux防火墙iptables
    etc/fstab
    EDT改成CST
    echo
    dd
    chown
    CAT
    Linux grep
    CHECKSUM比较两表字段值差异
    通过GitHub部署项目到Nginx服务器
  • 原文地址:https://www.cnblogs.com/coolcold/p/4354602.html
Copyright © 2011-2022 走看看