【HDOJ】5131 Song Jiang's rank list

STL的使用。

 1 /* 5131 */
 2 #include <iostream>
 3 #include <map>
 4 #include <cstdio>
 5 #include <cstdlib>
 6 #include <cstring>
 7 #include <string>
 8 #include <algorithm>
 9 using namespace std;
10
11 #define MAXN 205
12
13 typedef struct {
14     string s;
15     int i, n;
16 } hero_t;
17
18 typedef struct node_t {
19     int mmin, mmax;
20     node_t() {}
21     node_t(int a, int b) {
22         mmin = a; mmax = b;
23     }
24 } node_t;
25
26 hero_t heros[MAXN];
27
28 bool comp(hero_t a, hero_t b) {
29     if (a.n == b.n)
30         return a.s < b.s;
31     else
32         return a.n > b.n;
33 }
34
35 int main() {
36     int n, m;
37     int i, j, k, id = 0;
38     string s;
39     node_t nd;
40
41     ios::sync_with_stdio(false);
42
43     #ifndef ONLINE_JUDGE
44         freopen("data.in", "r", stdin);
45     #endif
46
47     while (cin>>n && n) {
48         for (i=0; i<n; ++i) {
49             heros[i].i = i;
50             cin >>heros[i].s>>heros[i].n;
51         }
52
53         sort(heros, heros+n, comp);
54         for (i=0; i<n; ++i)
55             cout <<heros[i].s<<‘ ‘<<heros[i].n<<endl;
56
57         map<string, node_t> tb;
58         i = 0;
59         while (i < n) {
60             j = 1;
61             while ((i+j)<n && heros[i+j].n == heros[i].n)
62                 ++j;
63             if (j > 1) {
64                 for (k=0; k<j; ++k) {
65                     tb[heros[i+k].s] = node_t(k+1, i+1);
66                 }
67                 i += j;
68             } else {
69                 tb[heros[i].s] = node_t(1, i+1);
70                 ++i;
71             }
72         }
73         cin >>m;
74         while (m--) {
75             cin >>s;
76             nd = tb[s];
77             if (nd.mmin == 1)
78                 cout <<nd.mmax<<endl;
79             else
80                 cout <<nd.mmax<<‘ ‘<<nd.mmin<<endl;
81         }
82         id = 0;
83     }
84
85     return 0;
86 }

【HDOJ】5131 Song Jiang's rank list

时间: 2024-08-26 14:40:12

【HDOJ】5131 Song Jiang's rank list的相关文章

hdoj 5131 Song Jiang&#39;s rank list 【模拟】

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 653    Accepted Submission(s): 323 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

【HDOJ】1811 Rank of Tetris

并查集+拓扑排序.使用并查集解决a = b的情况. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 using namespace std; 6 7 #define MAXN 10005 8 9 typedef struct ArcNode { 10 int adjvex; 11 ArcNode *next; 12 } ArcNode; 1

HDOJ 5131 Song Jiang&#39;s rank list 水

水排序 Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 71    Accepted Submission(s): 39 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Na

【HDOJ】3789 奥运排序问题

写了个函数指针,这题目很水,但是佷烦. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <cstdlib> 5 using namespace std; 6 7 #define MAXN 305 8 9 typedef struct { 10 int id, g, j; 11 float gp, jp; 12 } count_st; 13 14 typedef

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

【HDOJ】2844 Coins

完全背包. 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[105], c[105]; 5 int n, m; 6 int dp[100005]; 7 8 int mymax(int a, int b) { 9 return a>b ? a:b; 10 } 11 12 void CompletePack(int c) { 13 int i; 14 15 for (i=c; i<=m; ++i) 16 dp[i]

【HDOJ】3509 Buge&#39;s Fibonacci Number Problem

快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. 1 /* 3509 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #incl

【HDOJ】1818 It&#39;s not a Bug, It&#39;s a Feature!

状态压缩+优先级bfs. 1 /* 1818 */ 2 #include <iostream> 3 #include <queue> 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <algorithm> 8 using namespace std; 9 10 #define MAXM 105 11 12 typedef struct {