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

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. 专 linux命令之set x详解

    set -x与set +x指令   用于脚本调试.set是把它下面的命令打印到屏幕 set -x 是开启 set +x是关闭 set -o是查看 (xtrace),set去追中一段代码的显示情况. 执 ...

  2. Atcoder B - Boxes 玄学 + 数学

    http://agc010.contest.atcoder.jp/tasks/agc010_b 预处理出每两个相邻的数的差值,那么首先知道是一共取了sum / ((1 + n) * n / 2)次,因 ...

  3. jquery readio checked

    今天太鬼火了为这个难问题搜了一下午了到最后还是csdn的朋友给了我正确的答案http://bbs.csdn.net/topics/300162450谢谢这位朋友 // $("#ISOK1&q ...

  4. spring framework 第一章数据库管理(data access)

    spring data access 的网址:https://docs.spring.io/spring/docs/current/spring-framework-reference/index.h ...

  5. nginx for windows 安装

    一.nginx for windows 的安装地址: http://nginx.org/en/download.html 二.nginx 安装地址: http://nginx.org/en/docs/ ...

  6. R in action读书笔记(17)第十二章 重抽样与自助法

    12.4 置换检验点评 除coin和lmPerm包外,R还提供了其他可做置换检验的包.perm包能实现coin包中的部分功能,因此可作为coin包所得结果的验证.corrperm包提供了有重复测量的相 ...

  7. Python学习 Day 4 函数 切片 迭代 列表生成式 生成器

    定义函数 def my_abs(x):#求绝对值的my_abs函数 if x >= 0: return x else: return –x def nop():#空函数 pass#占位符 参数检 ...

  8. [转载]iTOP-4418开发板Ubuntu系统烧写方法分享

    本文转自迅为论坛:http://topeetboard.com 开发平台:iTOP-4418开发板系统:Ubuntu 1. TF卡读写速度测试烧写 Ubuntu 对于 TF 卡的要求比较高,很多老旧的 ...

  9. 集成新版(5.17+)Activiti Modeler与Rest服务

    声明: 此教程适合Activiti 5.17+版本. 本博客所涉及的内容均可在kft-activiti-demo中找到. 在线demo可以访问 http://demo.kafeitu.me:8080/ ...

  10. 去除inline-block间距

    去除inline-block间距 通过display:inline-block设置元素为水平时,相邻元素之间会有几px的间距: html: <ul class="list"& ...