(挑战编程_4_3)Bridge
来源:互联网 发布:mac系统升级10.10下载 编辑:程序博客网 时间:2024/05/31 04:03
http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110403&format=html
#include <iostream>#include <cstdlib>#include <vector>#include <set>#include <string>#include <fstream>#include <algorithm>#include <sstream>#include <string.h>#include <cassert>using namespace std;//#define _MY_DEBUG_/*排序,从小到大*/// 数组int arr[1100];/*MainStructure: 主结构*/void MainStructure();/*Process:处理每一组数据*/void Process();/*处理每一组数据,传入数据个数*/void Handle(int num);int main(){MainStructure();return 0;}void MainStructure(){#ifdef _MY_DEBUG_string inputStr = "C:/Users/cao/Desktop/算法/要看的书/算法/2挑战编程/input/1.inp";//string inputStr = "D:/2挑战编程/input/110205.inp";string outputStr = "C:/Users/cao/Desktop/算法/要看的书/算法/2挑战编程/input/0000001.outp";ifstream fin;fin.open(inputStr);cin.rdbuf(fin.rdbuf());//ofstream fout;//fout.open(outputStr);//cout.rdbuf(fout.rdbuf());#endifProcess();}void Process(){int count = 0;cin >> count;while (count--){int num = 0;cin >> num;for (int i = 0; i < num; ++i){cin >> arr[i];}// 分别处理每一组数据Handle(num);if (count){cout << endl;}}}void Handle(int num){// 1.排序sort(arr, arr + num);// 左右指针,左闭右开int left = 0;int right = num;int total = 0;string ansStr;stringstream ss(ansStr);int num1 = 0;int num2 = 0;if (num > 0){num1 = arr[left++];}if (num > 1){num2 = arr[left++];}int sumMin = num2 * 2 + num1;while (num > 3){int maxNum1 = arr[--right];int maxNum2 = arr[--right];int sum1 = sumMin + maxNum1;int sum2 = maxNum1 + num1 + maxNum2 + num1;if (sum1 <= sum2){ss << num1 << ' ' << num2 << '\n';ss << num1 << '\n';ss << maxNum2 << ' ' << maxNum1 << '\n';ss << num2 << '\n';total += sum1;}else{ss << num1 << ' ' << maxNum1 << '\n';ss << num1 << '\n';ss << num1 << ' ' << maxNum2 << '\n';ss << num1 << '\n';total += sum2;}num -= 2;}if (num == 3){int maxNum1 = arr[--right];ss << num1 << ' ' << maxNum1 << '\n';ss << num1 << '\n';ss << num1 << ' ' << num2 << '\n';total += (maxNum1);total += (num2 + num1);}else if (num == 2){ss << num1 << ' ' << num2 << '\n';total += (num2);}else if (num == 1){ss << num1 << '\n';total += num1;}/*if (num == 0){total = 0;ss << "";}*/cout << total << endl;cout << ss.str();}
- (挑战编程_4_3)Bridge
- (挑战编程_2_2)
- 编程挑战(一)
- (挑战编程_1_2)Minesweeper
- (挑战编程_1_6)Interpreter
- (挑战编程_2_3)Hartals
- (挑战编程_3_1)WERTYU
- (挑战编程_4_6)CDVII
- (挑战编程_5_4)Ones
- (挑战编程_6_3)Counting
- (挑战编程_8_3)Queue
- (挑战编程_9_1)Bicoloring
- 魔法(csdn编程挑战)
- 泥塑课(编程挑战)
- 挑战编程
- 编程挑战
- 编程挑战
- (挑战编程_1_3)The Trip
- PHP 发送Http Header 404及301\302重定向
- RegOpenKeyEx在64位与32位系统编程注意事项
- HyperWorks 集成桌面环境下二次开发【四】----脚本实例
- J2EE中的13种技术规范
- php header跳转及函数详细说明
- (挑战编程_4_3)Bridge
- php 五大运行模式 CGI FAST-CGI CLI ISAPI APACHE模式
- 如何在IE下使用Firebug
- Serial Programming Guide for POSIX Operating Systems
- 使用DELETE ADJACENT DUPLICATE FORM特别注意啦
- java中的native关键字
- S5PV210的LED应用(二)
- (挑战编程_4_4)Longest Nap
- linux 基本文件操作命令