『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": 求删除一个数, ...
随机推荐
- Properties没有被注意的地方
源起: 今天阅读源码时发现一个地方不理解: 为什么以下代码第10行 get() 之后value为null时还去 getProperty() 呢? org.springframework.util.Co ...
- ubuntu安装mysql多实例
想要尝试mysql的读写分离,在云上安装完mysql之后突然想到一个问题:我本机是没有公网IP的. 开始尝试在唯一一台云服务器上安装多个mysql实例. 主要步骤: 1.新建MySQL目录 (1):新 ...
- 自动创建xml文档
自动创建xml文档 import xml.etree.ElementTree as ET print(dir(ET)) #ET里面有Element方法 root = ET.Element(" ...
- C++模板类头文件和实现文件分离
http://www.cnblogs.com/lvdongjie/p/4288373.html 如何实现C++模板类头文件和实现文件分离,这个问题和编译器有关. 引用<<C++primer ...
- BaseAtapter
本文用于实现一个通用的BaseAdapter类,统一产品的Adapter类,作为一个工具类,减少重复性工作,增加开发效率. 序 我们在开发项目的过程中,经常会用到ListView.GridView这一 ...
- 混合开发之DCloud和Weex的集成及优缺点比较
记录此文时太忙,没时间整理上来.需要请私信,由于DCloud和Weex的版本及API更新过快,本次分享只是对某个版本处理.
- SQLite运算符
SQLite运算符 SQLite的运算符是什么? 运算符是一个保留字或一个字符主要用于SQLite语句的WHERE子句来执行操作,如比较和算术运算. 操作符用于指定条件的SQLite语句和作为连词在一 ...
- iTOP-iMX6开发板Android系统下LVDS和HDMI双屏异显方法
迅为iMX6 开发板 android 系统下 LVDS 和 HDMI 双屏异显的使用过程. 注意,iTOP-iMX6 开发板的 android 系统想要实现对 LVDS 和 HDMI 双屏异显功能的支 ...
- powerDesigner 把name项添加到注释(comment),完美方案!
第一次写博客,分享一点经验吧,平时大家用powerDesigner的时候,pd是不会把name项默认添加到comment的,所以生成的数据库表里面也没有中文字段的注释. 我在网上查了一下.有解决方案了 ...
- TCP socket如何判断连接断开
http://blog.csdn.net/zzhongcy/article/details/21992123 SO_KEEPALIVE是系统底层的机制,用于系统维护每一个tcp连接的. 心跳线程属于应 ...