poj2718 Smallest Difference
思路:
暴力乱搞。
实现:
#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的更多相关文章
- poj2718 Smallest Difference(dfs+特判,还可以贪心更快)
https://vjudge.net/problem/POJ-2718 其实不太理解为什么10超时了.. 这题似乎是有贪心优化的方法的,我下面直接暴力了.. 暴力之余要特判两个点:1.超时点就是n=1 ...
- (DFS、全排列)POJ-2718 Smallest Difference
题目地址 简要题意: 给若干组数字,每组数据是递增的在0--9之间的数,且每组数的个数不确定.对于每组数,输出由这些数组成的两个数的差的绝对值最小是多少(每个数出现且只出现一次). 思路分析: 对于n ...
- POJ-2718 Smallest Difference
http://poj.org/problem?id=2718 从一些数里面选择一个子集组成一个数,余下的数组成另外一个数,(数不能以0开头)问两个数的差的绝对值最小是多少! 不管是奇数还是偶数,要想绝 ...
- 【POJ - 2718】Smallest Difference(搜索 )
-->Smallest Difference 直接写中文了 Descriptions: 给定若干位十进制数,你可以通过选择一个非空子集并以某种顺序构建一个数.剩余元素可以用相同规则构建第二个数. ...
- LintCode "The Smallest Difference"
Binary search. class Solution { int _findClosest(vector<int> &A, int v) { , e = A.size() - ...
- Smallest Difference(POJ 2718)
Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6740 Accepted: 18 ...
- POJ 2718 Smallest Difference(最小差)
Smallest Difference(最小差) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given a numb ...
- The Smallest Difference
Given two array of integers(the first array is array A, the second array is arrayB), now we are goin ...
- Smallest Difference(暴力全排列)
Smallest Difference Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10387 Accepted: 2 ...
随机推荐
- HDU 1031.Design T-Shirt【结构体二次排序】【8月21】
Design T-Shirt Problem Description Soon after he decided to design a T-shirt for our Algorithm Board ...
- MaterialImageView
https://github.com/zhaozhentao/MaterialImageView
- 1 Angular 2 简介与 AngularJS 1.x 历史对比
Angular 2 是一款JavaScript的开源框架,用于协助单一页面应用程序运行.Angular 2 是 AngularJS 1.x 的升级版本,应Web的进化和前端开发的变革还有从Angula ...
- react-grid-layout
一个好用的拖拽.自适应布局 react 插件 基本使用: // 显示全部 chart 内容区域 import React,{PureComponent} from 'react'; import {R ...
- TCP Operational Overview and the TCP Finite State Machine (FSM) http://tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm
http://tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm http://tcpipgu ...
- 浅谈UML学习笔记之用例图
最近一直在学习UML的基础知识,再看完视频之后,并没有很好的总结,在画图的过程中发现了很多的问题,下面是看书的过程自己总结的UML用例图的一点知识,与大家分享一下. 一.概念 用例图是由参与者.用例以 ...
- Spring Security调研记录【七】--核心模型与实现
网上有非常多关于Spring Security文章中,都觉得Spring Security(相对于shiro)过于复杂,个人觉得复杂的是Spring Security的官方文档而不是Spring Se ...
- VA市场高烧已退,逐渐降温
本周市场国产VA报价在175元/公斤左右,较上周滑落.因前期停报的厂家均已报价,个别国产厂家报价较低,各厂家间报价价差较大,彰显不同态度.国内厂家供应依然偏紧,但较前期已缓解.中小饲料企业库存偏低,近 ...
- centos7下tomcat7 或tomcat8启动超慢原因
1,找到你的jdk安装的位置 ${JAVA_HOME}/jre/lib/security/java.security 2,vi 打开后找到 securerandom.source=file:/dev/ ...
- YTU 2892: I--免费看电影
2892: I--免费看电影 时间限制: 1 Sec 内存限制: 128 MB 提交: 30 解决: 12 题目描述 万象城星美影院开业1周年了,要举行为期一天的大酬宾,ACM队员准备去看电影.已 ...