A. Vasya and sockstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Vasya hasNPairs 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. everyM-Th day (at days with numbersM,? 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?
Input
The single line contains two integersNAndM(1? ≤?N? ≤? 100; 2? ≤?M? ≤? 100), separated by a space.
Output
Print a single integer-the answer to the problem.
Sample test (s) Input
2 2
Output
3
Input
9 3
Output
13
Portal: Click to open the link. Solution: Water question, simple simulation. Code:
#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\n", t); return 0;}
B. Little Dima and equationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Little Dima misbehaved during a math lesson a lot and the nasty teacher mr. Pickles gave him the following problem as a punishment.
Find All Integer SolutionsX(0? <?X? <? (109) of the equation:
X? =?
B·
S(
X)
A? +?
C,?
WhereA,B,CAre some predetermined constant values and FunctionS(X) Determines the sum of all digits in the decimal representation of numberX.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation:A,B,C. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.
Input
The first line contains three space-separated integers:A,?B,?C(1? ≤?A? ≤? 5; 1? ≤?B? ≤? 10000 ;? -? 10000? ≤?C? ≤? 10000 ).
Output
Print integerN-The number of the solutions that you 've found. Next printNIntegers in the increasing order-the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
Sample test (s) Input
3 2 8
Output
310 2008 13726
Input
1 2 -18
Output
0
Input
2 2 -1
Output
41 31 337 967
Portal: Click to open the link to solve the problem. The value of S (x) ranges from 1 to 81. We can enumerate the value of S (X) to the value of X to check whether it is consistent. Code:
#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\n", m); for(int i=0; i<m; ++i) { if(i) printf(" "); printf("%I64d", ans[i]); } printf("\n"); return 0;}
C. presenttime limit per Test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
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. planhe tedNFlowers 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 areMDays left to the birthday. The height ofI-Th flower (assume that the flowers in the row are numbered from 1NFrom left to right) is equalAIAt the moment. At each of the remainingMDays the beaver can take a special watering and waterWContiguous 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?
Input
The first line contains space-separated IntegersN,MAndW(1? ≤?W? ≤?N? ≤? 105; 1? ≤?M? ≤? 105). The second line contains space-separated IntegersA1 ,?A2 ,?...,?AN(1? ≤?AI? ≤? 109 ).
Output
Print a single integer-the maximum final height of the smallest flower.
Sample test (s) Input
6 2 32
2 2 2 1 1
Output
2
Input
2 5 15 8
Output
9
Portal: Click to open the link to solve the problem. The solution is divided into two parts. PS: The size of array B is n + W. Code:
#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\n", 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\n", l, r); } printf("%I64d\n", ans); return 0;}