『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals
2 seconds
64 megabytes
input.txt
output.txt
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of
the drink and, having come home, he went to bed at once.
DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly n days
in DravDe’s dream and the animal that came on the i-th day, ate exactly ci tons
of food daily starting from day i. But if one day the animal could not get the food it needed, it got really sad. At the very beginning
of the dream there were exactly X tons of food on the farm.
DravDe woke up terrified...
When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the n-th day any more, but he
did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.
It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that
day to the n-th.
The first input line contains integers n and X (1 ≤ n ≤ 100, 1 ≤ X ≤ 104)
— amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers ci (1 ≤ ci ≤ 300).
Numbers in the second line are divided by a space.
Output the only number — the maximum possible amount of animals on the farm by the end of the n-th day given that the food was enough
for everybody.
3 4
1 1 1
2
3 6
1 1 1
3
Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.
很有意思的一题,因为大家都没有做出来,比赛快结束时才知道要用
freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); 原来是水题,不过思路还是得清晰一点,,简化题意就是如果要容纳这只动物,那么就得吃到最后一天而且不会unhappy,就先把每只动物到最后一天所需的粮食求出来,再排序一下,,,然后贪心策略;
上代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N=500;
int n,m,a[N];
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int i;
while(~scanf("%d%d",&n,&m))
{
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
a[i]*=(n-i);//每只动物总共所需的粮食;
}
sort(a,a+n);
printf("\n");
if(a[0]>m)
printf("0\n");
else
{
int k=0;
for(i=0;i<n;i++)
{
if(m-a[i]>=0)
{
k++;
m-=a[i];
}
else
break;
}
printf("%d\n",k);
}
}
return 0;
}
『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals的更多相关文章
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]-最小内积(第八届北京师范大学程序设计竞赛决赛)
H. 最小内积 Time Limit: 1000ms Memory ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 第九届河南理工大学算法程序设计大赛 正式赛L:最优规划(最小生成树)
单测试点时限: 1.0 秒 内存限制: 512 MB 有很多城市之间已经建立了路径,但是有些城市之间没有路径联通.为了联通所有的城市,现在需要添加一些路径,为了节约,需要满足添加总路径是最短的. 输入 ...
- 『PyTorch』第九弹_前馈网络简化写法
『PyTorch』第四弹_通过LeNet初识pytorch神经网络_上 『PyTorch』第四弹_通过LeNet初识pytorch神经网络_下 在前面的例子中,基本上都是将每一层的输出直接作为下一层的 ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 237C,素数打表,二分查找
C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 236A,虽然很水,但有一个很简单的函数用起来方便
A. Boy or Girl time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge
B. Easy Number Challenge time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛 C-Cities
题目描述:There are n cities in Byteland, and the ith city has a value ai. The cost of building a bidirec ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛(重现赛)E.sequence(树状数组求逆序对(划掉))
传送门 E.sequence •题意 定义序列 p 中的 "good",只要 i 之前存在 pj < pi,那么,pi就是 "good": 求删除一个数, ...
随机推荐
- iphone 开发Categories 、Extensions 区别 --转
Category和Extension这两个概念,即便对于Java程序员,可能也会感到陌生.这是Objective C为程序员提供的两个强大的动态机制——简单地说,它们允许程序员为已有的对象添加新的方法 ...
- 17972 Golden gun的巧克力
17972 Golden gun的巧克力 时间限制:1000MS 内存限制:65535K提交次数:93 通过次数:13 收入:124 题型: 编程题 语言: G++;GCC;JAVA Descr ...
- 看Facebook是如何优化React Native性能
原文出处: facebook 译文出处:@Siva海浪高 该文章翻译自Facebook官方博客,传送门 React Native 允许我们运用 React 和 Relay 提供的声明式的编程模型, ...
- HBase备份恢复练习
一.冷备 1.创建测试表并插入测试数据 [root@weekend05 ~]# hbase shell hbase(main):005:0> create 'scores','grade','c ...
- 启动azkaban时出现User xml file conf/azkaban-users.xml doesn't exist问题解决(图文详解)
问题详情 [hadoop@master azkaban]$ ll total drwxrwxr-x hadoop hadoop May : azkaban- drwxrwxr-x hadoop h ...
- 06.NopCommerce配置邮箱账户
NopCommerce如果配置让用户注册为通过邮箱注册,并且注册后激活邮箱才可登录,那么我们需要对NopCommerce的邮箱账户进行配置,用来发送邮件用.当然邮件还有很多其他用途,比如发送用户订阅的 ...
- ASP.NET MVC IIS7 403.14-Forbidden
问题描述 IIS 7上发布ASP.NET MVC程序报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 折腾了半天,提示里面的解决方法是: 如果不希望启用目录浏览,请确保 ...
- Halcon学习笔记2
图像预处理 一般来说,我们采集到的图像会有一些小黑点,小斑点,不平滑等因素会会影响我们后期的算法,此时就需要我们对其图片进行预处理. 下面是一些预处理基本算子: 1.消除噪声:mean_image/b ...
- centos6上安装mysql8.0版本
本博客是采用yum源的方式安装,非常的方便和快捷.(redhat 与centos7 等操作系统都可以采用此方法,步骤大体一致) mysql官网地址: https://dev.mysql.com 开 ...
- JavaScript-基础类型和运算符
JavaScript-基础类型和运算符 P02.稍微了解 1.js代码需要编写到script标签中 <script type="text/javascript"> 此处 ...