zoukankan      html  css  js  c++  java
  • cf 581A— Vasya the Hipster

    题目:

    One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

    According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.

    Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.

    Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

    Can you help him?

    Input

    The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got.

    Output

    Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

    Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day。

    Sample Input

    Input
    3 1
    Output
    1 1
    Input
    2 3
    Output
    2 0
    Input
    7 3
    Output
    3 2
    题目大意: 给你一定数目的两种颜色的袜子(红色和蓝色)书n和m;让你将不同颜色的袜子配对输出这个数,然后将同色的袜子看能凑几双,输出这个数。
    解析: 水。。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,m;
     8     cin>>n>>m;
     9     int day=0,day1=0;
    10     int sum=n+m;
    11     if(sum%2==0)
    12     {
    13         if(n<m)
    14         {
    15             day=day+n;
    16             day1+=(m-n)/2;
    17         }
    18         else
    19         {
    20             day+=m;
    21             day1+=(n-m)/2;
    22         }
    23     }
    24     else
    25     {
    26         if(n<m)
    27         {
    28             day=day+n;
    29             day1+=(m-n-1)/2;
    30         }
    31         else
    32         {
    33             day+=m;
    34             day1+=(n-m-1)/2;
    35         }
    36     }
    37     printf("%d %d
    ",day,day1);
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    让DIV实现抖动效果!
    Linux下如果python2和python3同时存在使用pip3
    Eclipse 查找一个接口的具体实现
    linux下编译安装软件到指定目录
    NG机器学习-octave基本操作
    NG机器学习
    全注解方式构建SpringMVC项目
    Java多线程学习开发笔记
    RabbitMQ 学习开发笔记
    Redis 学习开发笔记
  • 原文地址:https://www.cnblogs.com/forwin/p/4855130.html
Copyright © 2011-2022 走看看