zoukankan      html  css  js  c++  java
  • Reward 杭电 2647

    Problem Description
    Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards.
    The workers will compare their rewards ,and some one may have demands of the distributing of rewards ,just like a's reward should more than b's.Dandelion's unclue wants to fulfill all the demands, of course ,he wants to use the least money.Every work's reward will be at least 888 , because it's a lucky number.
     
    Input
    One line with two integers n and m ,stands for the number of works and the number of demands .(n<=10000,m<=20000)
    then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
     
    Output
    For every case ,print the least money dandelion 's uncle needs to distribute .If it's impossible to fulfill all the works' demands ,print -1.
     
    Sample Input
    2 1
    1 2
    2 2
    1 2
    2 1
     
    Sample Output
    1777
    -1
    题目大意:老板发工资,基本工资是888,要求前面的人要比后面的人多,问最少能发多少。如果满足不了要求输出-1
    思路:拓扑排序,,先判断有没有环,有环 的话输出-1,一开始我想着前面人的钱比后面人的多,和后面的人比前面的人多结果应该相同。。但是。。wa了N次。
    这个题目有两个坑:首相就是 2个人的工资可能相等,第二个就是必须到着来。因为第一个人的工资为基础工资,,也就是说可能会多个人是基础工资。。所以工资必须降序
    AC代码:
    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cstring>
    #include<vector>
    using namespace std;
    typedef long long ll;
    const int N=1E5+7;
    vector<int >ve[N];
    int re[N];
    int in[N];
    int main(){
        int n,m;
        while(~scanf("%d%d",&n,&m)){
            memset(re,0,sizeof(re));
            memset(in,0,sizeof(in));
            queue<int >que;
            
            for(int i=1;i<=m;i++){
                int x,y;
                scanf("%d%d",&x,&y);
                in[x]++;
                ve[y].push_back(x);
            }
            
            for(int i=1;i<=n;i++){
                if(in[i]==0){
                    que.push(i);
                }
            }
            
            int n1=0;
            ll sum=0;
            while(que.size()){
                int xx=que.front();
                que.pop();
                sum+=888+re[xx];
                n1++;
                for(int i=0;i<ve[xx].size();i++){
                    in[ve[xx][i]]--;
                    if(in[ve[xx][i]]==0){
                        re[ve[xx][i]]=re[xx]+1;
                        que.push(ve[xx][i]);
                    }
                }
            }
            if(n1!=n){
                puts("-1");
            }
            else {
                printf("%lld
    ",sum);
            }
            for(int i=1;i<=n;i++){
                ve[i].clear();
            }
        }
        return 0;
    }
     
     
  • 相关阅读:
    我在互联网的第一年
    变速变调原理与方法总结
    TIMIT语音库
    基于HTK语音工具包进行孤立词识别的使用教程
    Praat 音频分析 人工标注
    HTK源码学习总结
    HTK搭建语音拨号系统实验材料下载
    应用HTK搭建语音拨号系统4: 识别器评估
    应用HTK搭建语音拨号系统3:创建绑定状态的三音素HMM模型
    应用HTK搭建语音拨号系统2:创建单音素HMM模型
  • 原文地址:https://www.cnblogs.com/Accepting/p/11314515.html
Copyright © 2011-2022 走看看