# 问题 A: 饶学妹的比赛

## 代码：

31 struct Node {
32     int id;
33     string name;
34     int a[20] = { 0 };
35     int b[20] = { 0 };
36     int num = 0;
37     int time = 0;
38     const bool operator<(const Node &t) const {
39         if (num != t.num) return num > t.num;
40         else if (time != t.time) return time < t.time;
41         else return id < t.id;
42     }
43 }p[MAXN];
44
45 int main() {
46     int n, m, k;
47     cin >> n >> m >> k;
48     rep(i, 1, n + 1) {
49         p[i].id = i;
50         cin >> p[i].name;
51     }
52     while (m--) {
53         int timei, idi, pidi;
54         string s;
55         cin >> timei >> idi >> pidi >> s;
56         if (s == "AC") {
57             if (!p[idi].b[pidi]) {
58                 p[idi].b[pidi] = 1;
59                 p[idi].a[pidi] += timei;
60             }
61         }
62         else {
63             if (!p[idi].b[pidi])
64                 p[idi].a[pidi] += 20;
65         }
66     }
67     rep(i, 1, n + 1) {
68         rep(j, 1, k + 1) if (p[i].b[j]) {
69             p[i].num++;
70             p[i].time += p[i].a[j];
71         }
72     }
73     sort(p + 1, p + 1 + n);
74     rep(i, 1, n + 1)
75         cout << p[i].name << ' ' << p[i].num << ' ' << p[i].time << endl;
76     return 0;
77 } 

# 问题 B: 地狱飞龙

“AC”代码如下

## 代码：

31 const double EPS = 1e-6;
32 double v1, v2, x, k;
33
34 double f(double t){
35     double d = v1*t*v1*t + (x - v2*t)*(x - v2*t);
36     return k / d;
37 }
38
39 inline double getAppr(double l, double r) {40     return (f(l) + 4.0*f((l + r) / 2) + f(r)) * (r - l) / 6.0;
41 }
42
43 double Simpson(double l, double r) {
44     double sum = getAppr(l, r);
45     double mid = (l + r) / 2;
46     double suml = getAppr(l, mid);
47     double sumr = getAppr(mid, r);
48     return (fabs(sum - suml - sumr) < EPS) ? sum : Simpson(l, mid) + Simpson(mid, r);
49 }
50
51 int main() {
52     int T;
53     cin >> T;
54     while (T--) {
55         scanf("%lf%lf%lf%lf", &v1, &v2, &x, &k);
56         double ans = Simpson(0, 20000);
57         printf("%.2lf\n", ans);
58     }
59     return 0;
60 } 

# 问题 C: 魔法宝石

## 代码：

31 vector<PII> C[MAXN];
32 int d[MAXN];
33 priority_queue<PII, vector<PII>, greater<PII> > que;
34
35 void dijkstra() {
36     while (!que.empty()) {
37         PII p = que.top(); que.pop();
38         int v = p.second;
39         if (d[v] < p.first) continue;
40         d[v] = p.first;
41         rep(i, 0, C[v].size()) {
42             PII p = C[v][i];
43             int a = v;
44             int b = p.first;
45             int c = p.second;
46             if (d[c] > d[a] + d[b]) {
47                 d[c] = d[a] + d[b];
48                 que.push(mp(d[a] + d[b], c));
49             }
50         }
51     }
52 }
53
54 int main() {
55     int T;
56     cin >> T;
57     while (T--) {
58         rep(i, 0, MAXN) C[i].clear();
59         int n, m;
60         cin >> n >> m;
61         rep(i, 1, n + 1) {
62             int a;
63             scanf("%d", &a);
64             d[i] = a;
65         }
66         while (m--) {
67             int a, b, c;
68             scanf("%d%d%d", &a, &b, &c);
69             que.push(mp(d[a]+d[b], c));
70             C[a].pb(mp(b, c));
71             C[b].pb(mp(a, c));
72         }
73         dijkstra();
74         rep(i, 1, n + 1) {
75             printf("%d", d[i]);
76             if (i == n) printf("\n");
77             else printf(" ");
78         }
79     }
80     return 0;
81 } 

# 问题 D: rqy的键盘

## 代码：

31 string s = " QWERTYUIOPASDFGHJKLZXCVBNM ";
32
33 struct Node {
34     char c, l, r;
35 }node[30];
36
37 int main() {
38     rep(i, 1, 27) {
39         node[i].c = s[i];
40         node[i].l = s[i - 1];
41         node[i].r = s[i + 1];
42     }
43     node[1].l = '0';
44     node[11].l = '0';
45     node[20].l = '0';
46     node[10].r = '0';
47     node[19].r = '0';
48     node[26].r = '0';
49     int T;
50     cin >> T;
51     while (T--) {
52         char x;
53         string dir;
54         cin >> x >> dir;
55         int pos = s.find(x, 0);
56         char ans;
57         if (dir == "Left") ans = node[pos].l;
58         else ans = node[pos].r;
59         if (ans == '0') cout << "No letter." << endl;
60         else cout << ans << endl;
61     }
62     return 0;
63 } 

