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.

Sample test(s)
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.

这道题真心不难,T T,没想全。。。没事,学到东西就好

我的想法

 #include <iostream>
#include <cstdio>
using namespace std;
///自己的想法那么复杂,好吧,想法其实也可以,当时没好好想完全
///n > m没问题,而 n < m 没考虑 T-T
int main()
{
int n, m;
while(cin >> n >> m)
{
int ans = ; do{
if(n >= m)
{
ans += m;
n = n - m + ;
}
else
{
ans = n;
n = ;
}
}while(n >= m);
ans += n;
cout << ans << endl;
}
return ;
}

参考,纯正模拟

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int main()
{
int n, m, i;
cin >> n >> m;
for(i = ; n > ; i++)
{
n--;
n += (i%m == ) ? : ;
}
//这种思想是完全模拟袜子的使用过程,应该就是这样的
i--;
cout << i << endl;
return ;
}

CF460 A. Vasya and Socks的更多相关文章

  1. 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 i ...

  2. A - Vasya and Socks

    A - Vasya and Socks Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  3. Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

    题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...

  4. X - Vasya and Socks

    Problem description Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pai ...

  5. codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子, ...

  6. codeforces 460A Vasya and Socks 解题报告

    题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...

  7. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

  8. codeforcess水题100道

    之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...

  9. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

随机推荐

  1. Caffe初试(一)win7_64bit+VS2013+Opencv2.4.10+CUDA6.5配置Caffe环境

    折腾了几天,终于在windows系统上成功配置了Caffe环境,期间遇到了很多问题,每个问题的解决也都花了不少时间,查过挺多资料,感觉挺有意义,这里写篇博客记录一下. 原来我使用的CUDA版本是7.5 ...

  2. python基础——继承和多态

    python基础——继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类 ...

  3. NYOJ题目806HEIHEI的心情

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtMAAANRCAIAAACumacBAAAgAElEQVR4nOzdrXLrOrjG8XMT5b2Q4l

  4. CLR via C#(03)- 对象创建和类型转换

    一. 创建对象 CLR要求用new操作符创建对象,这个操作符在编译时产生的IL指令为newobj.例如: Student XiaoJing=new Student(“XiaoJing”,”1986”) ...

  5. Oracle的thin驱动和oci驱动有什么不同?哪个性能好些?

    OCI:要安装ORACLE客户端,移植性略差,理论上性能好些 THIN:属于TYPE4,纯JAVA实现,移植性好,理论上性能略差些 推荐:最好还是使用THIN   DRIVER吧,移植性好些,使用起来 ...

  6. ASP.NET多线程下使用HttpContext.Current为null解决方案 2015-01-22 15:23 350人阅读 评论(0) 收藏

    问题一:多线程下获取文件绝对路径 当我们使用HttpContext.Current.Server.MapPath(strPath)获取绝对路径时HttpContext.Current为null,解决办 ...

  7. Oracle buffer cache

    Buffer Cache buffer cache 结构图 HASH链 ORACLE使用HASH算法,把buffer cache中每个buffer的buffer header串联起来,组成多条hash ...

  8. WPF中查看PDF文件

    需要打开PDF文件时,我们第一印象就是使用Adobe Reader.在开发中,经常会遇到需要展示PDF文件的需求.我们会借助于Adobe Reader的Active控件来实现.不过这需要客户的机器上安 ...

  9. MySQL数据库自带备份与恢复工具:MySQLdump.exe与mysql.exe

    数据库的备份工作是保护数据库正常运行的关键,以下的文章主要讲述的是MySQL数据库备份的一些小妙招,我们大家都知道使用MySQL dump备份数据库的用户所需要的权限相对而言还是比较小的,只需要sel ...

  10. sublime总结

    自定义快捷键: preferences->key binding->user ctrl+d 删除行 ctrl+k 选中下一同名变量,alt+F3 选中全部同名变量 [ {"key ...