题目链接:点击打开链接
#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);
else
printf("%d\n",n);
}
return 0;
}
题目链接: 点击打开链接
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.
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.
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
5 7500 South 10000 East 3500 North 4444 West 4000 North
YES
2 15000 South 4000 East
NO
5 20000 South 1000 North 1000000 West 9000 North 10000 North
YES
3 20000 South 10 East 20000 North
NO
2 1000 North 1000 South
NO
4 50 South 50 North 15000 South 15000 North
YES
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.
![](https://i-blog.csdnimg.cn/blog_migrate/8484bd9b10440abaf8ff8c45cce3052c.png)
大意:一只北极熊送包裹,起点为北极点,终点还是北极点。给出行走的路径,问是否是合法的路径。
有一个限制条件(当时没有 理解透):处于北(南)极点只能向南(北)走。
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");
else
puts("NO");
}
}
return 0;
}
/*
5
7500 South
10000 East
3500 North
4444 West
4000 North
2
15000 South
4000 East
5
20000 South
1000 North
1000000 West
9000 North
10000 North
3
20000 South
10 East
20000 North
2
1000 North
1000 South
4
50 South
50 North
15000 South
15000 North
*/
题目链接:点击打开链接
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".
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.
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.
3 -7 1 5 2 8 2
1907
2 57 1 22 2
Impossible
1 -5 1
Infinity
4 27 2 13 1 -50 1 8 2
1897
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);
else
div2=min(div2,1899-sum);
sum+=c;
}
printf("%d--%d--",div2,sum);
if(div2==INF)
puts("Infinity");
else if(div1>div2)
puts("Impossible");
else
printf("%d\n",div2+sum);
}
return 0;
}