# 问题 F: Hmz 的女装

## 题解：

dp[i] = ((k - 1)*dp[i - 2] + (k - 2)*dp[i - 1]) % MOD;

## 代码：

31 ll dp[MAXN];
32
33 int main() {
34     ll n, m, k;
35     while (cin >> n >> m >> k) {
36         dp[2] = k - 1;
37         dp[3] = (k - 1)*(k - 2);
38         rep(i, 4, n) dp[i] = ((k - 1)*dp[i - 2] + (k - 2)*dp[i - 1]) % MOD;
39         while (m--) {
40             int l, r;
41             scanf("%d%d", &l, &r);
42             if (l > r) swap(l, r);
43             ll ans = k;
44             ans = (ans*dp[r - l]) % MOD;
45             ans = (ans*dp[n - r + l]) % MOD;
46             printf("%lld\n", ans);
47         }
48     }
49     return 0;
50 } 

# 问题 G: 最大子段和

## 代码：

31 int a[MAXN];
32
33 int main() {
34     int T;
35     cin >> T;
36     while (T--) {
37         int n;
38         cin >> n;
39         int n1 = 0, n2 = 0;
40         rep(i, 1, n + 1) scanf("%d", a + i);
41         int sum = a[1], b = a[1];
42         for (int i = 2; i < n; i += 2) {
43             b += a[i] + a[i + 1];
44             if (b < a[i + 1]) b = a[i + 1];
45             if (sum < b) sum = b;
46         }
47         int ans = sum;
48         sum = a[2], b = a[2];
49         for (int i = 3; i < n; i += 2) {
50             b += a[i] + a[i + 1];
51             if (b < a[i + 1]) b = a[i + 1];
52             if (sum < b) sum = b;
53         }
54         ans = max(ans, sum);
55         cout << ans << endl;
56     }
57     return 0;
58 } 

# 问题 H: ch追妹

## 代码：

31 int main() {
32     int T;
33     cin >> T;
34     while (T--) {
35         int n, m, a, b;
36         cin >> n >> m >> a >> b;
37         string ans = "chsad";
38         while (m--) {
39             int x, y;
40             cin >> x >> y;
41             if (x == a && y == b || x == b && y == a) ans = "chhappy";
42         }
43         cout << ans << endl;
44     }
45     return 0;
46 } 

# 问题 I: 小天使改名

## 代码：

31 int main() {
32     int T;
33     cin >> T;
34     while (T--) {
35         string a, b;
36         cin >> a >> b;
37         VI v;
38         rep(i, 0, a.length()) if (a[i] != b[i]) v.pb(i);
39         if (v.size() == 0) {
40             string s = a;
41             sort(all(s));
42             int fg = 0;    //如果两个字符串一样 但是没有出现相同字符
43             rep(i, 1, s.length()) if (s[i] == s[i - 1]) fg = 1;
44             if (fg) cout << "YES" << endl;
45             else cout << "NO" << endl;
46         }
47         else if (v.size() == 2) {
48             if (a[v[0]] == b[v[1]] && a[v[1]] == b[v[0]]) cout << "YES" << endl;
49             else cout << "NO" << endl;
50         }
51         else cout << "NO" << endl;
52     }
53     return 0;
54 } 

# 问题 J: 爱看电视的LsF

## 代码：

31 int good[20];
32
33 bool check(int x) {
34     if (x == 0) return good[x];
35     while (x) {
36         if (!good[x % 10]) return false;
37         x /= 10;
38     }
39     return true;
40 }
41
42 int num_len(int x) {
43     int s = x == 0 ? 1 : 0;
44     while (x) x /= 10, s++;
45     return s;
46 }
47
48 int main() {
49     int n, s, t;
50     while (cin >> n >> s >> t) {
51         rep(i, 0, 10) good[i] = 1;
52         rep(i, 0, n) {
53             int t;
54             cin >> t;
55             good[t] = 0;
56         }
57         int ans = abs(t - s);
58         int step = ans;
59         rep(i, 0, step) {
60             int l = t - i;
61             int r = t + i;
62             if (l >= 0 && check(l)) ans = min(ans, i + num_len(l));
63             if (check(r)) ans = min(ans, i + num_len(r));
64         }
65         cout << ans << endl;
66     }
67     return 0;
68 }

posted @ 2017-04-23 18:19 Flowersea 阅读(...) 评论(...) 编辑 收藏