参考思路:很容易计算,略。
参考程序:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxN = 15 + 2; int N, A[maxN]; int main() { int nt; scanf("%d", &nt); while( (nt --) > 0 ) { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", A + i); sort(A, A + N); int res = (6 + 4) * A[N - 1] + N; N = unique(A, A + N) - A; res += 5 * N; printf("%d\n", res); } return 0; }
参考思路:容易推导出表达式:B[ i ] = A[ (((i - t) % N) + N) % N ] * (K^t),注意,这里下角标从0开始。
参考程序:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long i64d; i64d Mod = 1000000007LL; i64d exp_mod(i64d a, int b) { if( a == 0LL ) return 0LL; if( b == 0 ) return 1LL; if( b == 1 ) return a % Mod; i64d ret = exp_mod(a, b >> 0x1); ret = (ret * ret) % Mod; if( b & 0x1 ) ret = (ret * a) % Mod; return ret; } const int maxN = 10086; int N, t, K; i64d A[maxN], B[maxN]; int main() { int nt; scanf("%d", &nt); while( (nt --) > 0 ) { scanf("%d %d %d", &N, &t, &K); for(int i = 0; i < N; i ++) scanf("%I64d", A + i); i64d base = exp_mod((i64d)K, t); for(int i = 0; i < N; i ++) { int pos = (i - t) % N; pos = (pos + N) % N; B[i] = (A[pos] * base) % Mod; } for(int i = 0; i < N; i ++) { if( i ) putchar(' '); printf("%I64d", B[i]); } printf("\n"); } return 0; }
参考思路:Not Finished。
参考程序:Not Submitted。
参考思路:
考虑最容易想到的状态转移方程,即:
DP[ i ][ j ] = max{ DP[i - 1][ j - k * b[i] ] + k * a[i] | k = 0, 1, ..., j / b[i] }
式中,DP[ i ][ j ] 表示前 i 种食物的可供最大能量正好为 j。程序实现的时候,可做如下优化:
参考程序:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxN = 100 + 2; int N, M; struct node { int cost, val; inline bool operator<(const node &s) const { if( cost != s.cost ) return cost < s.cost; return val < s.val; } inline bool operator==(const node &s) const { return cost == s.cost && val == s.val; } inline void in() { scanf("%d %d", &val, &cost); } }; node A[maxN]; int dp[100000 + 10]; int main() { while( scanf("%d", &N) == 1 ) { for(int i = 0; i < N; i ++) A[i].in(); scanf("%d", &M); sort(A, A + N); N = unique(A, A + N) - A; for(int i = 0; i <= M; i ++) dp[i] = 0; for(int i = 0; i < N; i ++) { if( A[i].val == 0 ) continue; if( A[i].cost == 0 ) break; if( i + 1 < N && A[i].cost == A[i + 1].cost && A[i].val < A[i + 1].val ) continue; for(int j = 0; j + A[i].cost <= M; j ++) dp[j + A[i].cost] = max(dp[j + A[i].cost], dp[j] + A[i].val); } printf("%d\n", dp[M]); } return 0; }
参考思路:模拟。
参考程序:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxN = 500000 + 10; struct node { int s, e; int a, b; char c; inline void in() { scanf("%d%c%d", &a, &c, &b); s = a * 60 + b; scanf("%d%c%d", &a, &c, &b); e = a * 60 + b; //printf("s = %d, e = %d\n", s, e); } inline bool operator<(const node &cp) const { if( s != cp.s ) return s < cp.s; return e < cp.e; } }; int N; node A[maxN]; int main() { while( scanf("%d", &N) == 1 ) { for(int i = 0; i < N; i ++) A[i].in(); sort(A, A + N); int cnt = 0, end = 0; for(int i = 0; i < N; i ++) { if( end > A[i].e ) continue; end = max(end, A[i].s); cnt += A[i].e - end; end = max(end, A[i].e); } printf("%d\n", 60 * 24 - cnt ); } return 0; }
OpenSpirit @ SWJTU