Codeforces 1068A Birthday
程序员文章站
2022-05-09 21:58:15
...
二分就好了,注意边界条件。
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
long long N, M, K, L;
long long ans;
int main() {
scanf("%lld %lld %lld %lld", &N, &M, &K, &L);
if (M > N) {
printf("-1\n");
}
else {
long long div = N / M;
long long l = 1;
long long r = div;
long long m;
while (l <= r) {
m = (l + r) >> 1;
if ((m*M - K) >= L) {
r = m - 1;
}
else {
l = m + 1;
}
}
if ((r*M - K) >= L&&r<=div) {
printf("%lld\n", r);
}
else if ((l*M - K) >= L&&l<=div) {
printf("%lld\n", l);
}
else {
printf("-1\n");
}
}
//system("pause");
return 0;
}
下一篇: python爬取51job的招聘信息
推荐阅读
-
Codeforces Round #595 (Div. 3)D1D2 贪心 STL
-
『ACM C++』 Codeforces | 1066B - Heaters
-
『ACM C++』 Codeforces | 1003C - Intense Heat
-
Codeforces 939A题,B题(水题)
-
CodeForces 29D Ant on the Tree
-
Codeforces Global Round 9-C. Element Extermination
-
codeforces 712B Memory and Trident
-
CodeForces 962D Merge Equals
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
CodeForces 1326E - Bombs