7#include8#include9#include10#include11#include12#include13#include14#include

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

USACO Section 2.1: Prob Sorting A Three-Valu

系統 2216 0

貪心,先是交換倆倆交換后就可以的,接著交換3個輪回的,每個3個輪回的要交換2次

      
         1
      
      
        /*
      
      
         2
      
      
        ID: yingzho1


      
      
         3
      
      
        LANG: C++


      
      
         4
      
      
        TASK: sort3


      
      
         5
      
      
        */
      
      
         6
      
       #include <iostream>


      
         7
      
       #include <fstream>


      
         8
      
       #include <
      
        string
      
      >


      
         9
      
       #include <map>


      
        10
      
       #include <vector>


      
        11
      
       #include <
      
        set
      
      >


      
        12
      
       #include <algorithm>


      
        13
      
       #include <stdio.h>


      
        14
      
       #include <queue>


      
        15
      
       #include <cstring>


      
        16
      
      
        17
      
      
        using
      
      
        namespace
      
      
         std;


      
      
        18
      
      
        19
      
       ifstream fin(
      
        "
      
      
        sort3.in
      
      
        "
      
      
        );


      
      
        20
      
       ofstream fout(
      
        "
      
      
        sort3.out
      
      
        "
      
      
        );


      
      
        21
      
      
        22
      
      
        int
      
      
         N;


      
      
        23
      
      
        24
      
      
        int
      
      
         main()


      
      
        25
      
      
        {


      
      
        26
      
           fin >>
      
         N;


      
      
        27
      
           vector<
      
        int
      
      >
      
         f(N), g(N);


      
      
        28
      
      
        for
      
       (
      
        int
      
       i = 
      
        0
      
      ; i < N; i++) fin >>
      
         f[i];


      
      
        29
      
           g =
      
         f;


      
      
        30
      
      
            sort(g.begin(), g.end());


      
      
        31
      
      
        int
      
       acount = 
      
        0
      
      
        ;


      
      
        32
      
      
        for
      
       (
      
        int
      
       i = 
      
        0
      
      ; i < N-
      
        1
      
      ; i++
      
        ) {


      
      
        33
      
      
        for
      
       (
      
        int
      
       j = i+
      
        1
      
      ; j < N; j++
      
        ) {


      
      
        34
      
      
        if
      
       (f[j] != g[j] && f[i] == g[j] && f[j] ==
      
         g[i]) {


      
      
        35
      
      
                        swap(f[i], f[j]);


      
      
        36
      
                       acount++
      
        ;


      
      
        37
      
      
                    }


      
      
        38
      
      
                }


      
      
        39
      
      
            }


      
      
        40
      
      
        int
      
       count2 = 
      
        0
      
      
        ;


      
      
        41
      
      
        for
      
       (
      
        int
      
       i = 
      
        0
      
      ; i < N; i++
      
        ) {


      
      
        42
      
      
        if
      
       (f[i] != g[i]) count2++
      
        ;


      
      
        43
      
      
            }


      
      
        44
      
           fout << acount + count2/
      
        3
      
      *
      
        2
      
       <<
      
         endl;


      
      
        45
      
      
        46
      
      
        return
      
      
        0
      
      
        ;


      
      
        47
      
       }
    

?

USACO Section 2.1: Prob Sorting A Three-Valued Sequence


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 高平市| 隆回县| 吉水县| 汪清县| 宝鸡市| 赞皇县| 图们市| 那曲县| 田东县| 启东市| 天峻县| 岫岩| 汉川市| 隆化县| 剑川县| 辽阳市| 华亭县| 浦北县| 买车| 淅川县| 繁昌县| 安顺市| 南京市| 阿拉善右旗| 黄陵县| 和顺县| 木兰县| 益阳市| 自贡市| 宁强县| 永德县| 共和县| 娱乐| 西畴县| 伽师县| 大邑县| 永定县| 开鲁县| 稷山县| 增城市| 读书|