/********************************************************************************
倒不是什么太难的题,主要是细节太阴险了~具体见注释~
最后学校排排名31~这几场网络赛都相当给力啊~今年挺有戏的~
********************************************************************************/
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) ( (x) & ( (x) ^ (x - 1) ) )
//typedef long long LL;
typedef __int64 LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<LL>::iterator LI;
typedef set<int>::iterator SI;
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffff;
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
const int MAXN = 100004;
const LL MOD = 1000000007;
int test, n;
LL m, arr[MAXN];
inline LL llabs(LL x)
{
return x > 0 ? x : -x;
}
LL pow_mod(LL a, LL k)
{
LL r = 1;
while (k)
{
if (k & 0x1)
{
r = (r * a) % MOD;
}
a = (a * a) % MOD;
k >>= 1;
}
return r;
}
void ace()
{
int cas = 1;
int ncnt, max_id, min_id;
LL buf;
LL max_neg, min_pos;
LL two, tri, four;
for (scanf("%d", &test); test--; ++cas)
{
scanf("%d %I64d", &n, &m);
ncnt = 0;
max_neg = -INF_INT;
for (int i = 0; i < n; ++i)
{
scanf("%I64d", arr + i);
if (arr[i] < 0)
{
++ncnt;
if (max_neg < arr[i])
{
max_id = i;
max_neg = arr[i];
}
}
}
if (ncnt & 0x1) //如果有奇数个负数的话,尽量把最大的负数转化为正数
{
if (m > llabs( arr[max_id] ))
{
m -= llabs( arr[max_id] );
arr[max_id] = 0;
}
else
{
arr[max_id] += m;
m = 0;
}
}
if (m > 0) //如果有0存在的话,先尽量把0加为1
{
for (int i = 0; i < n && m > 0; ++i)
{
if (0 == arr[i])
{
++arr[i];
--m;
}
}
}
if (m > 0) //如果有1存在的话,尽量把1加为2
{
for (int i = 0; i < n && m > 0; ++i)
{
if (1 == arr[i])
{
++arr[i];
--m;
}
}
}
if (m > 0) //如果有2存在的话,尽量把2加为3
{
for (int i = 0; i < n && m > 0; ++i)
{
if (2 == arr[i])
{
++arr[i];
--m;
}
}
}
//开始变了,不能老是加最小的~不信自己列几个数试试~
two = tri = four = 0;
if (m > 0) //还剩下的操作尽量去添3
{
min_pos = INF_LL;
for (int i = 0; i < n; ++i)
{
if (arr[i] > 0 && arr[i] < min_pos) //在给定的集合中找最小的正数,显然应该>=3
{
min_id = i;
min_pos = arr[i];
}
}
tri = m / 3;
if (1 == m % 3) //如果还剩下1个操作,那么考虑将整个集合中最小的数+1
{ //这个地方阴险无比啊
if (tri > 0) //如果有3的话,显然把一个3->4
{
--tri;
++four;
}
else //否则把集合中最小的元素+1
{
++arr[min_id];
}
}
else if (2 == m % 3) //如果还剩下2个操作,那么就添一个2上去
{
++two;
}
}
buf = 1;
for (int i = 0; i < n; ++i)
{
buf = (buf * arr[i]) % MOD;
}
buf = (buf * pow_mod(2, two)) % MOD;
buf = (buf * pow_mod(3, tri)) % MOD; //tri必然很大~当然二分幂~
buf = (buf * pow_mod(4, four)) % MOD;
printf("Case %d: %I64d\n", cas, buf);
}
return ;
}
int main()
{
ace();
return 0;
}
相关推荐
什么是PMOS?什么是NMOS?两者有什么区别?
这个电压差被称为阈值电压(Vth),通常为0.7V至2V(低压NMOS)或4V至10V(功率NMOS)。当Vgs(栅极-源极电压)大于Vth时,沟道中的电子被吸引到栅极下方,形成导电通路,使电流可以从漏极流向源极。NMOS与PMOS的结构类似,都由三大部分组成:栅极(Gate)、源极(Source)和漏极(Drain)。由于NMOS在开启时,电子是主要的载流子,电子的迁移率比空穴高,因此NMOS通常具有更低的导通电阻(Rds(on)),这使其成为高速开关电路中的首选。它的沟道由电子(负载子)传导。
hdu4038——成都网络赛1008
这两天跟1008过不去额。。。老是被一些2b类型的错误卡。。。。 周六1008因为函数参数里一个long long的失误悲剧,周日的1008因为没有添加新生成的数到数组中一直WA。。。。这后台数据够强的~~ 思路:如果有奇数个负数,找出最大的那个,一直往上调,到0为止,然后把尽可能把0变成1,然后尽可能把1变成2,2->3.。。。到最后剩下的m求pow(3,m/3)然后填到数组里排序(注...
从零开始构建高精度称重系统:ADS1232硬件设计与软件调优实战
本文详细介绍了如何基于TI的ADS1232 24位ADC芯片构建高精度称重系统,涵盖硬件设计、软件调优及校准算法。通过优化电源设计、PCB布局和卡尔曼滤波算法,实现毫克级测量精度,适用于工业自动化和实验室等高要求场景。
Stone----HDU_4308----模拟+贪心+一点点二分的思想
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4038 /* Author:Bob Lee 2012.8.30 ======================================== 这题是2011成都赛区的网络题,而且号称是里面最水的一道题(但是我还是琢磨来好久) 题目的意思很简单给你n个整数,然后有两种操作让你选择 1.在某一个数
KV Cache 详解:新手也能理解的 LLM 推理加速技巧
(Autoregressive)生成的,即每次生成一个 token,然后将其作为输入继续生成下一个 token。:如果序列太长,超过了 KV Cache 的存储限制,就需要丢弃最早的 tokens(类似滑动窗口)。时,每次只会生成一个新 token,然后再把这个 token 作为输入继续生成下一个 token。,只缓存计算过的 K,VK, V,每次只计算新 token 的 K,VK, V,从而提升推理效率。:如果输入的 prompt 发生变化,之前的 KV Cache 不能复用,必须重新计算。
Spyglass实战指南:跨时钟域同步方案深度解析
本文深度解析了Spyglass在跨时钟域同步方案验证中的实战应用。通过真实案例阐述了亚稳态的危害,并详细介绍了从基础的两级同步器到复杂的异步FIFO与握手协议等八大同步方案,以及如何利用Spyglass进行有效配置、检查与问题排查,为提升芯片设计可靠性提供系统性的避坑指南。
hdu4038贪心(最快上升倍率,好题)
题意: 给你n个数,然后有两种操作 1.给其中的一个数+1,2.在序列里面增加一个1,然后给你一个m,表示进行了m次操作,最后问你操作之后所有数乘积最大是多少? 思路: 徒弟给我的一个题目,感觉不错,这个题目细节比较多,至于难度,感觉还行,值得做一做,大体思路就是模拟,有点贪心的意思,首先我们要看看负数的个数,如果是奇数个,那么要把其中的一个绝对值最小的负数,也
OpenClaw 子代理配对失败问题分析与解决方案
OpenClaw子代理配对失败问题分析与解决方案 问题核心在于agent设备权限不足,仅有operator.approvals权限而缺少operator.admin权限,导致子代理启动时形成权限死锁。本文提供三种解决方案: 直接编辑设备配对文件(推荐):修改本地JSON文件,为agent设备添加完整operator.admin权限,操作简单快捷。 标准重新配对流程:删除现有agent设备后重新配对,通过正常审批流程获取完整权限,符合系统安全设计。 修改源码降低权限要求(仅限开发环境):调整子代理代码避免强制
hdu 4038 Stone(贪心模拟)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4038 Stone Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 2535 Accepted Submission(s): 63
使用 MATLAB/Simulink 进行锂电池SOC估算和等效电路建模
本文介绍了使用MATLAB/Simulink进行锂电池SOC估算与等效电路建模的方法。首先阐述了SOC估算和等效电路模型的背景及重要性,然后详细讲解了系统结构设计的主要组成部分,包括电池模块、SOC估算模块(采用卡尔曼滤波器算法)和等效电路模型等。文章重点分步说明了建模过程:从创建Simulink项目、搭建电池模块,到实现SOC估算算法(提供示例代码),构建等效电路模型(Thevenin模型示例),添加传感器模块,最后设置仿真参数。通过仿真运行分析关键指标(SOC估算误差、电压偏差等)来评估模型性能,为锂电
嵌入式工程师必学(118):MCU的硬件定时器和中断
大多数微处理器都有一个或多个可编程硬件定时器,这些定时器包括对中断的支持。可以有不同类型的计时器,用于不同的应用程序。例如,LPC1768 具有四个 32 位通用定时器、一个看门狗定时器、一个重复中断定时器、一个系统滴答定时器、一个正交编码器接口、6 个 PWM 输出和一个支持中断的实时时钟。硬件定时器用于计时和计数作,允许处理器在 timer 进程运行时继续执行其他进程。硬件定时器是一种使用 clock 信号来增加 register 的电路。
HDU 4038 Stone
哎,当时比赛的时候各种胡思乱想,竟然把这道题给A了。 这题的题意就是给一序列的数,有两种操作,一种是把序列中某个数的值加1,要么在序列中增添一个数为1,然后给出操作数,最后要求这些数的乘积最大,求出这个乘积。 做这个题要考虑的细节很多,首先要把负数的个数求出,如果为奇数,那么要把最大的那个负数尽量加到0,就相当于转化为偶数的情况了,然后负数就不用在管了,这时候,序列中如果有0的话,很显然他们相...
OpenClaw 保姆级 window部署
OpenClaw 保姆级 window部署 养龙虾
HDU 4038 Stone (模拟 快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4038 这个题目wa的数次,数据非常严格,还有所有数据类型都要为long long的比较好 这个题目首先要知道基本的数学知识 首先判断负数的个数,如果为偶数,那么负数不用管了,最后乘起来就OK了 如果负数个数是奇数,那么就把尽可能的在m满足的情况下让这个负数向0靠近 完成之后把所有的0在m的允
老版QQ原生表情gif动态
这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
HDU-4038-Saving Princess Claire
HDU-4038-Saving Princess Claire http://acm.hdu.edu.cn/showproblem.php?pid=4308 给出的地图中,Y为起点,C为终点,#点不能通过,所有的P为互通的传送门,故可将所有的P看作同一个点 BFS即可,从Y点开始搜,搜到的第一个P点为最短的,此时将其他的P点都压入栈内,因为所有的P点都是等价的 #include #incl
IMSL CNL 7.0.0 (x86-64)Crack
IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件
hdu 4038 Stone
思路: 如果负数的个数为偶数则不必改变,为奇数就将最大负数变为正; 对于正数,尽量将1,2变为3即可。 代码如下: 1 #include<cstring> 2 #include<iostream> 3 #include<cstdio> 4 #include<algorithm> 5 #include&...
迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)
迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)
hdu 4038 stone
http://acm.hdu.edu.cn/showproblem.php?pid=4038 这题的题意就是给一序列的数,有两种操作,一种是把序列中某个数的值加1,要么在序列中增添一个数为1,然后给出操作数,最后要求这些数的乘积最大,求出这个乘积。 做这个题要考虑的细节很多,首先要把负数的个数求出,如果为奇数,那么要把最大的那个负数尽量加到0,就相当于转化为偶数的情况了,然后负数就不用...
成都1008 hdu4038
/* 题意:给一些数,每次可以从两种操作先一个操作:1、加个元素1 2、对某个元素加1。问M次操作后,最大的乘积是多少(对数取模) 分析:奇数个负数时,先选一个最大的负数,不断加,尽量让它变正;否则把所有0变为1;然后把所有1变为2;接着把所有2变成3 (注意当
HUD 4038
好像是成都赛的题目,看了一下,蒙了,规律题,比赛题和平时的练习题真的差太远,努力。 http://acm.hdu.edu.cn/showproblem.php?pid=4038 看了一下讨论,最后还是做出来了,骄傲一下。 #include #include #include #include using namespace std; typedef
hdu 4038 模拟+贪心 Stone
题意: 给一个数列,可以对这数列进行两种操作:A.使其中的一个数加1;B.增加1到这个数列。要求这个数列的乘积最大。 思路:贪心+模拟。 我觉得不够清晰。再理一遍。 1. 负数个数为奇数的时候我们把最大的负数变成0; 2.0是我们在这题当中很讨厌的东西(其他题也有卡0的,比如0!= 1,1对1的逆元是0),所以我们先将所有的精力集中对付0。
HDU/HDOJ 4038 2011成都赛区网络赛H题
Stone Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 130 Accepted Submission(
HDU4038-Stone(思维题)
Stone Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 2267 Accepted Submission(s): 568 Problem Description Given an array of int
6442



被折叠的 条评论
为什么被折叠?



