zoukankan      html  css  js  c++  java
  • Chips Moving ( Codeforces Round #582)

    You are given nn chips on a number line. The ii-th chip is placed at the integer coordinate xixi. Some chips can have equal coordinates.

    You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:

    • Move the chip ii by 22 to the left or 22 to the right for free (i.e. replace the current coordinate xixi with xi2xi−2 or with xi+2xi+2);
    • move the chip ii by 11 to the left or 11 to the right and pay one coin for this move (i.e. replace the current coordinate xixi with xi1xi−1 or with xi+1xi+1).

    Note that it's allowed to move chips to any integer coordinate, including negative and zero.

    Your task is to find the minimum total number of coins required to move all nn chips to the same coordinate (i.e. all xixi should be equal after some sequence of moves).

    Input

    The first line of the input contains one integer nn (1n1001≤n≤100) — the number of chips.

    The second line of the input contains nn integers x1,x2,,xnx1,x2,…,xn (1xi1091≤xi≤109), where xixi is the coordinate of the ii-th chip.

    Output

    Print one integer — the minimum total number of coins required to move all nn chips to the same coordinate.

    Examples
    input
    Copy
    3
    1 2 3
    
    output
    Copy
    1
    
    input
    Copy
    5
    2 2 2 3 3
    
    output
    Copy
    2
    
    Note

    In the first example you need to move the first chip by 22 to the right and the second chip by 11 to the right or move the third chip by 22 to the left and the second chip by 11 to the left so the answer is 11.

    In the second example you need to move two chips with coordinate 33 by 11 to the left so the answer is 22.


    题解:将所有点移动到同一点,问最小得花费是多少


    int main()
    {
        int n,k,ans=0,cnt=0;
        cin>>n;
        rep(1,n)
        {
            cin>>k;
            if(k&1) ans++;
        }
        cout<<min(ans,n-ans)<<endl;
        ok;
    } 

     

    所遇皆星河
  • 相关阅读:
    bootstrap 按钮 文本 浮动 隐藏
    bootstrap 表单控件 控件状态 控件大小 help-block
    wps 操作
    SSH中的免password登录
    Qt音乐播放器制作(二)Easy Player
    云计算资源分享与下载
    uva11059(最大乘积)
    两小时搞定C#版超级战舰游戏
    数据库中的參照完整性(Foreign Key)
    动手解决困扰自己的事情——记屏蔽网页广告
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11447070.html
Copyright © 2011-2022 走看看