比赛地址:戳我python
关键:ios
Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). git
即,给出的数必须包括[0...k]全部数字。超出范围的数字忽略不计。spa
一个小坑。注意读题。code
找出给出数列的最长子列,使这个子列知足: a[i] + a[i + 1] == a[i + 2]。ci
同时,长度为1 或 2的子列均认为知足条件。get
此题须要一个小小的证实,我不知道怎么表达。看代码就好,很简单的思路。input
一道中等题。string
对于一个子矩阵来讲,其和必须为: sum(a[i...j]) * sum(a[x...y])it
因此咱们用O(n^2)的时间复杂度枚举出s
的全部子串和,以及全部子串和出现的次数。
若是 M = sum(a[i...j]), 同时cnt[M] = u; 则推出 N = a / M; //注:M为0的状况再讨论 获得cnt[N] = v; 则 ans += u * v;
当上述伪代码中的M为0时,若是a == 0,则N必须为全部子串和的种数。
若是a != 0,则N必为0。(由于0 * M == 0 != a)
被得0状况小坑了几回,以后把这题切掉了。
其实这题算一道简单题。
由于题目中给出公式s(x) + d < s(y)
。根据此式咱们能够推出,不管咱们拥有什么宝贝。下一轮交换的结果必定知足以下两个条件。
A[i + 1] > A[i]; A[i + 1] <= A[i] + d;
A[i]表示的是第i轮咱们拥有的宝贝的总价值。
对于A[i],咱们能够用背包DP来求得其可能的值。
因而此题就转化为:背包DP + 一个while循环。能够归为简单题。可是有一点思路上的小弯。
TODO:此题不会,我须要一个证实。。。坐等题解。
import sys sys.stdin = open("input.txt") (n, k) = map(int, raw_input().split()) res = 0 for i in xrange(n): s = map(int, raw_input()) st = set() for item in s: if item > k: pass else: st.add(item) else: if len(st) == k + 1: res += 1 #print s, 'yes' print res
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define print(x) cout << x << endl #define input(x) cin >> x const int SIZE = 100100; int n; int A[SIZE]; int judge(int &t) { int st = t - 1 >= 0? t - 1: t; int res = 0; for (int i = 0; st + i < n; i++) { if (i >= 2 && A[st + i - 1] + A[st + i - 2] == A[st + i]) { res = i + 1; } else if (i < 2) { res++; continue; } else { break; } } t = st + res; return res; } int main() { freopen("input.txt", "r", stdin); while(input(n)) { for (int i = 0; i < n; i++) { input(A[i]); } int ans = 0; int t = 0; while (t < n) { int res = judge(t); //print(t); ans = max(ans, res); } print(ans); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <map> using namespace std; #define print(x) cout << x << endl #define input(x) cin >> x typedef long long llint; const int SIZE = 4444; llint a; int len; char val[SIZE]; map<llint, int> mp; int main() { freopen("input.txt", "r", stdin); while (input(a)) { llint ans = 0; input(val); len = strlen(val); mp.clear(); int sumall = 0; for (int i = 0; i < len; i++) { val[i] -= '0'; } for (int i = 1; i <= len; i++) { llint t = 0; for (int j = 0; j < i; j++) { t += val[j]; } mp[t]++; sumall++; for (int j = i; j < len; j++) { t -= val[j - i]; t += val[j]; mp[t]++; sumall++; } } for (map<llint, int>::iterator iter = mp.begin(); iter != mp.end(); ++iter) { llint x = iter -> first; int y = iter -> second; //print(x << ' ' << y); if (!x) { if (!a) { ans += (llint)sumall * y; } continue; } if (a % x == 0) { int z = mp[a / x]; ans += (llint)y * z; } } print(ans); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define print(x) cout << x << endl #define input(x) cin >> x const int N = 55; const int D = 10100; char dp[N * D]; int n, d; int A[N]; void do_package() { memset(dp, 0, sizeof(dp)); dp[0] = 1; for (int i = 0; i < n; i++) { for (int j = N * D - 1; j >= 0; j--) { if (dp[j] && j + A[i] < N * D) { dp[j + A[i]] = 1; } } } } void solve(int &val, int &day) { val = day = 0; while (1) { bool flag = false; for (int i = val + d; i > val; i--) { if (dp[i]) { val = i; day++; flag = true; break; } } if (!flag) break; } } int main() { freopen("input.txt", "r", stdin); while (input(n >> d)) { for (int i = 0; i < n; i++) { input(A[i]); } do_package(); int a, b; solve(a, b); print(a << ' ' << b); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <vector> using namespace std; #define print(x) cout << x << endl #define input(x) cin >> x const int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int main() { int n; input(n); vector<int> res; int limit = 2 * n * n; for (int i = 0; i < 15; i++) { res.clear(); res.push_back(1); for (int j = 0; j <= i; j++) { int p = prime[j]; int sz = res.size(); for (int k = 0; k < sz; k++) { int x = res[k]; while (x * p <= limit) { x *= p; res.push_back(x); } } } if (res.size() >= n) { break; } } sort(res.begin(), res.end(), greater<int>()); for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", res[i]); } puts(""); return 0; }