Codeforces Round #262 (Div. 2) A. Vasya and Socks【暴力/模拟/袜子在可以在合法情况下增加后用几天】

A. Vasya and Socks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

Input

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.

Output

Print a single integer — the answer to the problem.

Examples
input
2 2
output
3
input
9 3
output
13
Note

In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.

In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.

 

【代码】:

#include <bits/stdc++.h>

using namespace std;
int sum;
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=n,j=1;i>=1;i--,j++)//i:袜子个数 
        {
            if(j%m==0)
                i++;
            sum++;
        }
        cout<<sum<<endl;
    }
    return 0;
}
双指针

 

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int day=1;
        int k=0;
        while(n--)//袜子消耗
        {
            if(day%m==0)
            {
                n++;//当是m的倍数的时候再购进一双袜子
            }
            day++;//不管有没有袜子穿日子总要过下去
            k++;//维持的日子
        }
        printf("%d\n",k);
    }
    return 0;
}
多变量记录

 

全部评论

相关推荐

11-28 16:00
已编辑
武汉理工大学 Java
Tom哥981:这份简历是“短期项目硬堆中大型系统技术”的“技术炫技式造假模板”,槽点密集到能当反面教材: ### 1. 「项目时长」和「技术密度」严重脱节,造假痕迹焊死在简历上 两个项目时长分别是**3个月、2个月**,但堆了Spring AI、Elasticsearch、MinIO、Kafka、ShardingSphere、Docker、Sentinel等近20个中大型项目才用的技术——正常情况下,光把这些中间件的文档看完+环境搭好,3个月都不够,更别说实现“AI多轮对话、分库分表、RBAC权限、大模型调用”这些功能。 说白了:你这不是“做项目”,是把“后端技术栈清单”往项目里硬塞,明摆着“只调用了API,没碰过核心逻辑”。
点赞 评论 收藏
分享
12-08 07:42
门头沟学院 Java
27届末九,由于是女生,身边人几乎没有就业导向的,自学只能跟着网课,没人指导,很迷茫。下图是我目前的简历,不知道有需要修改的地方吗?求拷打。下面是目前的学习情况:目前算法过完了一遍力扣100和代码随想录,不过不是很熟,面经看了小林coding、JavaGuide,有一些没用过的技术看得不是很明白,掌握得不是很扎实。再加上常年跟黑马网课听思路,真正自己动手写代码的时间很少,这让我一直不敢投简历,总觉得内里空虚。项目没准备好面试相关的问题,简历上相应的考点不熟。如此种种。。。看到很多很多学长学姐大佬们的面经,愈发觉得面试可怕,自己没准备好,总担心自己是不是无望后端开发了。看到牛客很多同届以及更小一届的同学都找到实习了,很希望自己也能找到实习。而自己又好像摸不到后端学习的门路,只能不断赞叹黑马虎哥写的代码真优雅!微服务架构实在巧妙!消息队列、redis、sentinel、nacos、mybatisplus等等的引入都会让我赞叹这些工具的设计者的巧思,以及包括但不限于Java语言的优雅。然而只是停留在了解的程度,并不熟练。我是很希望能够继续深入探索这些知识的,只不过有一大部分时间都花在学校课程上了。我感觉我被困住了,我一方面必须保证我能够有个不错的学业分使我能有我几乎不想选择的读研退路(还有个原因是复习不全我会焦虑考试挂科,因此我会做好全面的准备,而这一步很费时间),一方面在B站学习各种网课,一方面得考虑提升自己并不扎实的算法基础,另一方面还得准备八股面经。这让我有点苦恼,我好像没那么多时间,因为绝大部分时间都花在了复习学校科目中了。我好像处处用时间,但收效甚微。想问问各位大佬是怎么平衡时间的呢?算法、项目和八股是怎么准备的呢?有什么高效的方法吗?谢谢您们花时间阅读我的稿件!
菜菜狗🐶:大胆投,我当时也是害怕面试,投多了发现根本约不到面🤡
投递哔哩哔哩等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务