解题报告 HDU1789 Doing Homework again

Doing Homework again

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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

题意:

  给出课程的deadline和超时所扣的分 做一个作业要一天 求出最少的扣分方案

错误思路:

  一开始想当然地 先对deadline按升序排序 再对相同deadline的按扣分多少按降序排序

  然后从头开始 当之后的数据deadline比已用天数小的时候 就+到sum里

  这个思路是不对的 我们从最后一组数据就能测试出他的问题 如果按这种思路

  排序后:1 2 3 4 4 4 6

      3 6 4 7 5 2 1

  那么我们做到第四个数据 之后的数据就全部都无法完成了 得出的结果是8

  但是这个case下的最优解其实是: 不做第一天的3和第四天的2 其他都可以完成 结果是5

正确思路:

  这里我用的是hash表的思路

  先按分数降序排列 然后从头开始加到时间表里

  表的4 放上数据7 意思是第四天完成7这个作业

  放5的时候冲突了 于是放到3 第三天完成5这个作业

  之后同理 如果无法放到表中 说明这个任务无法完成 加到sum里

ac代码:

其中的判定value大小的地方有垃圾部分 因为已经按降序排列 所以插入的时候没有比其中数据小的情况 懒得删了

 1 #include <iostream>
 2 using namespace std;
 3 int work;
 4 int sum=0;
 5 struct w
 6 {
 7     int dl;
 8     int score;
 9 }a[1005];
10
11 void sort(w *a)
12 {
13     for(int i=0;i<work-1;i++)
14     {
15         for(int j=i+1;j<work;j++)
16             if(a[j].score>a[i].score)
17             {
18                 w t=a[j];
19                 a[j]=a[i];
20                 a[i]=t;
21             }
22     }
23 }
24 void insert(int *timeset,int pos,int value)
25 {
26     if(timeset[pos]==0)
27         timeset[pos]=value;
28     else if(timeset[pos]>value&&(pos-1)>0)
29         insert(timeset,pos-1,value);
30     else if(timeset[pos]>value&&(pos-1)<=0)
31         sum+=value;
32     else if(timeset[pos]<=value)
33     {
34         int t=timeset[pos];
35         timeset[pos]=value;
36         if((pos-1)>0)
37             insert(timeset,pos-1,t);
38         else
39             sum+=t;
40     }
41 }
42 int main()
43 {
44     int N;
45     cin>>N;
46     for(int n=1;n<=N;n++)
47     {
48         sum=0;
49         cin>>work;
50         int maxdl=0;
51         for(int i=0;i<work;i++)
52         {
53             cin>>a[i].dl;
54             if(maxdl<a[i].dl)
55                 maxdl=a[i].dl;
56         }
57         for(int i=0;i<work;i++)
58             cin>>a[i].score;
59         int *timeset=new int[maxdl+1];
60         for(int i=0;i<maxdl+1;i++)
61             timeset[i]=0;
62
63         sort(a);
64
65         for(int i=0;i<work;i++)
66             insert(timeset,a[i].dl,a[i].score);
67
68         cout<<sum<<endl;
69     }
70     return 0;
71 }
时间: 2024-08-02 10:32:52

解题报告 HDU1789 Doing Homework again的相关文章

解题报告 之 POJ3057 Evacuation

解题报告 之 POJ3057 Evacuation Description Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time

hdu 1541 Stars 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有比它低层(或者同层)的或者在它左手边的星星数决定.计算出每个等级(0 ~ n-1)的星星各有多少颗. 我只能说,题目换了一下就不会变通了,泪~~~~ 星星的分布是不是很像树状数组呢~~~没错,就是树状数组题来滴! 按照题目输入,当前星星与后面的星星没有关系.所以只要把 x 之前的横坐标加起来就可以了

【百度之星2014~初赛(第二轮)解题报告】Chess

声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站,因此,笔者添加此条声明. 郑重声明:这篇记录<[百度之星2014~初赛(第二轮)解题报告]Chess>转载自 http://tiankonguse.com/ 的这条记录:http://tiankonguse.com/record/record.php?id=667 前言 最近要毕业了,有半年没做

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh童鞋的提醒. 勘误2:第7题在推断连通的时候条件写错了,后两个if条件中是应该是<=12 落了一个等于号.正确答案应为116. 1.煤球数目 有一堆煤球.堆成三角棱锥形.详细: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成三角形), 第四层10个(排列成三角形). -. 假设一共

[noip2011]铺地毯(carpet)解题报告

最近在写noip2011的题,备战noip,先给自己加个油! 下面是noip2011的试题和自己的解题报告,希望对大家有帮助,题目1如下 1.铺地毯(carpet.cpp/c/pas) [问题描述]为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有n 张地毯,编号从1 到n.现在将这些地毯按照编号从小到大的顺序平行于坐标轴先后铺设,后铺的地毯覆盖在前面已经铺好的地毯之上.地毯铺设完成后,组织者想知道覆盖地面某个点的最上面的那张地毯的

ACdream 1203 - KIDx&#39;s Triangle(解题报告)

KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description One day, KIDx solved a math problem for middle students in seconds! And than he created this problem. N

解题报告 之 CodeForces 91B Queue

解题报告 之 CodeForces 91B Queue Description There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue.

解题报告 之 POJ1226 Substrings

解题报告 之 POJ1226 Substrings Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings. Input The first li

解题报告 之 UVA563 Crimewave

解题报告 之 UVA563 Crimewave Description Nieuw Knollendam is a very modern town. This becomes clear already when looking at the layout of its map, which is just a rectangular grid of streets and avenues. Being an important trade centre, Nieuw Knollendam a