Doing Homework again (贪心)

15 篇文章 0 订阅

Doing Homework again

Problem Description
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
Input
The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.

Output
For each test case, you should output the smallest total reduced score, one line per test case.

Sample Input
3
3
3 3 3
10 5 1
3
1 3 1
6 2 3
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4

Sample Output
0
3
5
题目大致意思:做完每门功课需要一天的时间,每门功课有最后的完成期限,若在完成期限之后做完则会扣除相应的分数,计算最小扣分为多少

/*这道题目应该算是贪心+哈希
思路:按照分数降序排序,若分数相等按时间降序排序。
     对于排序后的每门功课从完成期限那一天向前循环,若有空闲的天数,则可以完成;
     若直到第一天没有找到空闲的天数,则该门功课分数将会被扣除。*/

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node{
    int t; //最后期限
    int s; //分数
}num[1004];

int cmp(node a,node b) //排序
{
    if(a.s>b.s || a.s==b.s && a.t>b.t)
        return 1;
    else
        return 0;
}

int main()
{
    int t;
    int vis[1005]; //标记数组,若第i天有空闲,则vis[i]=0,反之v[i]=1;
    scanf("%d",&t);
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        int n,i,j;
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%d",&num[i].t);
        for(i=0;i<n;i++)
            scanf("%d",&num[i].s);
        sort(num,num+n,cmp);
        int ans=0;
        for(i=0;i<n;i++)  //核心代码
        {
            for(j=num[i].t;j>0;j--)
            {
                if(!vis[j])
                {
                    vis[j]=1;
                    break;
                }
            }
            if(j==0)
                ans+=num[i].s;
        }
        printf("%d\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
A motivational kick in the pants to get the most out of your life Have you got an itch? To start your own business, go to the North Pole, retrain, lose weight, get promoted, learn to play the ukulele? Or do you just have a nagging sense that there must be more to life? If there is something you really want to do, but secretly fear you'll never do it then you need this book. The original Stop Talking Start Doing helped readers to move from talking to doing. To climb into the ring and face their fears about making their thing happen. It helped readers to understand why they had fears and why starting was easier than they thought. It encouraged them to start somewhere, anywhere. The Stop Talking Start Doing Action Book will help you to identify where or what that starting point should be, and how to build from there to make your thing happen. It will help you to evaluate why you have procrastinated until now and identify the small steps you need to take to make it happen. But it will help you to plan beyond that. It will help you see how you can execute your idea through small, simple steps that are right for you, rather than one undefined, daunting task. Find sources of inspiration that work for you and learn how you can draw upon them as you go, draw confidence from previous experiences, and find the self-discipline you need to make swift decisions along the way. Identify your personal starting point Take the first steps to set your plan into motion Find your inspiration and self-discipline Build confidence in your quick decisions along the way Table of Contents PART 1 TICK TOCK PART 2 THE ITCH PART 3 FEAR AND REGRET PART 4 START PART 5 THE ART OF DECISION-MAKING PART 6 …AND ACTION

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值