寒假作业第二组P&&Q&&R题解
P的题意是有M份作业,这些作业有不同的截止日期,超过截止日期完成,不同的作业有不同的罚分,求如何完成罚分最低。
首先,从截止日期最长的那个作业到截止日期,这些天数是固定的,所做的就是把这些作业填进这些天。很明显的贪心,把作业按从大到小罚分排序,罚分截止日期越近的放在前面,然后通过枚举把作业往时间轴里放,知道这些天数被填满。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
struct subject{
int point;
int time;
};
int compare(struct subject a,struct subject b)
{
if(a.point!=b.point)
{
if(a.point>b.point)
return ;
else return ;
}
else {
if(a.time<b.time)
return ;
else return ;
}
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
int m;
int sum=;
int flag[]={};
struct subject sb[];
int a[]={};
int b[]={};
scanf("%d",&m);
for(int j=;j<m;j++)
{
scanf("%d",&a[j]);
sb[j].time=a[j];
}
for(int h=;h<m;h++)
{
scanf("%d",&b[h]);
sb[h].point=b[h];
}
sort(sb,sb+m,compare);
for(int g=;g<m;g++)
{
for(int j=sb[g].time;j>=;j--)
{
if(!flag[j]&&j)
{
flag[j]=;
break;
}
if(!j)
sum+=sb[g].point;
}
}
printf("%d\n",sum);
}
return ;
}
Q的题意其实跟DOTA没啥关系,可以理解成回合制游戏,只不过每次都是敌人先攻击你,你的血量无限,不过你每次只能打对方一点血,对方有DFS(每次攻击你掉的血)和HP(血量)两个特征,求把他们打死,你消耗的最少血量。既然是贪心,就要排序,按DFS排还是按HP排呢,都不是,因为你优先要打的是,HP低&&攻击力强的敌人,所以应该优先打DFS/HP大的敌人。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
struct hero{
int dps;
int hp;
};
int compare(struct hero a,struct hero b)
{
if((a.dps*1.0/a.hp)>(b.dps*1.0/b.hp))
return ;
else return ;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int sum=;
struct hero a[];
for(int i=;i<n;i++)
scanf("%d%d",&a[i].dps,&a[i].hp);
sort(a,a+n,compare);
for(int j=;j<n;j++)
{
for(int h=j;h<n;h++)
{
sum+=a[h].dps*(a[j].hp);
}
}
printf("%d\n",sum);
}
return ;
}
R题,题意很简单,有n个机器,m个任务,每个机器和任务都对应着 time和level两个量,只有机器的时间和等级都大于等于任务时,才能完成任务,求完成任务的最大数量,多解考虑利润最多的情况,利润是任务的时间*500+等级*2;
因为任务的时间权重很高,所以可以直接忽略利润这个东西。
我本来的想法是,从最简单地任务开始(简单就是时间少且等级低,首要看时间)每个任务,都从最烂的机器(烂机器就是时间少,等级低)开始匹配,匹配上的机器用flag标记,结果超时了,确实,这么做太暴力,因为任务的简单和机器的烂是有联系的,特别是当他们被排好顺序的时候。最后借鉴了别人的方法。从最难的任务开始,然后先挑出一部分时间上满足的机器,然后再看等级。再下一个任务,因为排好序所以比上一个任务简单,可以继续用到上一次被挑出来的机器,还可以继续挑选机器,节省了时间。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
struct com{
int time;
int level;
};
int compare(struct com a,struct com b)
{
if(a.time!=b.time)
{
if(a.time>b.time)
return ;
else return ;
}
else return a.level>b.level;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
struct com mac[];
struct com task[];
int flag[]={};
int cnt=;
long long sum=;
for(int i=;i<n;i++)
scanf("%d%d",&mac[i].time,&mac[i].level);
for(int j=;j<m;j++)
scanf("%d%d",&task[j].time,&task[j].level);
sort(mac,mac+n,compare);
sort(task,task+m,compare);
for(int i=,j=;i<m;i++)
{
while(j<n&&mac[j].time>=task[i].time)
{
flag[mac[j].level]++;
j++;
}
for(int h=task[i].level;h<=;h++)
{
if(flag[h])
{
flag[h]--;
cnt++;
sum+=*task[i].time+*task[i].level;
break;
}
}
}
printf("%d %lld\n",cnt,sum);
}
return ;
}
寒假作业第二组P&&Q&&R题解的更多相关文章
- 寒假作业第二组C题题解
这道题题意很简单,主要是练习map的使用.看输入有三个数据,水果名,地名,和出现次数.再看输出,很容易想到map<string,int> string是水果,int是次数,那个地名怎么用m ...
- 寒假作业第二组E题题解
注意看题,注意看题,注意看题.重要的事情三遍感觉都不够.不怕大家笑话,这道题RuntimeError 9次,我一直以为是哪里越界了,结果最后发现的时候,真是无语了,题目里说了,所有的integer都不 ...
- Hdu1015&&寒假作业第二组I题
题意是A-Z对应1-26,然后给个目标数字和字符串,看看字符串里的某5个字符的组合能不能使v - w^2 + x^3 - y^4 + z^5 = target等式成立,其实多写几个循环也可以达到目的, ...
- FJUT寒假作业第二周C题解(位运算)
题目来源:http://210.34.193.66:8080/vj/Contest.jsp?cid=161#P2 题意比较好理解.如果直接按题目要求一步一解.一定超时.作为一个懒人也不会这么暴力一个肯 ...
- FJUT寒假作业第二周G题解快速幂
题目来源:http://210.34.193.66:8080/vj/Contest.jsp?cid=161#P6 题意:求n个数字的乘积对c取摸.主要就是有快速幂扩展到广义幂的过程. 首先题目 ...
- 寒假作业第二篇随笔(A+B)
Github链接:https://github.com/heihuifei/object-oriented A+B Format (20) Calculate a + b and output the ...
- 【GDKOI2014】JZOJ2020年8月13日提高组T3 壕壕的寒假作业
[GDKOI2014]JZOJ2020年8月13日提高组T3 壕壕的寒假作业 题目 Description Input Output 输出n行.第i行输出两个整数,分别表示第i份作业最早完成的时刻以及 ...
- 2016蓝桥杯省赛C/C++A组第六题 寒假作业
题意:现在小学的数学题目也不是那么好玩的. 看看这个寒假作业: □ + □ = □ □ - □ = □ □ × □ = □ □ ÷ □ = □ 每个方块代表1~13中的某一个数字,但不能重复. 比如: ...
- NOIP提高组2004 合并果子题解
NOIP提高组2004 合并果子题解 描述:在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消 ...
随机推荐
- RAC环境下控制文件损坏重建过程
处理过程参考了: https://blogs.oracle.com/Database4CN/entry/%E5%A6%82%E4%BD%95%E9%87%8D%E5%BB%BArac%E7%9A%84 ...
- codeforces 660D D. Number of Parallelograms(计算几何)
题目链接: D. Number of Parallelograms time limit per test 4 seconds memory limit per test 256 megabytes ...
- python 生成特定间隔数列的方法
(1)range() 和 xrange( )[python内置函数] range(开始,结束,间隔). 值得注意的是:生成数列最后一个数< 结束值. 返回结果类型:list,其中元素是integ ...
- MySQL交叉表处理_20160923
交叉表处理,在二维表中例如下面表 想把年月字段放到列字段,在sql中可以使用sum(if(条件,求和字段,null)) 函数来进行行列的转置 1.首先是上篇的年月字段在一列 SELECT city A ...
- 「LuoguP1725」琪露诺(dp 单调队列
题目描述 在幻想乡,琪露诺是以笨蛋闻名的冰之妖精. 某一天,琪露诺又在玩速冻青蛙,就是用冰把青蛙瞬间冻起来.但是这只青蛙比以往的要聪明许多,在琪露诺来之前就已经跑到了河的对岸.于是琪露诺决定到河岸去追 ...
- bzoj 2946 公共串 —— 后缀自动机
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2946 建出 n-1 个后缀自动机一起跑呗. 代码如下: #include<cstdio ...
- hdu 3625 Examining the Rooms —— 第一类斯特林数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625 学习斯特林数:https://blog.csdn.net/qq_33229466/article/d ...
- 百度地图API的第一次接触——右键菜单
1.初始化地图 var map = new BMap.Map("container"); var point = new BMap.Point(116.404, 39.915); ...
- WPF 中 UserControl作为另一个Process宿主到Window里, ErrorTemplate的默认红框没有出现
最近做WPF项目遇到一个问题, 我有2个process, 一个Process里只有Usercontrol, 另一个Process获取前一个Process中Usercontrol并host到当前的win ...
- PCL中有哪些可用的PointT类型(5)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=270 Narf36 - float x, y, z, roll, pitch ...