Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game.
The first line of the input contains one integer n (1 ≤ n ≤ 90) — the number of interesting minutes.
The second line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... tn ≤ 90), given in the increasing order.
Print the number of minutes Limak will watch the game.
3 7 20 88
35
9 16 20 30 40 50 60 70 80 90
15
9 15 20 30 40 50 60 70 80 90
90
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.
题意:
一场球有90min,如果有连续15min是boring的,他就会关掉电视,有n个interesting的时间点,问他看球的时间是多长?(每分钟不是boring就是interesting的)。
题解:
果t1>15,只能看15Min,否则,for循环,如果ti-t(i-1) >15,跳出。
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define INF 0x3f3f3f3f
using namespace std;
int a;
int aa[100];
int main()
{
while(cin>>a)
{
mem(aa);
for(int i=0;i<a;i++)
{
cin>>aa[i];
}
int sum=15;
if(aa[0]>15)
cout<<sum<<endl;
else
{
sum=aa[0];
for(int i=1;i<a;i++)
{
if(aa[i]-aa[i-1]>15)
break;
else
sum=aa[i];
}
sum+=15;
if(sum>90)
sum=90;
cout<<sum<<endl;
}
}
}
There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules:
Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.
Note, that the relation of similarity is not transitive. That is, if problem i is similar to problem j and problem j is similar to problem k, it doesn't follow that i is similar to k.
The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following m lines contains a pair of similar problems ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). It's guaranteed, that no pair of problems meets twice in the input.
Print one integer — the number of ways to split problems in two divisions.
5 2 1 4 5 2
2
3 3 1 2 2 3 1 3
0
3 2 3 1 3 2
1
In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sample reminds you that the similarity relation is not transitive. Problem 3 is similar to both 1 and 2, but 1 is not similar to 2, so they may be used together.
难度为 1-n的题,两个集合, m个约束, ui,vi不能在同一集合内,要求第一个集合内的最小值比第二个集合的最大值大,且集合不为空,问有多少中组合,
题解:
将ui,vi的大值给第一个集合,小值给二集合,记录第一个集合的最小值,第二个集合的最大值,如果mi>mx,输出mi-mx(好像需要证明,不会。。。。),否则输出0.
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define INF 0x3f3f3f3f
using namespace std;
int a,b,x,y;
int main()
{
while(cin>>a>>b)
{
int mi=a;
int mx=1;
for(int i=0;i<b;i++)
{
cin>>x>>y;
if(x<y)
swap(x,y);
mi=min(mi,x);
mx=max(mx,y);
}
cout<<max(0,mi-mx)<<endl;
}
}