zoukankan      html  css  js  c++  java
  • XidianOJ 1120 Gold of Orz Pandas

    题目描述

    Orz Panda is addicted to one RPG game. To make his character stronger, he have to fulfil tasks to get EXP for higher level.At first he accepted all the tasks.But after he read rules carefully, he realized that what he has done was stupid.
    Rule:
    Every task costs 1 time interval.
    Every task has a dead line.If you can't finish it on time ,you have to pay the same amount of gold as the EXP given by this task.

    Orz Panda wants to know the minimum amount of gold he has to pay.

    输入

    The first line has one integer n, tell you how many tasks Orz Panda has accepted.
    The second line has n integers ti separated by blank, represent for the ith task's dead line.
    The third line has n integers ei separated by blank, represent for the
    EXP given by the ith task.
    (1 <= n, ti, ei <= 1000)

    输出

    One integer for the minimum amount of gold Orz Panda has to pay.

    --正文
    第一想法就是贪心,想了一想按照价值排好来贪好像是对的,试了一下果然如此
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    
    struct TaskNode{
        int DeadLine;
        int Value;
    };
    struct TaskNode Task[1001];
    int used[1001];
    bool cmp(struct TaskNode t1,struct TaskNode t2){
        if (t1.Value == t2.Value) return (t1.DeadLine < t2.DeadLine);
        return t1.Value > t2.Value;
    }
    
    int main(){
        int n;
        while (scanf("%d",&n) != EOF){
            int i;
            for (i=1;i<=n;i++){
                scanf("%d",&Task[i].DeadLine);
            }
            for (i=1;i<=n;i++){
                scanf("%d",&Task[i].Value);
            }
            sort(Task+1,Task+1+n,cmp);
            int Ans = 0;
            memset(used,0,sizeof(used));
            for (i=1;i<=n;i++){
                int nowT = Task[i].DeadLine;
                while (nowT > 0 && used[nowT]) nowT--;
                if (nowT == 0) {
                    Ans += Task[i].Value;
                } 
                else used[nowT] = 1;
            } 
            printf("%d
    ",Ans);
        }
        return 0;
    }
  • 相关阅读:
    技术牛人在阿里内网的公开信:“王坚,你为什么要放弃”
    hadoop日志【6】----mahout的速度
    基于命令行的mahout软件0.8版本Canopy算法分析的数据处理流程
    WolframAlpha
    颠覆编程方式的感知编码:Wolfram雄心勃勃的全新计算模式
    Autolayout及VFL经验分享
    IOS7 Text View 截断的问题解决
    Discuz 首页图文列表实现
    UIResponder详解
    IOS开发之----四舍五入问题
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/6153737.html
Copyright © 2011-2022 走看看