2017ccpc女生赛
6023 模拟
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; int T; int cnt[2010]; int vis[2010]; int main() { int n, m; cin >> T; while(T--) { memset(vis, 0, sizeof(vis)); memset(cnt, 0, sizeof(cnt)); int a, b, c; char ch, s[6]; cin >> n >> m; int times = 0; int sum = 0; for(int i = 0; i < m; i++) { scanf("%d%d%c%d%s", &a, &b, &ch, &c, s); if(vis[a]) continue; if(s[0] == 'A') { vis[a] = 1; int tmp = b * 60 + c; times++; sum += cnt[a] * 20 + tmp; } else { cnt[a]++; } } cout << times << " " << sum << endl; } return 0; }
6025 前缀和思想
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<map> using namespace std; const int maxn = 2e5 + 10; int T; int a[maxn]; //int cnt[maxn]; int forw[maxn], backw[maxn]; int gcd(int a, int b) { if(b == 0) return a; else return gcd(b, a % b); } int main() { cin >> T; int n; int t; //cout << gcd(1, 1) << endl; for(int kase = 1; kase <= T; kase++) { scanf("%d", &n); //cout << "ford" << endl; for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); if(i == 1) forw[i] = a[i]; else { forw[i] = gcd(forw[i - 1], a[i]); } //cout << forw[i] << endl; } //cout << "backw" << endl; for(int i = n; i >= 1; i--) { if(i == n) backw[i] = a[i]; else { backw[i] = gcd(backw[i + 1], a[i]); } //cout << backw[i] << endl; } int mmax = max(backw[2], forw[n - 1]); for(int i = 2; i <= n - 1; i++) { mmax = max(mmax, gcd(forw[i - 1], backw[i + 1])); } cout << mmax << endl; } return 0; }
6027 基础取模
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; ll qpow(ll a, ll b) { ll ans = 1; while(b) { if(b & 1) ans = ans * a % MOD; b >>= 1; a = a * a % MOD; } return ans; } ll cal(ll n, int k) { ll sum = 0; for(ll i = 1; i <= n; i++) { sum = (sum + qpow(i, k)) % MOD; } return sum; } int main() { int T; cin >> T; ll a; int b; while(T--) { cin >> a >> b; cout << cal(a, b) << endl; } return 0; }
6030 递推+矩阵快速幂(构造矩阵)
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; struct Mat { ll m[5][5]; };
Mat mul(Mat a, Mat b) { Mat c; memset(c.m, 0, sizeof(c.m)); for(int i = 1; i <= 4; i++) { for(int j = 1; j <= 4; j++) { for(int k = 1; k <= 4; k++) { c.m[i][j] = (c.m[i][j] + (a.m[i][k] * b.m[k][j])) % MOD; } } } return c; } void calc(Mat ori, ll n, Mat &res) //take care ll of n { //Mat res; memset(res.m, 0, sizeof(res.m)); res.m[1][1] = res.m[2][2] = res.m[3][3] = res.m[4][4] = 1; while(n) { if(n & 1) { res = mul(res, ori); } ori = mul(ori, ori); n >>= 1; } } int main() { int T; cin >> T; ll n; while(T--) { scanf("%lld", &n); if(n == 1) printf("1\n"); else if(n == 2) printf("3\n"); else if(n == 3) printf("4\n"); else if(n == 4) printf("6\n"); else { Mat ans; Mat mid; memset(mid.m, 0, sizeof(mid.m)); mid.m[1][1] = mid.m[1][3] = mid.m[2][1] = mid.m[3][2] = mid.m[4][3] = 1; calc(mid, n - 4, ans); ll sum = (ans.m[1][1] * 6 + ans.m[1][2] * 4 + ans.m[1][3] * 3 + ans.m[1][4] * 1) % MOD; printf("%lld\n", sum); } } return 0; }
posted on 2019-05-30 21:30 stagelovepig 阅读(307) 评论(0) 编辑 收藏 举报