【u221】分数

Time Limit: 1 second
Memory Limit: 128 MB

【问题描述】

高考分数刚刚公布。共有n人参加考试,为了便于填报志愿,教育部把所有考生的成绩平均分为m档。保证n是m的倍数。考试成绩名次在(k-1)(n/m)+1名到k(n/m)名的考生被分在第k档(k=1,2,3…m)。并列第i名的所有考生都算第i名。小Y刚参加完高考.迫切想知道自己被分在第几档,你能帮助他吗?

【输入格式】

第一行两个整数n,m≤1000,保证。是m的倍数。 接下来n行,每行一个整数Ai,表示第i个考生的成绩。 最后一行,一个整数x,l≤x≤n,表示询问第i个考生被分在哪一档。

【输出格式】

一行一个数,表示它被分在哪一档。

【数据规模】

Sample Input1

3 3
632
651
624
3

Sample Output1

3

【题目链接】:http://noi.qz5z.com/viewtask.asp?id=u221

【题解】

1 2 2 3 3 3 4
如果成绩为3则为第4名;如果成绩为4就是第7名了(而不是第5);
这样处理就可以了;模拟题;

【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

void rel(LL &r)
{
    r = 0;
    char t = getchar();
    while (!isdigit(t) && t!='-') t = getchar();
    LL sign = 1;
    if (t == '-')sign = -1;
    while (!isdigit(t)) t = getchar();
    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
    r = r*sign;
}

void rei(int &r)
{
    r = 0;
    char t = getchar();
    while (!isdigit(t)&&t!='-') t = getchar();
    int sign = 1;
    if (t == '-')sign = -1;
    while (!isdigit(t)) t = getchar();
    while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
    r = r*sign;
}

const int MAXN = 1e3+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);

struct abc
{
    int x,pos;
};

abc a[MAXN];
int n,m;

bool cmp(abc a,abc b)
{
    return a.x > b.x;
}

int main()
{
    //freopen("F:\rush.txt","r",stdin);
    rei(n);rei(m);
    rep1(i,1,n)
        rei(a[i].x),a[i].pos=i;
    sort(a+1,a+1+n,cmp);
    int x;
    rei(x);
    rep1(i,1,n)
        if (a[i].pos==x)
        {
            int j = i-1;
            while (j>=1 && a[j].x==a[i].x) j--;
            j = j+1;
            int t = n/m;
            int k = m;
            while ((k-1)*t>j) k--;
            printf("%d
",k);
            break;
        }
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626904.html