Codeforces Round #262 (Div. 2) 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.
【代码】:
#include <bits/stdc++.h> using namespace std;
int sum;
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=n,j=;i>=;i--,j++)//i:袜子个数
{
if(j%m==)
i++;
sum++;
}
cout<<sum<<endl;
}
return ;
}
双指针
#include <bits/stdc++.h> using namespace std; int main()
{
int n,m;
while(cin>>n>>m)
{
int day=;
int k=;
while(n--)//袜子消耗
{
if(day%m==)
{
n++;//当是m的倍数的时候再购进一双袜子
}
day++;//不管有没有袜子穿日子总要过下去
k++;//维持的日子
}
printf("%d\n",k);
}
return ;
}
多变量记录
Codeforces Round #262 (Div. 2) A. Vasya and Socks【暴力/模拟/袜子在可以在合法情况下增加后用几天】的更多相关文章
- 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 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 ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力
A. Vasya and Football Vasya has started watching football games. He has learned that for some foul ...
- Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #262 (Div. 2)解题报告
详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks http ...
随机推荐
- Android保持屏幕常亮唤醒状态
第一步: 首先添加权限: <uses-permission android:name="android.permission.WAKE_LOCK"></uses ...
- 图解-Excel的csv格式特殊字符处理方式尝试笔记(个人拙笔)
Excel格式如下.(截图来自,WPS Office) CSV是一种文本格式的Excel文档格式.不支持Excel的字体特效(比如加粗,颜色)等等的保存. 每一行数据用 "\n" ...
- GTID环境中手动修复主从故障一例(Error 1236/Error 1396)
Preface I got an replication error 1236 when I modified the password of a user without start ...
- android中dumpsys命令使用
转自:https://testerhome.com/topics/1462 adb shell dumpsys,默认打印出当前系统所有service信息,在后面可加上具体的服务名 需要列出当前运行的服 ...
- JMeter学习笔记(九) 参数化2--CSV Data Set Config
2.CSV Data Set Config 1)添加 CSV Data Set Confi 2)配置CSV Data Set Config 3)添加HTTP请求,引用参数,格式 ${} 4)执行HTT ...
- linux path环境变量基础
系统环境变量与个人环境变量的配置文件 系统级别的配置文件: /etc/profile :这个文件预设了几个重要的变量,例如PATH, USER, LOGNAME, MAIL, INPUTRC, HO ...
- nginx 快速查看配置文件的方法
查看nginx实际调用的配置文件 1.查看nginx路径 ps aux|grep nginx root ?? S :43上午 :00.08 nginx: worker process root ?? ...
- 聊聊、SpringBoot 上传文件大小
#2.0#spring.servlet.multipart.max-file-size=10Mb#spring.servlet.multipart.max-request-size=10Mb #1.3 ...
- 构建Docker镜像两种方式的比较-Dockerfile方式和S2I方式
前言 写Dockerfile是构建Docker镜像最通常的方式,接触过Docker的童鞋多少了解一些.前段时间研究OpenShift(paas的一种),发现了另外一种构建Docker镜像的方式:S2I ...
- Learn the shell
learn the shell what is the shell? when we speak of the command line,we are really to the shell.Actu ...