Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)只有A题和B题
2 seconds
256 megabytes
standard input
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.
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.
题意蛮好理解,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来判断;
2 seconds
256 megabytes
standard input
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.
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 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题的更多相关文章
- 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 ...
- 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 ...
- 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. 题解: ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors
题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)
A.暴力枚举,注意游戏最长为90分钟 B.暴力,c[l]++,c[r]--,记录中间有多长的段是大小为n的,注意特判m=0的情况 C.暴力枚举,我居然一开始没想出来!我一直以为每次都要统计最大的,就要 ...
- 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 ...
随机推荐
- 【转】JAVA的静态变量、静态方法、静态类
转自:http://blog.csdn.net/zhandoushi1982/article/details/8453522/ 静态变量和静态方法都属于静态对象,它与非静态对象的差别需要做个说明. ( ...
- JDK集合框架--综述
接下来的几篇博客总结一下对jdk中常用集合类知识,本篇博客先整体性地介绍一下集合及其主要的api: 从整体上来说,集合分两大类collection和map: 首先来看看Collection: c ...
- 策略模式--Java篇
策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...
- 详解Android Activity生命周期
转载注明来自: http://www.cnblogs.com/wujiancheng/ 一.正常情况下Activity的生命周期: Activity的生命周期大概可以归为三部分 整个的生命周期:o ...
- git 学习笔记1
目前我属于粗放型的[学习者],接下来需要做一些改变,让自己更加规范.首先需要学习的就是版本控制系统,本科在工作室的时候使用过一点Subversion,不过到现在已经基本没有印象了.git现在越来越成为 ...
- ActiveSync日志分析
Here are the steps to exporting the ActiveSync log data: Create a folder on the root of C:\ ...
- chgrp - 改变文件的组所有权
总览 chgrp [选项] 组文件... POSIX 选项: [-R] [--] Austin 草拟选项: [-hHLPR] GNU 团体指示: [--reference=rfile] GNU 选项 ...
- vue 发布build 本地设置 相对路径 两个地方 一个根目录用./ css文件里面用../../ 【也不好用,还是得手改】
build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths a ...
- CAD参数绘制多行文字(网页版)
在CAD设计时,需要绘制多行文字,用户可以设置设置绘制文字的高度等属性. 主要用到函数说明: _DMxDrawX::DrawMText 绘制一个多行文字.详细说明如下: 参数 说明 DOUBLE dP ...
- js 给url添加时间戳 解决浏览器缓存
//解决浏览器缓存 function timestamp(url){ // var getTimestamp=Math.random(); var getTimestamp=new Dat ...