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\n",Ans);
    }
    return 0;
}
时间: 2024-10-23 06:16:28

XidianOJ 1120 Gold of Orz Pandas的相关文章

XidianOJ 1195 Industry of Orz Pandas

--正文 贪心 排序好慢慢找就好 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; int a[20001],b[20001]; int n,m,x; int main(){ while (scanf("%d %d %d",&n,&m

XidianOJ 1123 K=1 Problem of Orz Pandas

题目描述 One panda named orz is playing a interesting game, he gets a big integer Num and an integer K. In this game, he can exchange two single numbers in Num. For example, he can get 1243 from 3241 by exchange 1 and 3.But orz can exchange at most K tim

BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <= 400) differe

Orz_panda cup I题 (xdoj1117) 状压dp

Orz_panda cup I题 (xdoj1117)  状压dp 1117: Insert Orz Pandas 时间限制: 2 Sec  内存限制: 128 MB提交: 15  解决: 5[提交][状态][讨论版] 题目描述 Orz panda emotion is a famous emotion in XDU/ACM-ICPC QQ groups.Big Big Xi loves to create new Orz panda emotions.Now he has a matrix w

用pandas分析百万电影数据

用pandas分析电影数据 Lift is short, use Python. 用Python做数据分析,pandas是Python数据分析的重要包,其他重要的包:numpy.matplotlib . 安装pandas(Linux, Mac, Windows皆同): pip install pandas 电影数据来源:http://grouplens.org/datasets/movielens/ 下载数据文件解压,包含如下4个文件: users.dat 用户数据 movies.dat 电影数

pandas pivot_table 活学活用实例教程

pandas pivot_table 活学活用实例教程 导入相关数据分析的库 首先进行commentTime时间进行数据预处理 查看数据类型信息 最简单的透视表 直接敲击该函数,在notebook中可以查看该函数的参数 多个索引列 特定列的统计 规定特定的聚合函数 传入多个聚合函数 传入columns参数 生成的DataFrame可以导出excel或csv文件 修改index中的数据类型,显示完整的索引列 传入fill_value参数,处理缺失值 设添加margins参数,定margin_nam

数据分析处理库pandas

# pandas_1 import pandas food_info = pandas.read_csv("food_info.csv") #print(type(food_info)) print (food_info.dtypes) ''' NDB_No int64 Shrt_Desc object Water_(g) float64 Energ_Kcal int64 Protein_(g) float64 Lipid_Tot_(g) float64 Ash_(g) float64

一些Pandas常用方法

Series(列)方法describe(),对于不同类型的变量的列,有不同返回值(http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html) >>> s = pd.Series([1, 2, 3]) >>> s.describe() count 3.0 mean 2.0 std 1.0 min 1.0 25% 1.5 50% 2.0 75% 2.5 max 3

Pandas学习之常用函数详解

本文和大家分享的主要是Pandas库常用函数相关内容,一起来看看吧,希望对大家学习Pandas有所帮助. 1. DataFrame 处理缺失值 pandas.DataFrame.dropna df2.dropna(axis=0, how='any', subset=[u'ToC'], inplace=True) 把在ToC列有缺失值的行去掉 2. 根据某维度计算重复的行 pandas.DataFrame.duplicated print df.duplicated(['name']).value