题目链接: http://codeforces.com/contest/863/problem/B
题目描述: 有n-1个双人独木舟, 2个单人独木舟, 规定单人独木的花费为0, 双人为两个人的绝对之差, 求最小花费
解题思路: 自己一开始忘了暴力了, 一直钻着去想怎么能达到最优解, 却没有注意数据范围, stupid!!!!!!!1
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <string> #include <algorithm> #include <vector> using namespace std; typedef long long ll; int w[130]; const int INF = 0x3fffffff; int main() { int n; scanf( "%d", &n ); n <<= 1; for( int i = 0; i < n; i++ ) { scanf("%d", w+i); } int ans = INF; for( int i = 0; i < n; i++ ) { for( int j = i+1; j < n; j++ ) { vector<int> v; for( int k = 0; k < n; k++ ) { if( i != k && j != k ) { v.push_back(w[k]); } } sort(v.begin(), v.end()); int temp = 0; for( int k = 1; k < int(v.size()); k+=2 ) { temp += abs(v[k]-v[k-1]); } ans = min( ans, temp ); } } printf( "%d ", ans ); return 0; }
思考: 题见得不够?自己再认真一点好不好