Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.
Print a single integer — the answer to the problem.
2 2
3
9 3
13
#include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> using namespace std; typedef long long lint; typedef double DB; //const int MAXN = ; int main() { int n, m, t = 0; scanf("%d%d", &n, &m); while(n) { n--; t++; if(0 == t%m) n++; } printf("%d ", t); return 0; }
#include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> using namespace std; typedef long long lint; typedef double DB; const int MAX = 1e9; const int MAXN = 100; lint ans[100]; int fun(lint x) { int ret = 0; while(x) { ret += x%10; x /= 10; } return ret; } int main() { int a, b, c, n, m = 0; scanf("%d%d%d", &a, &b, &c); for(int i=1; i<=81; ++i) { lint x = 1ll*b*pow(i*1.0,a) + 1ll*c; if(x<MAX && x>0 && i==fun(x)) ans[m++] = x; } sort(ans, ans+m); printf("%d ", m); for(int i=0; i<m; ++i) { if(i) printf(" "); printf("%I64d", ans[i]); } printf(" "); return 0; }
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.
There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?
The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the maximum final height of the smallest flower.
6 2 3 2
2 2 2 1 1
2
2 5 1 5 8
9
ps:这里的b数组大小是n+w。
#include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> using namespace std; typedef long long lint; typedef double DB; const int MAXN = 2e5+10; const int INF = 2e9; lint a[MAXN], b[MAXN], ans; int n, m, w; bool check(lint k) { memset(b, 0, sizeof(b)); lint sum = 0, d = 0; for(int i=1; i<=n; ++i) { sum += b[i]; lint tp = k - a[i] - sum; if(tp > 0) { sum += tp; b[i+w] -= tp; d += tp; // printf("%I64d %I64d ", tp, d); if(d > m) return false; } } return true; } int main() { scanf("%d%d%d", &n, &m, &w); for(int i=1; i<=n; ++i) scanf("%I64d", a+i); lint l = 1, r = 1ll*INF; while(l <= r) { lint mid = (l+r)>>1; if(check(mid)) l = mid + 1, ans = mid; else r = mid - 1; // printf("%I64d %I64d ", l, r); } printf("%I64d ", ans); return 0; }