题目链接:点击打开链接

A. New Year and Hurry
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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 15minutes 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<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k;
int main()
{while(~scanf("%d%d",&n,&k)){int sum=240-k;int ans=0;for(int i=1;i<=n;i++){if(i*(i*5+5)/2>sum){ans=i;break;}}if(ans!=0)printf("%d\n",ans-1);elseprintf("%d\n",n);}return 0;
}

题目链接: 点击打开链接

B. New Year and North Pole
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 000kilometers.

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 dirithat 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.

大意:一只北极熊送包裹,起点为北极点,终点还是北极点。给出行走的路径,问是否是合法的路径。

有一个限制条件(当时没有 理解透):处于北(南)极点只能向南(北)走。

1 . 也就是说当某一次正好到达北(南)极点时,下一次只能向南(北)走;

2 . 某一次走的中途到达北(南)极点,那么此次行走必然不合法;

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,t;
char dir[10];
int main()
{while(~scanf("%d",&n)){int flag=1;bool temp=0;int sum=0;for(int i=1;i<=n;i++){scanf("%d%s",&t,dir);if(sum==0&&dir[0]!='S')temp=1;if(sum==20000&&dir[0]!='N')temp=1;if(dir[0]=='S'){sum+=t;if(sum>20000)temp=1;}else if(dir[0]=='N'){sum-=t;if(sum<0)temp=1;}}if(temp)puts("NO");else{if(sum==0)puts("YES");elseputs("NO");}}return 0;
}
/*5
7500 South
10000 East
3500 North
4444 West
4000 North2
15000 South
4000 East5
20000 South
1000 North
1000000 West
9000 North
10000 North3
20000 South
10 East
20000 North2
1000 North
1000 South4
50 South
50 North
15000 South
15000 North*/

题目链接:点击打开链接

C. New Year and Rating
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.

Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division di (i.e. he belonged to this division just before the start of this contest) and his rating changed by ci just after the contest. Note that negative ci denotes the loss of rating.

What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".

Input

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

The i-th of next n lines contains two integers ci and di ( - 100 ≤ ci ≤ 100, 1 ≤ di ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.

Output

If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the ncontests.

Examples
input
3
-7 1
5 2
8 2

output
1907

input
2
57 1
22 2

output
Impossible

input
1
-5 1

output
Infinity

input
4
27 2
13 1
-50 1
8 2

output
1897

Note

In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:

  • Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7.
  • With rating 1894 Limak is in the division 2. His rating increases by 5.
  • Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets  + 8 and ends the year with rating 1907.

In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
int n;
int div1=-INF,div2=INF;
int main()
{while(~scanf("%d",&n)){int sum=0;for(int i=1;i<=n;i++){int c,d;scanf("%d%d",&c,&d);if(d==1)div1=max(div1,1900-sum);elsediv2=min(div2,1899-sum);sum+=c;}printf("%d--%d--",div2,sum);if(div2==INF)puts("Infinity");else if(div1>div2)puts("Impossible");elseprintf("%d\n",div2+sum);}return 0;
}

codeforces-750【C思维】相关推荐

  1. codeforces 有意思的思维题 1 ~ 15

    codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...

  2. codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]

    A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...

  3. CodeForces - 364A Matrix(思维+数学)

    题目链接:点击查看 题目大意:给出一个长度为 n 的,只由十进制数字组成的字符串 s,可以构造出一个大小为 n * n 的矩阵,构造方法如下:b[ i ][ j ] = s[ i ] * s[ j ] ...

  4. Task On The Board CodeForces - 1367D(思维)

    Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This strin ...

  5. Orac and Game of Life CodeForces - 1350E(思维+BFS)

    Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with t ...

  6. Ehab and Path-etic MEXs CodeForces - 1325C(思维+贪心)

    You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such t ...

  7. Mind Control CodeForces - 1291C(思维)

    You and your n−1n−1 friends have found an array of integers a1,a2,-,ana1,a2,-,an. You have decided t ...

  8. codeforces 1060a(思维水题)

    Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", ...

  9. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

  10. Marvolo Gaunt's Ring ---CodeForces - 855B(思维题)

    题目链接:http://codeforces.com/problemset/problem/855/B Marvolo Gaunt's Ring Professor Dumbledore is hel ...

最新文章

  1. java map collection_java 集合----Map、Collection
  2. c++成员函数的调用
  3. 【Vegas原创】本地sys登录,ORA-01031: insufficient privileges的解决方法
  4. python 程序设计思维_Python程序设计与算法思维
  5. Shell脚本_备份/etc数据
  6. python函数编程训练题_Python文件与函数练习题
  7. [No0000E6]C# 判断与循环
  8. Windows live writer插入代码图片Test
  9. Myeclipse学习总结(14)——Eclipse/MyEclipse中Java编译时Java反射机形参没有保留问题2种解决方案
  10. java考试系统_Java在线考试系统(含源码)
  11. 特殊域名后缀如何申请备案?
  12. netkeeper客户端_中国电信创翼客户端下载
  13. html设置为邮箱格式,HTML中怎么设置为email链接
  14. Heartbeat超时值
  15. android系统裁剪之APP精简
  16. 吴恩达神经网络与深度学习——深度神经网络
  17. PageHelper处理分页问题,total总数不对
  18. 计算机硬件与系统软件
  19. 使用shell让其在系统空闲一段时间后自动结束指定进程
  20. 文件操作——打开关闭、顺序读写、随机读写

热门文章

  1. php压缩包 加密,php加密压缩文件
  2. 免费沙箱软件模拟支付_小游戏虚拟支付沙箱测试报错
  3. labview精华资料集合光盘
  4. 虚拟服务器 补丁,两种方法为VMware ESXi打补丁
  5. 测量小助手——典型用户及使用场景
  6. VMware Workstation Pro 16 XP home edition安装(ISO文件最底下)
  7. 盘点国内十大免费CDN提供商
  8. 对不起,我要站队,关于今晚Core组和吴忌寒在推特上的论战
  9. CF1037E. Trips
  10. m.444lu.co show.php,vml圆角矩形最简布局_javascript技巧