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

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了,不过通过这个起码可以知道自己的不足之处,思维还是不够敏捷清晰,能力也有待提高;

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题的更多相关文章

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

    B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...

  2. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B

    B. Problems for Round time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths

    题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...

  4. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  5. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造

    D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...

  6. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力

    C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...

  7. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

  8. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

    A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...

  9. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D

    D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. 【转】JAVA的静态变量、静态方法、静态类

    转自:http://blog.csdn.net/zhandoushi1982/article/details/8453522/ 静态变量和静态方法都属于静态对象,它与非静态对象的差别需要做个说明. ( ...

  2. JDK集合框架--综述

       接下来的几篇博客总结一下对jdk中常用集合类知识,本篇博客先整体性地介绍一下集合及其主要的api: 从整体上来说,集合分两大类collection和map: 首先来看看Collection: c ...

  3. 策略模式--Java篇

    策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...

  4. 详解Android Activity生命周期

    转载注明来自:  http://www.cnblogs.com/wujiancheng/ 一.正常情况下Activity的生命周期:  Activity的生命周期大概可以归为三部分 整个的生命周期:o ...

  5. git 学习笔记1

    目前我属于粗放型的[学习者],接下来需要做一些改变,让自己更加规范.首先需要学习的就是版本控制系统,本科在工作室的时候使用过一点Subversion,不过到现在已经基本没有印象了.git现在越来越成为 ...

  6. ActiveSync日志分析

    Here are the steps to exporting the ActiveSync log data: Create a folder on the root      of C:\     ...

  7. chgrp - 改变文件的组所有权

    总览 chgrp [选项] 组文件... POSIX 选项: [-R] [--] Austin 草拟选项: [-hHLPR] GNU 团体指示: [--reference=rfile] GNU 选项 ...

  8. vue 发布build 本地设置 相对路径 两个地方 一个根目录用./ css文件里面用../../ 【也不好用,还是得手改】

    build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths a ...

  9. CAD参数绘制多行文字(网页版)

    在CAD设计时,需要绘制多行文字,用户可以设置设置绘制文字的高度等属性. 主要用到函数说明: _DMxDrawX::DrawMText 绘制一个多行文字.详细说明如下: 参数 说明 DOUBLE dP ...

  10. js 给url添加时间戳 解决浏览器缓存

    //解决浏览器缓存 function timestamp(url){      //  var getTimestamp=Math.random(); var getTimestamp=new Dat ...