Codeforces 879 A Borya's Diagnosis

题目链接

题目大意:给出n个医生的工作时间,问按顺序拜访所有医生最少要用多少天。

医生的工作时间符合等差数列。

题目分析:一开始以为不按顺序拜访卡了很久。

如果是按顺序拜访的话利用等差数列公式sn=s1+(k-1)d。当一号医生在第x天工作,那么对于二号医生,由x=s1+(k-1)d,得到k,根据除法向下取整可知二号医生一定在

第k+1个工作日工作。需要注意的是这个公式的前提是x>s1,如果x<s1的话明显k=1.但不用+1.

代码如下

#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
#include<fstream>
//#define mod 1030
//#define size 3
using namespace std;
typedef long long LL;
const int maxn = (int)(2 * 1e4 + 100);
const int maxm = (int)(22222);
const int inf = (int)(1e9 * 2);
const double eps = 1e-8;
const double pi = acos(-1);
int main() {
	int n;
	while (scanf("%d", &n) == 1) {
		int s, d, ans;
		for (int i = 1; i <= n; i++) {
			scanf("%d%d", &s, &d);
			if (i == 1) ans = s;
			else {
				if (ans < s) ans = s;
				else {
					int tmp = (ans - s) / d;
					ans = s + (tmp + 1)*d;
				}
			}
		}
		printf("%d\n", ans);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值