Topic Transmission: Codeforces Round #315 (Div. 2)
A. Music
Test instructions is more difficult to understand, but just push the formula.
Note that s+ (q-1) * t = q * t;
Just need t equals S, that is, each time you increase s second, you need to listen to the song again.
AC Code:
#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL Long Long#define INF 0x7fffffffusing namespace STD;intMain () {intT, S, q;scanf(" %d%d%d", &t, &s, &q);intAns =0; while(S < T) {s = s * q; Ans + +; }cout<< ans << Endl;return 0;}
B. Inventory
Water problem.
AC Code:
#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL Long Long#define INF 0x7fffffffusing namespace STD;intNintvis[100005];intans[100005];intpos[100005];intpos_cnt;intMain () {pos_cnt =0;scanf("%d", &n); for(inti =1; I <= N; i + +) {intTscanf("%d", &t);if(t <= n && t >=1&& Vis[t] = =0) {Ans[i] = t; VIS[T] =1; }Else{pos[pos_cnt + +] = i; } }intp =1; for(inti =0; i < pos_cnt; i + +) { for(;p <= N; p + +) {if(Vis[p] = =0) {Ans[pos[i]] = p; VIS[P] =1; Break; } } } for(inti =1; I < n; i + +) {printf("%d", Ans[i]); }printf("%d\n", Ans[n]);return 0;}
C. Primes or palindromes?
Enumeration of Dafa good.
AC Code:
#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#include <ctime>#define LL Long Long#define INF 0x7fffffffusing namespace STD;Const intMAXN =2000005;intPI[MAXN];intVIS[MAXN];intHW[MAXN];voidInit () {pi[1] =0; for(inti =2; i < MAXN; i + +) {if(!vis[i]) {Pi[i] = pi[i-1] +1; for(intj =2I J < Maxn; J + = i) {Vis[j] =1; } }ElsePi[i] = pi[i-1]; }}intP, q;intSearch () { for(inti = MAXN-1; I >=0; I--) {if(LL) pi[i] * Q <= (LL) hw[i] * p)returnI }}BOOLFunintN) {intm =0;intt = N; while(t) {m = m *Ten+ t%Ten; T/=Ten; }//cout << m << "" << n << Endl; returnm = = N;}intMain () {init (); hw[0] =0; for(inti =1; i < MAXN; i++) {if(Fun (i)) hw[i] = hw[i-1] +1;ElseHw[i] = hw[i-1]; }scanf("%d%d", &p, &q);intAns = search ();printf("%d\n", ans);return 0;}
D. Symmetric and transitive
Test instructions: is to seek in a set containing n elements, to satisfy the symmetry and transitivity, does not satisfy the relationship of reflexivity how many kinds.
Here's a strange thing--bell number
Bell number, which represents the number of sets divided by N, that is, the corresponding number of equivalence relations
A strange pattern can be found: ans[n] = bell[n +1]-bell[n];
And then you can hit the table based on the Bell Triangle.
AC Code:
#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL Long Long#define INF 0x7fffffffusing namespace STD;Const intMOD =1e9+7; LL bell[4005][4005];intMain () {intNscanf("%d", &n); bell[0][0] =1; for(inti =1; I <= N; i + +) {bell[i][0] = Bell[i-1][i-1]; for(intj =1; J <= I; J + +) {Bell[i][j] = (Bell[i][j-1] + bell[i-1][j-1])% MOD; } }printf("%i64d\n", Bell[n][n-1]);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Round #315 (Div. 2)