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 ...
随机推荐
- grep如何忽略.svn目录,以及如何忽略多个目录
grep如何忽略.svn目录,以及如何忽略多个目录 这是我在网上看到的文章,不过里面还有问题,我的不支持,需要更换架包 grep -r 'function_name' * (*表示当前目录下所有文件, ...
- Swift - 状态栏颜色显示(字体、背景)
ios上状态栏 就是指的最上面的20像素高的部分 状态栏分前后两部分,要分清这两个概念,后面会用到: 前景部分:就是指的显示电池.时间等部分: 背景部分:就是显示黑色或者图片的背景部分: 如下图:前景 ...
- 聊聊Android的APK反编译
上一篇<How To Use Proguard in Android APP>介绍了如何对Android进行混淆,现在来对它进行反编译看看,里面有些什么东西. APK文件,其实也是一个压缩 ...
- Shell编程基础教程4--控制流结构
4.控制流结构 4.1.控制结构 4.2.if then else语句 格式: if 条件1 //如果条件1为真 then 命令1 //那么,执行命令1 el ...
- My97DatePicker使用技巧
My97DatePicker使用是很常用的控件,总结一下常用使用技巧: 1.onpicked是事件,也就选择日期之后触发事件: 2.isShowClear:是否显示清理按钮: 3.maxDate:最大 ...
- 【JAVA IO流之字符流】
一.概述. java对数据的操作是通过流的方式.java用于操作流的对象都在IO包中.流按照操作数据不同分为两种,字节流和字符流.流按照流向分为输入流,输出流. 输入输出的“入”和“出”是相当于内存来 ...
- POJ3294 Life Forms(后缀数组)
引用罗穗骞论文中的话: 将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组.然后二分答案,用和例3 同样的方法将后缀分成若干组,判断每组的后缀是否出现在不小于k 个的原串中 ...
- AOP常用术语
1.连接点(Joinpoint) 程序执行的某个特定位置:如类开始初始化前,类初始化后,类某个方法调用前,调用后,方法跑出异常后.一个类或一段程序代码拥有一些具有边界性质的特定点.这些代码中的特定点就 ...
- IOS 100 - 1 开工闲聊
1 前言 现在的行情,作为码农,ios 普遍比c# 的待遇好上不少.感觉就如清洁工人,扫厕所干的再高效和干净,一个月就那么点微薄的收入.当然你可以选择去香港打扫卫生间,那里的行情据说清洁工也破万了.说 ...
- C# 使用 NPOI 库读写 Excel 文件
NPOI 是开源的 POI 项目的.NET版,可以用来读写Excel,Word,PPT文件.在处理Excel文件上,NPOI 可以同时兼容 xls 和 xlsx.官网提供了一份 Examples,给出 ...