zoukankan      html  css  js  c++  java
  • 4040 EZ系列之奖金

    4040 EZ系列之奖金

     

    时间限制: 1 s
    空间限制: 64000 KB
    题目等级 : 钻石 Diamond
     
     
     
     
    题目描述 Description

    由于无敌的WRN在2015年世界英俊帅气男总决选中胜出,EZ总经理Mr.Lin心情好,决定给每位员工发奖金。EZ决定以每个人本年在EZ的贡献为标准来计算他们得到奖金的多少。

    于是Mr.Lin下令召开m方会谈。每位参加会谈的代表提出了自己的意见:“我认为学生a的奖金应该比b高!”Mr.Lin决定要找出一种奖金方案,满足各位代表的意见,且同时使得总奖金数最少。每位学生奖金最少为100元。

    输入描述 Input Description

    第一行两个整数n,m,表示学生总数和代表数;

    以下m行,每行2个整数a,b,表示某个代表认为第a号学生奖金应该比第b号学生高。

    输出描述 Output Description

    若无法找到合法方案,则输出“-1”;否则输出一个数表示最少总奖金。

    样例输入 Sample Input

    2 1

    1 2

    样例输出 Sample Output

    201

    数据范围及提示 Data Size & Hint

    80%的数据满足n<=1000,m<=2000

    100%的数据满足n<=10000,m<=20000

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 int rd[10001];
     5 int ans[10001];
     6 int a[10001][300]={0};
     7 int n,m;
     8 int mon;
     9 bool topsort()
    10 {
    11     int tot=0,k=0;
    12     int t;
    13     while(tot<n)
    14      {
    15          t=0;
    16          for(int i=1;i<=n;i++)
    17           {
    18               if(rd[i]==0)
    19                {
    20                    tot++;
    21                    t++;
    22                    mon+=100;
    23                    ans[t]=i;
    24                    rd[i]=0xfffffff;
    25                }
    26           }
    27           if(t==0) return false;
    28           mon+=k*t;
    29           k++;
    30           for(int i=1;i<=t;i++)
    31            {
    32                for(int j=1;j<=a[ans[i]][0];j++)
    33                 {
    34                     rd[a[ans[i]][j]]--;
    35                 }
    36            } 
    37      }
    38      return true;
    39 }
    40 void init()
    41 {
    42     int x,y;
    43     cin>>n>>m;
    44     for(int i=1;i<=m;i++)
    45      {
    46          cin>>x>>y;
    47          rd[x]++;
    48          a[y][0]++;
    49          a[y][a[y][0]]=x;
    50      }
    51 }
    52 int main()
    53 {
    54     init();
    55     mon=0;
    56     if(topsort())cout<<mon<<endl;
    57     else cout<<"-1";
    58     return 0;
    59 }
  • 相关阅读:
    Nginx 部署多个 web 项目(虚拟主机)
    Nginx 配置文件
    Linux 安装 nginx
    Linux 安装 tomcat
    Linux 安装 Mysql 5.7.23
    Linux 安装 jdk8
    Linux 安装 lrzsz,使用 rz、sz 上传下载文件
    springMVC 拦截器
    spring 事务
    基于Aspectj 注解实现 spring AOP
  • 原文地址:https://www.cnblogs.com/lyqlyq/p/6709972.html
Copyright © 2011-2022 走看看