Codeforces Round #315 (Div. 2)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #315 (Div. 2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目傳送:Codeforces Round #315 (Div. 2)
A. Music
題意較難懂。只是僅僅要推公式就好了
注意到S+(q - 1) * t = q * t;
僅僅須要t等于S就可以。即每次添加S秒,就須要又一次聽一次歌
AC代碼:
#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 0x7fffffff using namespace std;int main() {int T, S, q;scanf("%d %d %d", &T, &S, &q);int ans = 0;while(S < T) {S = S * q;ans ++;}cout << ans << endl;return 0; }B. Inventory
水題。。
AC代碼:
#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 0x7fffffff using namespace std;int n; int vis[100005];int ans[100005];int pos[100005]; int pos_cnt;int main() {pos_cnt = 0;scanf("%d", &n);for(int i = 1; i <= n; i ++){int t;scanf("%d", &t);if(t <= n && t >= 1 && vis[t] == 0) {ans[i] = t;vis[t] = 1;}else {pos[pos_cnt ++] = i;}}int p = 1;for(int i = 0; i < pos_cnt; i ++) {for(;p <= n; p ++) {if(vis[p] == 0) {ans[pos[i]] = p;vis[p] = 1;break;}}}for(int i = 1; i < n; i ++) {printf("%d ", ans[i]);}printf("%d\n", ans[n]);return 0; }C. Primes or Palindromes?
枚舉大法好。。
AC代碼:
#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 0x7fffffff using namespace std;const int maxn = 2000005; int pi[maxn]; int vis[maxn];int hw[maxn];void init() {pi[1] = 0;for(int i = 2; i < maxn; i ++) {if(!vis[i]) {pi[i] = pi[i - 1] + 1;for(int j = 2 * i; j < maxn; j += i) {vis[j] = 1;}}else pi[i] = pi[i-1];} }int p, q;int search() {for(int i = maxn - 1; i >= 0; i --) {if((LL)pi[i] * q <= (LL)hw[i] * p) return i;} }bool fun(int n) {int m = 0;int t = n;while(t) {m = m * 10 + t % 10;t /= 10;}//cout << m << " " << n << endl;return m == n; }int main() {init();hw[0] = 0;for(int i = 1; i < maxn; i++) {if(fun(i)) hw[i] = hw[i-1] + 1;else hw[i] = hw[i-1];}scanf("%d %d", &p, &q);int ans = search();printf("%d\n", ans);return 0; }D. Symmetric and Transitive
題意:就是去求在一個含有n個元素的集合里。滿足對稱性和傳遞性。不滿足自反性的關系有多少種。
這里有一個奇怪的東西——Bell數
Bell數,表示基數為n的集合劃分數目,也就是相應的等價關系個數
能夠發現一個奇怪的規律:ans[n] = Bell[n +1] - Bell[n];
然后依據Bell三角形打表就能夠了
AC代碼:
#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 0x7fffffff using namespace std;const int MOD = 1e9+7;LL Bell[4005][4005];int main() {int n;scanf("%d", &n);Bell[0][0] = 1;for(int i = 1; i <= n; i ++) {Bell[i][0] = Bell[i - 1][i - 1];for(int j = 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; }轉載于:https://www.cnblogs.com/gccbuaa/p/6970751.html
總結
以上是生活随笔為你收集整理的Codeforces Round #315 (Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 06. 从尾到头打印链表
- 下一篇: openjudge 菲波那契数列 275