Good Bye 2016(A+B)

A. New Year and Hurry
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Examples
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.
题意:一场比赛持续4h,一共有N道题,你还有K分钟才能回到家开始做题,每道题花费的时间为它的编号*5,问最多能做出来几题
题解:贪心,
代码:

#include <bits/stdc++.h>
#define ll long long
#define babab printf("!!!!!\n");
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
   ll n,k;
   cin>>n>>k;
   k=240-k;
   int ans=0;
   for(int i=1;i<=n;i++)
   {
       if(k>=i*5)
       {
           k-=i*5;
           ans++;
       }
       else
        break;
   }
   cout<<ans<<endl;
}

B. New Year and North Pole
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.

Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: “North”, “South”, “West”, “East”.

Limak isn’t sure whether the description is valid. You must help him to check the following conditions:

If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.
If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.
The journey must end on the North Pole.
Check if the above conditions are satisfied and print “YES” or “NO” on a single line.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 50).

The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Output
Print “YES” if the description satisfies the three conditions, otherwise print “NO”, both without the quotes.

Examples
input
5
7500 South
10000 East
3500 North
4444 West
4000 North
output
YES
input
2
15000 South
4000 East
output
NO
input
5
20000 South
1000 North
1000000 West
9000 North
10000 North
output
YES
input
3
20000 South
10 East
20000 North
output
NO
input
2
1000 North
1000 South
output
NO
input
4
50 South
50 North
15000 South
15000 North
output
YES
Note
Drawings below show how Limak’s journey would look like in first two samples. In the second sample the answer is “NO” because he doesn’t end on the North Pole.
题意:你在北极点出发,经过一系列操作是否能回到北极点。
题解;我们不用管东西方向, 只要最后南北的和为0即可。注意坑点就好,当你在北(南)极点时,只能往南(北)走,还有不能穿过极点。(我cha了7个,早上醒了,自己的FST了,一个-号让我打成+了。。。)
代码:

#include <bits/stdc++.h>
#define ll long long
#define babab printf("!!!!!\n");
using namespace std;
int main()
{
    int n,k;
    cin>>n;
    int ans=0;
    string str;
    bool flag=false;
    for(int i=1;i<=n;i++)
    {
        cin>>k>>str;
        if(str=="North"&&ans-k<0)
            flag=true;
        if(str=="South"&&k+ans>20000)
            flag=true;
        if(ans==20000&&str!="North")
        flag=true;
        if(ans==0&&str!="South")
            flag=true;
        if(str=="South")
            ans+=k;
        if(str=="North")
            ans-=k;
    }
    if(flag)
    {
         cout<<"NO"<<endl;
         return 0;

    }
    if(ans==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值