poj2586Y2K Accounting Bug

Y2K Accounting Bug POJ2586 Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5559   Accepted: 2712 Descripti 阅读详情

背景:再做这道题的时候,我严重怀疑我的英语能力,o(︶︿︶)o 唉,翻译了一个多小时。

思路:由于本题情况比较少,所以可以直接枚举出所有的情况,首先要找出五个月中最少亏损月份,然后就开始枚举出五种情况,最后输出即可。

#include <stdio.h>
void print(int n)
{
    if(n<0) printf("Deficit\n");
    else printf("%d\n",n);
}
void YinKui(int m,int s,int d)
{
    int n=0;
    if(m==1) n=10*s-2*d;
    else if(m==2) n=8*s-4*d;
    else if(m==3) n=6*s-6*d;
    else if(m==4) n=3*s-9*d;
    else n=-1;
    print(n);
}
void Deficit_Month(int s,int d)
{
    int m;
    if(d>4*s) m=1;
    else if(d*2>3*s) m=2;
    else if(d*3>2*s) m=3;
    else if(d*4>s) m=4;
    else m=5;
    YinKui(m,s,d);
}
int main(void)
{
    int s,d;
    while(scanf("%d %d",&s,&d)==2)
        Deficit_Month(s,d);
    return 0;
}

然后看了同学的代码,发现也可以用贪心算法。

下面附同学的代码

#include<stdio.h>  
int a[15];  
int main ()  
{  
    int s,d;  
    while (scanf("%d%d",&s,&d)==2)  
    {  
        int sum=0;  
        int i,j;  
        for(i=5;i>=0;i--)       //一定要写成i>=0   若写成i>0可能出现一种情况i=1的时候sum>0 然后由于i>0退出了  sum仍然>0   
        {                      //写成i>=0 则上面那种情况变成i=1时sum>0,i=0时sum<0 break   
            sum=i*s-(5-i)*d;  
            if(sum<0)break;  
        }  
        for(j=0;j<i;j++)  
            a[j]=s;  
        for(j=i;j<5;j++)  
            a[j]=-d;  
        for(i=5;i<12;i++)  
        {  
            a[i]=a[i-5];  
            sum+=a[i];  
        }  
        if(sum>0)  
        printf("%d\n",sum);  
        else printf("Deficit\n");  
    }  
    return 0;  
}  


【信息学奥赛一本通】1215:迷宫(bfs版) 同时当Extense处在某个格点时,他只能移动到东南西北(或者说上下左右)四个方向之一的相邻格点上,Extense想要从点A走到点B,问在不走出迷宫的情况下能不能办到。每组测试数据的第1行是一个正整数n(1≤n≤100),表示迷宫的规模是n×n的。接下来是一个n×n的矩阵,矩阵中的元素为‘再接下来一行是4个整数ha,la,hb,lb,描述A处在第ha行, 第la列,B处在第hb行, 第lb列。一天Extense在森林里探险的时候不小心走入了一个迷宫,迷宫可以看成是由n×n的格点组成,每个格点只有2种状态,. 阅读详情

相关推荐

用Cloudflare Worker搭建你的私人Gemini Pro API

文章介绍如何通过开源项目gemini-cli-openai将谷歌Gemini模型转换为兼容OpenAI API的服务,解决Gemini CLI的三大使用障碍:网络访问、命令行操作和生态整合问题。部署流程主要包括获取Google OAuth2凭证、配置Cloudflare Worker项目并设置KV存储,最终可在CherryStudio等图形客户端中调用Gemini。该方法利用Cloudflare全球网络实现加速访问,同时保持认证信息安全可控。

Hsiao的二进制生活 1683

