Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题

连接在这里,->点击<-

A. Bear and Game
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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.

Output

Print the number of minutes Limak will watch the game.

Examples
input
3
7 20 88
output
35
input
9
16 20 30 40 50 60 70 80 90
output
15
input
9
15 20 30 40 50 60 70 80 90
output
90
Note

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.

题意蛮好理解,90分钟的节目,如果在任意15分钟内没有有趣的时刻那么他就会关闭电视机,问他最长看多久;

其实题是个水题,但思路要清晰,具体看代码加注释:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,i,x,sum;
while(~scanf("%d",&n))
{
sum=x=0;
int f=0;
for(i=1; i<=n; i++)
{
scanf("%d",&a);
if(x+15>=a)
{
sum=a;//更新,然后又从这个时刻开始看起;
x=a;也同时更新;用它来判断15分钟内会不会出现有趣的时刻;
}
else
{
f=1;//这种时候已经关闭了电视;
}
}
if(f)
{
if(sum==0)
printf("15\n");
else
printf("%d\n",sum+15);//从最后一次更新然后再看15分钟;
}
else
{
if(sum>=75)//如果最后一次更新在75分钟后,那么他再看15分钟已经达到了90分钟;
printf("90\n");
else
printf("%d\n",sum+15);
}
}
return 0;
}

其实不用X作为判断条件,直接用sum来判断;

B. Problems for Round
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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:

  • Problemset of each division should be non-empty.
  • Each problem should be used in exactly one division (yes, it is unusual requirement).
  • Each problem used in division 1 should be harder than any problem used in division 2.
  • If two problems are similar, they should be used in different divisions.

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.

Input

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.

Output

Print one integer — the number of ways to split problems in two divisions.

Examples
input
5 2
1 4
5 2
output
2
input
3 3
1 2
2 3
1 3
output
0
input
3 2
3 1
3 2
output
1
Note

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 to2,
so they may be used together.

题意:在DIV赛中分为Div.1与Div.2,给定n个题目,m对难度相似的题目;①其中Div.1中的任何题都要比Div.2更难(题目所述);;②难度相似的题不能在同一个级别中;③每个题只能出现在一个级别中;④一个级别至少有一个题;

思路:我自己用了两个数组把这些难度存起来,然后判断,却发现并没有什么用,我们要用到的只是两个数组中的最大值与最小值,想想看,题目已表明u不等于v,所以大的一定在Div.1中,小的一定在Div.2中,所以只需找出Div.1中最小的难度与Div.2中最大的难度,相减大于0便直接输出,反之输出0;

#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
int a[N],b[N],v1[N],v2[N];
int main()
{
int n,m,i,x,y;
while(~scanf("%d%d",&n,&m))
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(v1,-1,sizeof(v1));
memset(v2,-1,sizeof(v2));
int k1=0,k2=0;
if(m==0)
printf("%d\n",n-1);
else
{
int f=0;
for(i=1; i<=m; i++)
{
scanf("%d%d",&x,&y);
if(x>y)
{
if(v2[x]==0||v1[y]==0)//判断大的是否在Div.2中出现过,另一个同理;
f=1;
a[k1++]=x;
v1[x]=0;
b[k2++]=y;
v2[y]=0;
}
else
{
if(v2[y]==0||v1[x]==0)
f=1;
a[k1++]=y;
v1[y]=0;
b[k2++]=x;
v2[x]=0;
}
}
sort(a,a+k1);
sort(b,b+k2);
k1=unique(a,a+k1)-a;
k2=unique(b,b+k2)-b;
// printf("%d %d %d %d %d\n",a[0],b[k2-1],k1,k2,f);
if(f||k1==0||k2==0||(a[0]<=b[k2-1]))
printf("0\n");
else
printf("%d\n",a[0]-b[k2-1]);
}
}
return 0;
}

优化后的代码:

#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
int main()
{
int n,m,i,x,y,maxx,minn;
while(~scanf("%d%d",&n,&m))
{
maxx=1,minn=n;//maxx代表Div.2中难度最大的;minn同理;
for(i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
maxx=max(maxx,min(x,y));//小的在Div.2中,找出Div.2难度最大的;
minn=min(minn,max(x,y));//同上;
}
if(minn-maxx<0)
printf("0\n");
else
printf("%d\n",minn-maxx);
}
return 0;
}这个为什么不用判断一个题是否在两个级别中出现呢,我们可以反证,当两个题难度不等时,一定可以分级别,如果本应该在一个级别中的题却在另一个级别中出现了,那么不是违背了①么,所以判断的时候还是可以得到正确的答案;

剩下的题由于能力不足,就没有去A了,不过通过这个起码可以知道自己的不足之处,思维还是不够敏捷清晰,能力也有待提高;

上一篇:对Slony-I中wait on的理解


下一篇:Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题