思路:

暴力乱搞。

实现:

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

最新文章

  1. C++ Primer Plus 第六版笔记
  2. Access使用join进行多个表联合查询的问题
  3. 做贴吧系统,偶然发现使用iframe的弊端
  4. Thinking in java学习笔记之finalize
  5. android-ContentProvider
  6. oracle中if/else功能的实现的3种写法
  7. tomcat管理页面用户角色、用户名、用户密码的配置
  8. (转)VS2012网站发布详细步骤
  9. css media
  10. Scala学习文档-各种使用模式的情况
  11. js中set和get的用法
  12. 排序算法Java实现(直接插入排序)
  13. vscode断点调试工程化服务端文件
  14. idea基本使用1
  15. JDK中所包含的设计模式
  16. babel(一)
  17. 读取PBOC电子现金指令流
  18. 946. Validate Stack Sequences验证栈序列
  19. Modeless对话框如何响应快捷键
  20. Tomcat配置https、访问http自动跳转至https

热门文章

  1. OpenCV实践之路——Python的安装和使用
  2. autofac如何注册静态方法里的接口对象
  3. Library Project里面使用Case语句判断R.id值报错。case expressions must be constant expressions
  4. su: /bin/bash: Permission denied带来的疑惑
  5. Unable to resolve dependency for &#39;:app@debug/compileClasspath&#39;: Could not resolve com.android.support.constraint:constraint-layout:1.1.0. Could not resolve com.android.support.constraint:constraint-l
  6. 文件上传Apache
  7. windows系统下mysql5.5查看和设置数据库编码
  8. 【转】Vuex 学习总结
  9. less 语法
  10. hibernate映射文件set key one-to-many