首页 > 代码库 > ZOJ 3705 Applications 模拟

ZOJ 3705 Applications 模拟

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI  3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
    return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
    return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else

    freopen("in.txt","r",stdin);
    freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
    int ch;
    while((ch=getchar())!=EOF) {
        if(ch!= &&ch!=\n)return ch;
    }
    return EOF;
}

const int maxn=505;
const double eps=1e-8;
int isprime(int n)
{
    if(n==1||n==0)return 0;
    if(n==2)return 1;
    for(int i=2;i*i<=n;i++)
        if(n%i==0)return false;
    return true;
}
struct APP
{
    char name[50];
    char belong[50];
    char sex;
    vector<int> solved;
    vector<int> rating;
    double score;
    bool operator < (const APP &ant ) const
    {
        if(fabs(score-ant.score)>eps) return score>ant.score;
        else return strcmp(name,ant.name)<0?1:0;
    }
}da[maxn];
map<string,int> prize;
int prob[10005];
int n,m;

void cal()
{
    for(int i=1;i<=n;i++)
    {
        da[i].score=0;
        for(int j=0;j<da[i].solved.size();j++)
        {
            int id=da[i].solved[j];
            if(prob[id]==1) da[i].score+=2.5;
            else if(prob[id]==2) da[i].score+=1.5;
            else if(isprime(id)) da[i].score+=1;
            else da[i].score+=0.3;
        }
        int x=prize[string(da[i].belong)];
        if(x!=0&&x<=3) da[i].score+= (5-x)*9;

        int rat;
        if(da[i].rating.size()>=3)
            rat=max(1200,da[i].rating[2]);
        else rat=1200;

        da[i].score+= (rat-1200)/100.0*1.5;

        if(da[i].sex==F) da[i].score += 33;
    }
    sort(da+1,da+n+1);
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int ca=1;ca<=t;ca++)
    {
        scanf("%d%d",&n,&m);
        memset(prob,0,sizeof(prob));
        for(int i=1;i<=2;i++)
        {
            int x; scanf("%d",&x);
            for(int j=1;j<=x;j++)
            {
                int a; scanf("%d",&a);
                prob[a]=i;
            }
        }
        int teamnum;
        scanf("%d",&teamnum);
        prize.clear();
        for(int i=1;i<=teamnum;i++)
        {
            char s[50];
            int x;
            scanf("%s%d",s,&x);
            prize[string(s)]=x;
        }

        for(int i=1;i<=n;i++)
        {
            da[i].solved.clear();
            da[i].rating.clear();
            scanf("%s%s",da[i].name,da[i].belong);
            da[i].sex=getch();
            int a,b; scanf("%d%d",&a,&b);
            for(int j=1;j<=a;j++)
            {
                int id; scanf("%d",&id);
                da[i].solved.push_back(id);
            }
            for(int j=1;j<=b;j++)
            {
                int rat; scanf("%d",&rat);
                da[i].rating.push_back(rat);
            }
            sort(da[i].rating.begin(),da[i].rating.end(),greater<int>());
        }
        cal();

        for(int i=1;i<=m;i++)
        {
            printf("%s %.3lf\n",da[i].name,da[i].score);
        }
    }
    return 0;
}
View Code