zoukankan      html  css  js  c++  java
  • 水题Eating Soup

     A. Eating Soup
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
        The three friends, Kuro, Shiro, and Katie, met up again! It’s time for a party…
        What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now n cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.
        Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are m cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?Could you help her with this curiosity?You can see the examples and their descriptions with pictures in the “Note” section.
        Input
        The only line contains two integers n and m (2≤n≤1000, 0≤m≤n) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.
        Output
    Print a single integer — the maximum number of groups of cats at the moment Katie observes.
        Examples
        inputCopy
        7 4
        outputCopy
        3
        inputCopy
        6 2
        outputCopy
        2
        inputCopy
        3 0
        outputCopy
        1
        inputCopy
        2 2
        outputCopy
        0
        题意:题目的意思就是说,有n只猫,围在一起喝汤,喝完了就可以走m只,最后可以围成的多少组
        思路:当一只猫都没走的时候,还是一圈只有一个组;
                当剩下的猫大于走的猫的时候,这时候能围成m组;
                当剩下的猫小于走的猫的时候,这时候能围成n-m组;
                水题一道,哎,特此记录一下

     1 #include"iostream"
     2 #include"algorithm"
     3 #include"cstdio"
     4 #include"cstring"
     5 #include"string.h"
     6 using namespace std;
     7 int main(){
     8     int n,m;
     9     while(cin>>n>>m){
    10          if(m==0)
    11             cout<<"1"<<endl;
    12         else if(n-m>=m)
    13             cout<<m<<endl;
    14         else
    15             cout<<n-m<<endl;
    16         }
    17     return 0;
    18 } 
    19 //不要脸的贴个网上代码
    20 #include<bits/stdc++.h>
    21 using namespace std;
    22 int n,m;
    23 int main()
    24 {
    25     cin>>n>>m;
    26     cout<<min(n-m,max(1,m));
    27 }
  • 相关阅读:
    HDU2897( 巴什博奕变形)
    HTML小知识点积累
    几种自己主动运行js代码的方式
    leetcode笔记:Contains Duplicate
    【Nutch基础教程之七】Nutch的2种执行模式:local及deploy
    为什么使用模板
    前端编程提高之旅(十)----表单验证插件与cookie插件
    【HDOJ 5399】Too Simple
    进程间通信之-信号signal--linux内核剖析(九)
    iOS类的合理设计,面向对象思想
  • 原文地址:https://www.cnblogs.com/huangdf/p/12227134.html
Copyright © 2011-2022 走看看