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);
}
}
题目大意:给出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 Round #443 (Div. 2)A. Borya's Diagnosis
- Codeforces Round #443 (Div.2) - A - Borya's Diagnosis
- A. Borya's Diagnosis
- Codeforces Round #443 (Div. 2) A. Borya's Diagnosis(水水的模拟)
- code forces 443 A.Borya's Diagnosis(找规律)
- Codeforces Round #443 A. Borya's Diagnosis
- Codeforces 442A - Borya and Hanabi
- Codeforces Round #443 (Div. 2) A. Borya's Diagnosis
- Codeforces 879 B Table Tennis(模拟)
- 【CodeForces - 879】 A B C【构造+思维】
- Codeforces Round #443 (Div. 2) A. Borya's Diagnosis
- Codeforces 879-B. Table Tennis
- CodeForces 828A Restaurant Tables
- codeforces 893F Subtree Minimum Query 线段树合并
- CodeForces-VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) -C. Substring and Subsequence
- CodeForces 509B Painting Pebbles
- CodeForces 173C Spiral Maximum (想法、模拟)
- codeforces 180F Mathematical Analysis Rocks!
- Codeforces 827C/828E DNA Evolution[树状数组]
- Codeforces 895A (入门 prefix sum)