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 ...
随机推荐
- [ZPG TEST 110] 多边形个数【DP】
1. 多边形个数 (polygons.pas/c/cpp) [问题描述] 给定N线段,编号1到n.并给出这些线段的长度,用这些线段组成一个K边形,并且每个线段做多使用一次.若使用了一条不同编号的线段, ...
- yii2 设置多个入口文件
在web下希望加个core.php的后台入口,但因为权限问题,总是会跳转到index.php
- JS 事件添加onclick写法注意。
自定义函数添加onclick事件写法注意. 错误写法:element.onclick = addclass(className); 正确写法:element.onclick = function(){ ...
- 锁 Lock、重入锁、写入锁
ReentrantLock 重入锁 类似于synchronize 区别与写法上,在需要进行同步的代码部分加上锁定,但不要忘记最后一定要释放锁定, 不然会造成锁永远无法释放,其他线程永远进不来的结果.e ...
- npm run dev报错--Error: Cannot find module 'yargs-parser'
Error: Cannot find module 'yargs-parser' ---报错不知何解??? 百度了很久没找到方法,是缺少“ yargs-parser ”模块,需要安装一下即可:cnp ...
- web调用手机相册,并实现动态增加图片功能
注:经测试h5调用相册效果有兼容性问题,安卓仅能调用拍照功能(部分安卓可能会调不起来,所以建议用app原生调用),ios可调起拍照和相册功能. <html xmlns="http:// ...
- GA详解
转:http://blog.csdn.net/u010451580/article/details/51178225 本文是去年课题组周报中的一个专题讲解,详细讲了GA,由于是周报,所以十分详细.很适 ...
- Day3 CSS 引入及基本选择器
一 .CSS 层叠样式表,为了使网页元素的样式更加丰富,内容与样式拆分开来.HTML负责结构与内容,表现形式交给CSS. CSS注释/**/ 来注释 二.CSS基本语法与引用 CSS的语法结构 选择器 ...
- 上POJ刷题
Online Judge系统 Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交给定问题的多种程序(如C.C++.Pascal.Java)源代码,系统对源代码进行 ...
- CAD绘制二维码(网页版)
js中实现代码说明: //新建一个COM组件对象 参数为COM组件类名 var getPt = mxOcx.NewComObject("IMxDrawUiPrPoint"); ge ...