CF460 A. Vasya and Socks
1 second
256 megabytes
standard input
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?
The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.
Print a single integer — the answer to the problem.
2 2
3
9 3
13
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的更多相关文章
- 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 ...
- A - Vasya and Socks
A - Vasya and Socks Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- 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 ...
- 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 ...
- 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双袜子, ...
- codeforces 460A Vasya and Socks 解题报告
题目链接:http://codeforces.com/problemset/problem/460/A 题目意思:有一个人有 n 对袜子,每天早上会穿一对,然后当天的晚上就会扔掉,不过他会在 m 的倍 ...
- Codeforces Round #262 (Div. 2) A B C
题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...
- codeforcess水题100道
之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...
- Codeforces Round #262 (Div. 2)解题报告
详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks http ...
随机推荐
- linux vi 中按了ctrl+s后没法退出
linux vi 中按了ctrl+s后无法退出 Linux 中使用vi编辑文件 不小心按了Ctrl + S (习惯了) 结果终端就跟死了一样, 解决办法: Ctrl+Q
- hdu1071(抛物线弓形面积阿基米德算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1071 题意:给出抛物线的顶点和它与一直线的两交点,求他们围成的面积: 思路: 可以直接求出他们的方程式 ...
- 数据结构和算法 – 9.二叉树和二叉查找树
9.1.树的定义 9.2.二叉树 人们把每个节点最多拥有不超过两个子节点的树定义为二叉树.由于限制子节点的数量为 2,人们可以为插入数据.删除数据.以及在二叉树中查找数据编写有效的程序了. 在 ...
- linux中who命令显示的tty、pts和(:0)(:0.0)是什么意思
http://blog.csdn.net/cwj_beyond/article/details/6987345 http://unix.stackexchange.com/questions/7217 ...
- Delphi ini文件读写
参考:http://www.cnblogs.com/zhangzhifeng/archive/2011/12/01/2270267.html 一.ini文件的结构 ;这是关于 ini 文件的注释 [节 ...
- 突破python缺陷,实现几种自定义线程池 以及进程、线程、协程的介绍
Python线程 Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元. #!/usr/bin/env python # -*- coding:utf-8 -*- import t ...
- 简简单单的一个PYTHON多进程实现
因为在作自动化部署时,希望能将多个服务分不同的批次进行发布, 同一批次的机器同时发布, 如果前面一批次出错误,后面就需要停止整 个流程. 那可以简单的用threading来实现了. thread_li ...
- 【openGL】画直线
#include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...
- foreach与Iterable学习
以前对于foreach的使用都是自然而然的感觉,没有深究过为什么可以用,什么时候可以用.最近才发现,原来那些可以使用的类,都是实现了Iterable接口的,否则根本就不能用. 下面是我之前学习时候写的 ...
- Linux 下编译自己的 OpenJDK7 包括JVM和JDK API
1.首先去 这里 http://download.java.net/openjdk/jdk7/ 下载OpenJDK7的源码zip包 2. 简要介绍下OpenJDK7中的目录 hotspot: 放有Op ...