POJ2586-Y2K Accounting Bug

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 题意比较难懂,其实只要读懂题意,就很简单了。 /* Author: Exp Date: ...

ζёСяêτ - 小優YoU 9127

【亲测】ubuntu20.4 安装CUDA11.8

一步一步搭建C++ CUDA CUDNN TENSORRT OPENCV DNN ONNXRUNTIME推理环境

weixin_40950590的博客 3894

Poj2586(java实现)

DescriptionAccounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. All what they remember is that MS Inc. posted a sur

peachli 670

Zephyr OS实战指南:从入门到精通物联网开发

本文提供了一份详尽的Zephyr OS实战指南,涵盖从开发环境搭建到物联网应用开发的全过程。文章详细介绍了如何利用Zephyr OS进行线程管理、设备驱动开发、低功耗设计以及蓝牙通信,并通过具体代码示例帮助开发者快速掌握这一专为物联网设备设计的开源实时操作系统,实现从入门到精通的跨越。

weixin_29201933的博客 546

Halcon工业相机开发全流程:从SDK配置到实时图像采集(C++版)

本文详细介绍了使用C++进行Halcon工业相机开发的完整流程,从SDK配置到实时图像采集的实现。涵盖环境搭建、设备初始化、回调机制、参数控制等关键环节,并提供异常处理和实战案例,帮助开发者快速掌握工业视觉系统的开发技巧。

weixin_33728268的博客 512

【水题】POJ 2586 Y2K Accounting Bug

这段时间要沉迷刷题一段时间了,就让优快云陪我一起吧! 一、题目大意 这道题难就难在题目上,题目读懂了,这其实就是一道水题,不瞒大家说,我就没读懂。 其实意思也很简单,就是一个公司,每个月要么盈利s元,要么亏损d元,而且要保证在一年中任意连续5个月的营业额是亏损的,问一年中的盈利情况,如果盈利,则输出最大可能的盈利数额,如果亏损,则直接输出Deficit。 二、题目思路以及AC代码 在这里我就...

Johnson的博客 281

武汉理工大学数据结构综合实验——连连看游戏综合实践

文章目录实验目的主要仪器设备及耗材一、实验要求二、分析与设计(非线性结构)1.数据结构的设计2.核心算法设计一条直线消子两条直线消子三条直线消子初始化游戏地图搜寻路径提示和重排3.测试用例设计4.测试效果总结 实验目的 (1)线性结构实验目的 调研连连看游戏,了解连连看游戏的功能和规则等 掌握集成开发工具VS2019的使用和C++的基础编程 了解MFC框架 了解线性结构,掌握数组的遍历、消子和胜负判断等算法 了解企业软件开发过程,应用迭代开发思路进行项目开发,养成良好的编程习惯和培养软件工程化思维 .

mo_zhe的博客 7612

POJ:2586-Y2K Accounting Bug

Y2K Accounting BugTime Limit: 1000MS Memory Limit: 65536KDescriptionAccounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for

二营长的意大利炮友 329

HAL STM32+EC11编码器实现增减调节及单击、双击、长按功能

HAL STM32+EC11编码器实现增减调节及单击、双击、长按功能

perseverance51博客 4236

【Mode】多模干涉仪的设计 Multi-mode interferometer(MMI)

与 Splitter 器件一样,MMI 器件也是一种常见的分光器件,可以根据用户的需求将光束分成不同的比例。本文,我们将介绍如何仿真 MMI 器件。这里我们使用的是 1x2 MMI,其本质上是由四个部分组成的,中间的矩形多模式干涉区域以及左右两侧的三个 taper 模式转换区域。之前的教程中我们也提及了,为了获取稳定的模式场分布,通常,我们需要进行模式收敛性扫描。这里以官网给出的案例为例。如何提取 S 参数我们先暂时不做介绍,后续有时间了我们再做介绍。

u011699626的博客 1214

poj2586 Y2K Accounting Bug(贪心)

poj2586 Y2K Accounting Bug(贪心)

1509

QT C++ AI棉花智能变量灌溉工上位机(信创完整版)

北斗履带灌溉机器人/田间分区电磁阀基站 → 多层土壤温湿度/盐分EC传感器实时采集墒情 → 双目AI视觉扫描棉田长势、病苗分布 → AI融合**生育期+土壤墒情+盐分+棉株长势**计算变量灌溉定额、水肥配比、灌溉时长 → 分区电磁阀/变频水泵变量供水,病弱苗地块减量、干旱地块增量;墒情、盐分、长势多因子闭环修正灌水量;多层土壤含水率(0–10/20–40/40–80cm)、土壤EC盐分、土壤温度、空气温湿度、蒸发量、北斗地块坐标、管道水压、水肥罐液位、分区流量计、水泵电机负载、滴灌带压力反馈。

寒寒豆豆软件公司的博客 186

POJ2586 Y2K Accounting Bug

POJ2586 Y2K Accounting Bug题干DescriptionInputOutputSample InputSample Output题意题解提交代码 题干 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. All what they rememb

wjqaea的博客 191

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

深度学习工具包 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")

POJ 2586- Y2K Accounting Bug

POJ 2586- Y2K Accounting Bug (贪心) 思路: 之前做过一遍这个题目,现在又看了一遍,刚开始没看懂题目,后来才发现要求在每连续555月都亏损的情况下输出最大利润,若某个月盈利则获sss,否则亏损ddd元. 考虑每个月选择盈利还是亏损,根据贪心的思想,我们肯定是优先选择前面的月作为sss,这样后面就能用较少的ddd就能在给较多的表单作贡献,从而放更多的sss. 分类讨论: 1.每个月只有一个d (d>4s)d\ (d>4s)d (d>4s) s

Harris-H的博客 645

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

贪心 POJ 2586 Y2K Accounting Bug

题目地址:http://poj.org/problem?id=2586 1 /* 2 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D。 3 公司每五个月进行一次统计,全年共统计8次(1-5、2-6、3-7、4-8、5-9、6-10、7-11、8-12), 4 已知这8次统计的结果全部是亏...

weixin_34198797的博客 105

【贪心】POJ 2586:Y2K Accounting Bug

一、题目内容 POJ 2586 原题地址 二、题意解释 某公司每个月要么盈利s元,要么亏损d元, 一年之中任意连续的五个月的利润和是亏损的,最后问一年的总收入是多少, 如果盈利即输出数额,如果亏损,则输出Deficit。 三、代码及注释 #include<cstdio> using namespace std; /* 贪心,要使每五个月都亏损,那么就让这些亏损的月份在后面更有利 符合最优子结构性质。5个月统计一次都亏空,那么有5种情况: 1、若SSSSD亏空,那么全年可能最大盈利情

szy_fasheng的博客 225

POJ 2586 Y2K Accounting Bug

                                           Y2K Accounting Bug题目链接:http://poj.org/problem?id=2586DescriptionAccounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital d...

sortmin的博客 233

POJ 2586【Y2K Accounting Bug】

题目链接 这题是tm一个翻译题吧。 即使这样我也WA了 翻译:感谢康文骐的Blog。 思路: 因为后两个月是盈利的关键,并且依然要保证连续 5 个月亏损,所以要把每组中的亏损月往后放。 首先给大家逐字逐句翻译一遍: Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vita...

Masker 237

Y2K Accounting Bug POJ - 2586(贪心)

Y2K Accounting Bug POJ - 2586(贪心) 题目 参考博客:https://blog.youkuaiyun.com/lyy289065406/article/details/6642603#commentBox Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vi...

qq_43280247的博客 288

Y2K Accounting Bug POJ 2586

Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. All what they remember is that MS Inc. posted a

Sunmh_AC的博客 650

POJ 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8282   Accepted: 4106 Description Accounting for Computer Machinists (ACM) has sufferred fro...

weixin_34293246的博客 76
上一篇: poj2109Power of Cryptography
下一篇: poj3295Tautology
qiweigo
博客等级 码龄12年 11粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值