杭电oj1789 Doing Homework again(贪心与队列完美碰撞)

杭电OJ 1074:Doing Homework 这个题目的难点是状态压缩和DP,详细的解题过程请参考http://www.cnblogs.com/rain-lei/archive/2012/08/04/2623314.html和http://blog.sina.com.cn/s/blog_8338b9050100vvpa.html两篇文章。 C++代码: #include #include const int MAX=1<<15; cons 阅读详情

Doing Homework again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8877    Accepted Submission(s): 5234



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<queue>
#include<algorithm>
using namespace std;
priority_queue<int ,vector<int>,greater<int> >q;//进入队列都会从小到大排 注意:固定格式 
struct act
{
	int day;//最后期限几天后交作业 
	int score;//不交作业扣的分数 
}arr[10000];
bool cmp(act x,act y)
{
	if(x.day==y.day)
	return x.score>y.score;
	else
	return x.day<y.day;//肯定要写期限小的作业而且如果期限小的话要写扣的分大的 
}
int main()
{
	int T,n,i;
	scanf("%d",&T);
	while(T--)
	{
	while(!q.empty())//因为要有好多测试数据,所以队列要清空 注意:固定格式 
	{
		q.pop();
	}
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d",&arr[i].day);//因为题目要求 
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&arr[i].score);
		}
		sort(arr,arr+n,cmp);//按照贪心思想排序 
	int sum=0;
	for(i=0;i<n;i++)
	{
		if(q.size()<arr[i].day)//q.size()代表的是开始写作业时当天的天数如果还没达到天数先存到队列中按从小到大 
		{
			q.push(arr[i].score);
		}
		else//否则要比较扣分大小输出扣分小的当替罪羊 
		{
			int x=q.top();
			if(x<arr[i].score)
			{
				q.pop();
				q.push(arr[i].score);
				sum=sum+x;
			}
			else
				sum=sum+arr[i].score;
		}
	}
	printf("%d\n",sum);
	}
	return 0;
}

Codex接入CCSwitch:本地代理与模型路由配置指南 在AI编程工具链中,本地代理与模型路由是连接智能体与模型服务的核心桥梁。Codex作为OpenAI推出的编程智能体,虽然具备强大的仓库理解和自主编码能力,但其默认模型链路固定,导致在多模型切换、内网统一管理及成本控制上存在天然瓶颈。CCSwitch正是为解决这一痛点而生的本地代理工具,它通过OpenAI兼容协议将Codex的请求透明转发至DeepSeek、通义千问等第三方模型服务,使模型切换如同点击按钮般简单。本文从本地代理和模型路由器的基础原理切入,系统讲解Codex与CCSwitch的安装配置、模型ID 阅读详情

相关推荐

RT-Thread Studio使用笔记(四):带片外Flash(W25Q128)的OTA(YModem)

前言 在学习OTA之前,请先参考上两篇博客写的关于SPI设备及W25Q128的使用方法,传送门: https://blog.youkuaiyun.com/tigerots/article/details/107423633 https://blog.youkuaiyun.com/tigerots/article/details/107933991 如何使用OTA 一. 制作BootLoader 打开Bootloader 在线获取地址,注册,并根据RT-thread官方文档生成BootLoader,官方文档已经写的很清楚,再此

tigerots的专栏 4008

杭电OJ 1789(贪心)

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9782    Accepted Submission(s): 5726 Problem Description Ignat

mengxiang000000 2301

深入解析组合逻辑环(combinational loop)的成因与解决方案

本文深入解析了数字电路设计中组合逻辑环(combinational loop)的成因与危害。通过边沿检测和中断轮询(round_robin)仲裁器等实例,揭示了代码如何意外形成环路,并对比了插入触发器、重构逻辑以及状态机思维三种核心解决方案,帮助硬件工程师从根本上避免这一常见设计陷阱,确保电路稳定可靠。

weixin_28278377的博客 313

杭电OJ1789、南阳OJ236(贪心法)解题报告

杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/problem.php?pid=236 1、最简单的贪心法是只有一个东西需要考虑(如安排会场,只需要将 "时间" 进行排序),   即使需要考虑两个,也有一个明显的先后顺序(比如应先考虑开...

aiyuneng5167的博客 176

基于小波变换的信号降噪处理及仿真研究_信号处理方法推荐--1(转载自用,侵删)...

综述作者:aresmiki链接:https://www.zhihu.com/question/23701194/answer/167005497来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。非平稳信号处理应该是现在信号处理技术最新的也是最热的研究方向了,信号处理方法从最早的时域统计到傅里叶变换的频域分析,是人们认识信号本质的一次巨大飞跃,给了分析人员换个角度看世界的...

weixin_32144483的博客 1249

AUTOSAR TcpIp模块 以太网配置开发2

someip协议之tcpIp协议

汽车电子电气 1085

【杭电oj】1789 - Doing Homework again(贪心,并查集)

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10545    Accepted Submission(s): 6179 Problem Description Igna

wyg1997 806

5.6华为OD机试真题 新系统 - 匹配命令行前缀关键字 (Java/Py/C/C++/Js/Go)

5.6华为OD机试真题 新系统 - 匹配命令行前缀关键字本文整理华为 OD 机试新系统机考真题库,涵盖高频考点精析与完整题目内容,提供 C 语言、Java、C++、Python、Go、JavaScript 多语言源码实现,搭配详细解题思路讲解,并支持在线 OJ 刷题练习,助力高效备考华为 OD 机试新系统。

算法大师! 2129

【ACM】杭电OJ 1789(Doing Homework again)

 http://acm.hdu.edu.cn/showproblem.php?pid=1789 cmp函数: 先按扣分由多到少进行排序,然后如果遇到扣分一样的,则先做时间少的。 vis数组: 最要的事,放在它的截至日期那一天去做,然后,之后如果有相同的天数,则往前找是否有空余的天数,没有的话就把扣的分值加入sum #include &lt;iostream&gt; #include &...

( :3 ) 396

PICO640红外探测器配置模块verilog

Ulis pico 640红外探测器配置模块

Go Forward Forever! 2032

【笔记篇】Davinci Configurator OS模块(下)

AUTOSAR OS的配置项和Vevtor MICROSAR OS的特性

weixin_47571898的博客 1157

杭电1789贪心java实现

题意: 问题描述 伊格内修斯有很多功课要做。每个老师都会给他一个交作业的截止日期。如果在截止日期之后提交作业,老师会减少他的最终考试成绩。现在我们假设每个人做功课都需要一天的时间。所以希望你帮助他安排作业的次序,以尽量减少分数。 输入 输入包含多个测试用例。输入的第一行是一个整数T,即测试用例的数量。 T测试用例如下。 每个测试用例都以一个表示作业数量的正整数N(1 &lt;= N &lt;= ...

bigsai 2831

linux v3h平台开发系列详解(GMSL摄像头篇):1.11 解串器MIPI 1.5G高速率特殊deskew配置

解串器max96712 deskew配置

xian18809311584的博客 1775

杭电1789—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 ...

诗鸩的博客 307

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU OJ 1074: Doing Homework

HDU OJ 1074: Doing Homework(状压DP)序言: 关于DP的题目已经做了不少了,但是对于一些特殊的DP还是掌握不佳,今天啃了一道关于状态压缩的DP题,感觉挺有意思。Problem Description: Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h

ajaxlt的博客 407

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

杭电1789

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 题目大意:一个美女回学校了,但是作业没有做。现在每一个老师都给她交作业的最后时间,而且每一天只能完成一个作业。如果没有在老师给的最后时间里完成作业,那么就会被罚学分。她想让你安排她的作业时间,让她的学分被罚的少一点。要是你做的好会有神秘大奖。 解题思路: 1、作业只要在最后时间之前完成就可以

qq_34796437的博客 546

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

杭电1789 Doing Homework again(贪心)

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6961    Accepted Submission(s): 4145 Problem Description Ignatius

听自己心跳的声音 999

杭电OJ 1789:Doing Homework again

经典的贪心问题,先按照作业的扣除分数从大到小排序,如果分数相同则按截至日期从小到大排序。然后根据day判断哪些作业可以被安排。注意:for循环中如果存在一个作业符合条件就要跳出循环(因为每天只能安排一个作业)。 C++代码: #include #include using namespace std; const int N=1001; struct homework{ int deadli

708

杭电 1789(贪心思维练习)

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 th...

PengWei Yang 278

HDOJ 1074 Doing Homework (DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 思路:暴力。但是N=15,15!的暴力必然超时。问题为求完成N个作业后的最短罚时,考虑如果知道N-1个的最短罚时,能否求出N个作业的最短罚时,发现可行,把N个作业是否完成用二进制表示,则复杂度降为(2^N)。 输出路径,网传的很多代码都是错的,数据不够强。要输出的字典序最小,倒着找必须遍历所...

alternater的博客 246

杭电1789贪心

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10545    Accepted Submission(s): 6179   Problem Description Ignatius ha...

hhdmw的博客 301

杭电ACM1074——Doing Homework~~状态压缩DP

题目的意思:N门课程有作业,一个时间是最迟交的时间,一个是需要耗费多少时间来完成,到了期限,迟交多少,就扣多少分,求扣最少分的做作业的顺序。 N小于等于15,可以枚举所以的情况,数的二进制来表示各种情况。 对于集合编码成整数,可以看我的另一篇博客:点击打开链接

XD 1313

hdoj2007(java)平方和与立方和

平方和与立方和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 139859    Accepted Submission(s): 44757 Problem Description 给定一段连续的整数,求出他们中所有

GoodLuckAC的博客 2338

hdoj2023(java)求平均成绩(二维数组+一维数组+格式问题+行转化列)

求平均成绩 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 100836    Accepted Submission(s): 23407 Problem Description 假设一个班有n(n   I

GoodLuckAC的博客 1729

hdoj 2020 (java)绝对值排序(Math.abs()函数应用以及数组冒泡排序)

绝对值排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 64703    Accepted Submission(s): 31130 Problem Description 输入n(n   In

GoodLuckAC的博客 1559

hdoj2011 (java)多项式求和

多项式求和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 65082    Accepted Submission(s): 37387 Problem Description 多项式的描述如下: 1 - 1/2 +

GoodLuckAC的博客 1480
上一篇: nyoj448寻找最大数(贪心)
下一篇: 小程序员都来看看吧
JINKELA_
博客等级 码龄11年 75粉丝 178原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值