acgo题库
  • 首页
  • 题库
  • 学习
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情提交记录(0)
  • 开荒

    userId_undefined

    The Third Reich

    秩序白银时间刺客时空双修者空间掌握者
    59阅读
    0回复
    1点赞
  • 题解

    userId_undefined

    WA君

    倔强青铜空间掌握者时空双修者时间刺客枚举·枚举小能手递归·套娃学徒
    17阅读
    0回复
    1点赞
  • 解题

    #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N; cin>>N; vector<int>arr(N); for (int i=0;i<N;i) { cin>>arr[i]; } int count1=count(arr.begin(),arr.end(),1); int count2=count(arr.begin(),arr.end(),2); int count3=count(arr.begin(),arr.end(),3); int a=0,b=0; // 区域1中的2和3的数量 for(int i=0;i<count1;i) { if(arr[i]==2)a; else if(arr[i]==3)b; } int c=0,d=0; // 区域2中的1和3的数量 for(int i=count1;i<count1+count2;i) { if (arr[i]==1)c; else if (arr[i]==3)d++; } int e=0,f=0; // 区域3中的1和2的数量 for (int i=count1+count2;i<N;i) { if (arr[i]==1)e; else if (arr[i]==2)f++; } int direct_swaps=min(a,c)+min(b,e)+min(d,f); int remaining=a-min(a,c); // 剩余的待处理错误 int total_swaps=direct_swaps+2*remaining; cout<<total_swaps<<endl; return 0; }

    userId_undefined

    REN

    5阅读
    0回复
    0点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页