首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > C/C++ > My solution for SRM 306 DIV2 [250]
【标  题】:My solution for SRM 306 DIV2 [250]
【关键字】:My,solution,for,SRM,306,DIV2,250
【来  源】:http://blog.csdn.net/Gooler/archive/2006/06/09/781944.aspx

My solution for SRM 306 DIV2 [250]

Problem Statement: http://www.topcoder.com/stat?c=problem_statement&pm=6413&rd=9986

My solution:

#include <iostream>
#include <vector>

using namespace std;

class SortMachine  {
 
public:
  SortMachine () {}
 
public:
  int countMoves(vector <int> a) {
    int countMove = 0;

    while(1) {
      int move = -1;
      int minInversion = 1001;
     
      for (unsigned int i = 0; i < a.size() - 1; ++i) {
        for (unsigned int j = i + 1; j < a.size(); ++j) {
          if (a[i] > a[j] && a[i] < minInversion) {
            move = i;
            minInversion = a[i];
            break;
          }
        }
      }
     
      if (move == -1) {
        break;
      }
     
      int temp = a[move];     
      for (unsigned int i = move; i < a.size() - 1; ++i) {
        a[i] = a[i + 1];
      }
      a[a.size() - 1] = temp;

      ++countMove;
    }
   
    return countMove;
  }
};

小心C++编译器给我们带来的麻烦:【上一篇】
primer学习笔记2 const:【下一篇】
【相关文章】
  • C For Dummies(2nd Edition) [Part 1] Introduction to C Programming [Chapter 1] - Up from the Primordi...
  • C For Dummies(2nd Edition) [Part 1] [Chapter 2] - C of Sorrow, C of Woe
  • C For Dummies(2nd Edition) [Part 1] [Chapter 3]: C Straight
  • C For Dummies(2nd Edition) [Part 1] [Chapter 4]: C What I/O
  • C For Dummies(2nd Edition) [Part 1] [Chapter 5]: To C or Not to C
  • C For Dummies(2nd Edition) [Part 1] [Chapter 6]: C More I/O with gets()and puts()
  • C For Dummies(2nd Edition) [Part II]: Run and Scream from Variables and Math [Chapter 7]: A + B = C
  • C For Dummies(2nd Edition) [Part 2] [Chapter 8]Charting Unknown Cs with Variables
  • C For Dummies(2nd Edition) [Part 2] [Chapter 9]: How to C Numbers
  • 用.NET Framework 2.0创建 Form设计器[翻译]
  • 【随机文章】
  • 例子1
  • 『VC++技术内幕』学习笔记(1)
  • 网址URL的调整
  • 手机WAP使用攻略及答疑(2)
  • 利用SQL语句计算库存
  • DSL规模应用的宽带测试解决方案
  • 回复“请教一条SQL语句”
  • 2.1派生对话框类(Subclassing QDialog)
  • 摆脱光网络配置瓶颈
  • 隐藏默认按钮黑线框的小技巧
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.