思路:

暴力乱搞。

实现:

 #include <iostream>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std; const int INF = 0x3f3f3f3f; bool in[];
int t, n, num[];
string s;
stringstream ss;
int minn = INF; int main()
{
cin >> t;
getchar();
while (t--)
{
getline(cin, s);
ss.clear();
n = ;
minn = INF;
ss << s;
while (ss >> num[n++]);
n--;
if (n == )
{
cout << abs(num[] - num[]) << endl;
continue;
}
do
{
int x = , y = , z = ;
for (int i = ; i < n / ; i++)
{
x += num[i];
if (i != n / - )
x *= ;
}
for (int i = n / ; i < n; i++)
{
y += num[i];
if (i != n - )
y *= ;
if (i == n / )
continue;
z += num[i];
if (i != n - )
z *= ;
}
if (!(n > && num[] == || num[n / ] == ))
minn = min(minn, abs(x - y));
if (n & && !(num[] == || n > && num[n / + ] == ))
minn = min(minn, abs(x * + num[n / ] - z));
} while (next_permutation(num, num + n));
cout << minn << endl;
}
return ;
}

poj2718 Smallest Difference的更多相关文章

  1. poj2718 Smallest Difference(dfs+特判,还可以贪心更快)

    https://vjudge.net/problem/POJ-2718 其实不太理解为什么10超时了.. 这题似乎是有贪心优化的方法的,我下面直接暴力了.. 暴力之余要特判两个点:1.超时点就是n=1 ...

  2. (DFS、全排列)POJ-2718 Smallest Difference

    题目地址 简要题意: 给若干组数字,每组数据是递增的在0--9之间的数,且每组数的个数不确定.对于每组数,输出由这些数组成的两个数的差的绝对值最小是多少(每个数出现且只出现一次). 思路分析: 对于n ...

  3. POJ-2718 Smallest Difference

    http://poj.org/problem?id=2718 从一些数里面选择一个子集组成一个数,余下的数组成另外一个数,(数不能以0开头)问两个数的差的绝对值最小是多少! 不管是奇数还是偶数,要想绝 ...

  4. 【POJ - 2718】Smallest Difference(搜索 )

    -->Smallest Difference 直接写中文了 Descriptions: 给定若干位十进制数,你可以通过选择一个非空子集并以某种顺序构建一个数.剩余元素可以用相同规则构建第二个数. ...

  5. LintCode "The Smallest Difference"

    Binary search. class Solution { int _findClosest(vector<int> &A, int v) { , e = A.size() - ...

  6. Smallest Difference(POJ 2718)

    Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6740   Accepted: 18 ...

  7. POJ 2718 Smallest Difference(最小差)

     Smallest Difference(最小差) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given a numb ...

  8. The Smallest Difference

    Given two array of integers(the first array is array A, the second array is arrayB), now we are goin ...

  9. Smallest Difference(暴力全排列)

    Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10387   Accepted: 2 ...

随机推荐

  1. C#数据库连接池 MySql SqlServer

    查阅了一天的资料来学习MySql数据库连接池,终于在一篇博文上找到了,自己也整理了一下,希望对大家有用处 1. 建立连接池 using MySql.Data.MySqlClient; using Sy ...

  2. 竞赛中经常使用的C++写法

    首先是构造函数,重载 #include <iostream> #include <cstdio> #include <cstring> #include <s ...

  3. NS3网络仿真(12): ICMPv4协议

    快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 ICMP的全称是 Internet ControlMessage Protocol . 其目的就是 ...

  4. 我的kindle书单

    刚刚入手kindle,希望能够持续阅读,不断进步. 列下书单,记录我的阅读足迹,更希望园友若有好书多多推荐,互相交流. # keep updating ... 我的kindle书单 book name ...

  5. Delphi的函数指针

    不求全面,先留个爪: TNotifyEvent = procedure(Sender: TObject) of object; TMethod = record Code, Data: Pointer ...

  6. vue学习1

    1.<div id="app">{{message}}<input v-model="message"></div>new ...

  7. 设计模式-(8)外观(swift版)

    一,概念 为子系统中的一组接口提供一个统一的接口.外观模式定义了一个更高层次的接口,这个接口使得这一子系统更加容易使用. 二,结构图 (1)SubSystem子系统类:每个子系统定义了相关功能和模块的 ...

  8. js的location对象

    js的location对象 location基础知识 BOM(浏览器对象模型)中最有用的对象之一就是location,它是window对象和document对象的属性.location对象表示载入窗口 ...

  9. 【SCOI 2005】 互不侵犯

    [题目链接] 点击打开链接 [算法] 和HDU2167类似 先搜出一行内符合的状态,然后,f[i][j][k]表示第i行,第j种状态,放了k个,合法的方案,DP即可 [代码] #include< ...

  10. bzoj 5281 Talent Show —— 01分数规划+背包

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5281 二分一个答案比值,因为最后要*1000,不如先把 v[] *1000,就可以二分整数: ...