C - New Year and Hurry CodeForces - 750A(动态规划)
2017-09-08 16:11
489 查看
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 be
n problems, sorted by difficulty, i.e. problem
1 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 needs
k 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?
Input
The only line of the input contains two integers n and
k (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.
Output
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.
Example
Input
Output
Input
Output
Input
Output
Note
In the first sample, there are 3 problems and Limak needs
222 minutes to get to the party. The three problems require
5, 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 (after
222 minutes). In this scenario Limak would solve
2 problems. He doesn't have enough time to solve 3 problems so the answer is
2.
In the second sample, Limak can solve all 4 problems in
5 + 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 all
7 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;
}
n problems, sorted by difficulty, i.e. problem
1 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 needs
k 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?
Input
The only line of the input contains two integers n and
k (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.
Output
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.
Example
Input
3 222
Output
2
Input
4 190
Output
4
Input
7 1
Output
7
Note
In the first sample, there are 3 problems and Limak needs
222 minutes to get to the party. The three problems require
5, 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 (after
222 minutes). In this scenario Limak would solve
2 problems. He doesn't have enough time to solve 3 problems so the answer is
2.
In the second sample, Limak can solve all 4 problems in
5 + 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 all
7 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;
}
相关文章推荐
- New Year and Rating CodeForces - 750C
- Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- 【codeforces 750A】New Year and Hurry
- 750A- New Year and Hurry
- 【转】Codeforces GoodBye2015 New Year and Three Musketeers Codeforces 611E(贪心)
- New Year and Curling CodeForces - 908C
- New Year and North Pole CodeForces - 750B
- E - New Year and North Pole CodeForces - 750B(状态处理下就好了)
- codeforces goodbye 2016 C. New Year and Rating
- New Year and Old Property CodeForces - 611B
- 750A New Year and Hurry
- New Year and Rating CodeForces - 750C
- codeforces GoodBye2015 D.New Year and Ancient Prophecy (dp+lcp+树状数组)
- New Year and Old Property CodeForces - 611B
- New Year and Rating CodeForces - 750C
- codeforces 750A New Year and Hurry
- 【codeforces 750A】New Year and Hurry
- I - New Year and Rating CodeForces - 750C 模拟
- Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies