您的位置:首页 > 其它

Codeforces 879 A Borya's Diagnosis

2017-10-27 13:11 330 查看
题目链接

题目大意:给出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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces