贴贴水题
http://www.codeforces.com/problemset/problem/175/B
标签是模拟题,我用两个数状数组做的,分别记录比当前数大的数的个数和小于等于当前数的个数
有些细节都要处理好
View Code
//============================================================================ // Name : w.cpp // Author : dd.cpp // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #pragma warning (disable : 4786) #include<cstdio> #include<cstring> #include<map> #include<cmath> #include<set> #include<queue> #include<iostream> #include<string> #include<algorithm> using namespace std; const double eps = 1e-8; const int maxn = 1010; int c1[maxn]; int c2[maxn]; map<string, int> mm; set<string> st; void add1(int x, int d) { for (; x < maxn; x += x & -x) c1[x] += d; } int sum1(int x) { int ans = 0; for (; x > 0; x -= x & -x) ans += c1[x]; return ans; } void add2(int x, int d) { for (; x > 0; x -= x & -x) c2[x] += d; } int sum2(int x) { int ans = 0; for (; x < maxn; x += x & -x) ans += c2[x]; return ans; } int main() { string ss; int num; int n, m, i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { cin >> ss >> num; st.insert(ss); if (mm.find(ss) != mm.end()) { if (num+1 > mm[ss]) mm[ss] = num+1; } else { mm[ss] = num+1; } } n = st.size(); cout<<n<<endl; set<string>::iterator it; memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); for (it = st.begin(); it != st.end(); it++) { add1(mm[*it], 1); add2(mm[*it], 1); } for (it = st.begin(); it != st.end(); it++) { cout << *it << " "; int num1 = sum2(mm[*it] + 1); int num2 = sum1(mm[*it]); //printf("num1=%d num2=%d\n",num1,num2); if (1.0 * num1 / n > 0.5) printf("noob\n"); else if ((fabs(num2 * 1.0 / n - 0.5) < eps || num2*1.0/n-0.5>eps) && num1 * 1.0 / n - 0.2 >eps) printf("random\n"); else if ((fabs(num2 * 1.0 / n - 0.8) < eps||num2*1.0/n-0.8>eps) && num1 * 1.0 / n - 0.1 > eps) printf("average\n"); else if ((fabs(num2 * 1.0 / n - 0.9) < eps || num2*1.0/n-0.9>eps) && num1 * 1.0 / n - 0.01 >eps) printf("hardcore\n"); else printf("pro\n"); } return 0; }