1. 程式人生 > >codeforces#518 Div2 ABCD【未完成】

codeforces#518 Div2 ABCD【未完成】

A Birthday

http://codeforces.com/contest/1068/problem/A

題意:

有n種硬幣,m個人。m個人要給Ivan送硬幣,每個人送的硬幣都要互不相同但數量一樣。Ivan現在已經有k種了,具體哪k種不知道。現在要求朋友們送的硬幣至少有l種是IVan沒有的。

思路:

剛開始想的是l/m取上整。後來發現題意是不知道Ivan有的是哪幾種,為了保證一定至少l種的話,就需要(l+k)/m取上整。

不可能的情況是人數乘每個人送的硬幣數超過n。

用longlong

 1 #include <bits/stdc++.h>
 2 #define
inf 0x3f3f3f3f 3 using namespace std; 4 5 long long n, m, l, k; 6 int main() 7 { 8 while(scanf("%I64d%I64d%I64d%I64d", &n, &m, &k, &l) != EOF){ 9 long long cnt; 10 if((l + k) % m == 0){ 11 cnt = (l + k) / m; 12 } 13 else { 14 cnt = (l + k) / m + 1
; 15 } 16 if(cnt * m > n){ 17 printf("-1\n"); 18 } 19 else{ 20 printf("%I64d\n", cnt); 21 22 } 23 24 } 25 return 0; 26 }
View Code