• USACO Section 2.1 Sorting A ThreeValued Sequence


    好题,自己想没想出来,虽然大家都说是水题

     1 /* ID:linyvxi1
    2 PROB:sort3
    3 LANG:C++
    4 */
    5 #include <stdio.h>
    6 #include <algorithm>
    7 using namespace std;
    8 int start_pos[1005];
    9 int final_pos[1005];
    10 int corr_map[4][4]={0};
    11 int main()
    12 {
    13 freopen("sort3.in","r",stdin);
    14 freopen("sort3.out","w",stdout);
    15
    16 int n;
    17 int swap_num=0;
    18 scanf("%d",&n);
    19 int i;
    20 for(i=0;i<n;i++){
    21 scanf("%d",&start_pos[i]);
    22 final_pos[i]=start_pos[i];
    23 }
    24
    25 sort(final_pos,final_pos+n);
    26
    27 for(i=0;i<n;i++){
    28 if(final_pos[i]!=start_pos[i]){
    29 swap_num++;
    30 corr_map[final_pos[i]][start_pos[i]]++;
    31 }
    32 }
    33 int ans=0;
    34 int j;
    35 for(i=1;i<=3;i++){
    36 for(j=i+1;j<=3;j++){
    37 int t=min(corr_map[i][j],corr_map[j][i]);
    38 ans+=t;
    39 corr_map[i][j]-=t;
    40 corr_map[j][i]-=t;
    41 swap_num-=2*t;
    42 }
    43 }
    44 ans+=swap_num/3*2;
    45 printf("%d\n",ans);
    46 }



  • 相关阅读:
    添加yum源
    tar命令
    tomcat压力测试、优化
    vi命令
    Linux简单命令
    Linux简单命令
    vi命令
    tomcat压力测试、优化
    tar命令
    动态加载 CSS 文件
  • 原文地址:https://www.cnblogs.com/yangce/p/2357910.html
Copyright © 2020-2023  润新知