poj2718 Smallest Difference
2024-08-30 18:27:27
思路:
暴力乱搞。
实现:
#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 ;
}
最新文章
- C++ Primer Plus 第六版笔记
- Access使用join进行多个表联合查询的问题
- 做贴吧系统,偶然发现使用iframe的弊端
- Thinking in java学习笔记之finalize
- android-ContentProvider
- oracle中if/else功能的实现的3种写法
- tomcat管理页面用户角色、用户名、用户密码的配置
- (转)VS2012网站发布详细步骤
- css media
- Scala学习文档-各种使用模式的情况
- js中set和get的用法
- 排序算法Java实现(直接插入排序)
- vscode断点调试工程化服务端文件
- idea基本使用1
- JDK中所包含的设计模式
- babel(一)
- 读取PBOC电子现金指令流
- 946. Validate Stack Sequences验证栈序列
- Modeless对话框如何响应快捷键
- Tomcat配置https、访问http自动跳转至https
热门文章
- OpenCV实践之路——Python的安装和使用
- autofac如何注册静态方法里的接口对象
- Library Project里面使用Case语句判断R.id值报错。case expressions must be constant expressions
- su: /bin/bash: Permission denied带来的疑惑
- 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
- 文件上传Apache
- windows系统下mysql5.5查看和设置数据库编码
- 【转】Vuex 学习总结
- less 语法
- hibernate映射文件set key one-to-many