C
来源:互联网 发布:淘宝卖家插件推荐 编辑:程序博客网 时间:2024/06/05 07:57
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will ben problems, sorted by difficulty, i.e. problem1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needsk minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
The only line of the input contains two integers n andk (1 ≤ n ≤ 10,1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
3 222
2
4 190
4
7 1
7
In the first sample, there are 3 problems and Limak needs222 minutes to get to the party. The three problems require5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is2.
In the second sample, Limak can solve all 4 problems in5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all7 problems.
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int sum=240;int dp[300];struct node{int score;}hh[200];int main(){int n,k;scanf("%d%d",&n,&k);sum=sum-k;int i;for(i=1;i<=n;i++)hh[i].score=i*5;//这边是按照顺序从小到大排列的 嗯 如果先加的是大的话那么....嗯怎么说 就是小的一定都会被加进来吧for(i=1;i<=n;i++){for(int gg=sum;gg>=hh[i].score;gg--){if(dp[gg]<dp[gg-hh[i].score]+hh[i].score){dp[gg]=dp[gg-hh[i].score]+hh[i].score; }}}//printf("%d",dp[sum]);int t=0;int kkk=0;for(i=1;i<=n;i++) { if(t+hh[i].score<=dp[sum]) { kkk++; t=t+hh[i].score; } } printf("%d\n",kkk); // printf("%d\n",t);return 0;}
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- 工厂模式
- A/B 测试的基本概念举例理解以及具体实现方法【传统A/B测试基于后端的 A/B 测试(Back-end AB test),现在基本上基于前端js在客户端进行分流,有更多优点,请看里面】
- SQL Server数据库表锁定原理以及如何解除表的锁定
- libpcap--GTPv2协议的cap文件解析
- Android 性能优化
- C
- python里创建任务执行一半时取消任务执行
- JS跑马灯效果实现(很好用)
- python 迭代器
- Java的*.class字节码查看方法
- 【PAT】【Advanced Level】1105. Spiral Matrix (25)
- devExpress GridControl repositoryItemCheckEdit 设置值对应的选中状态
- Spring Security# RoleHierarchy
- CAS实现单点登录(数据库认证)