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

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. 

题意:现在给你一个节目的n个愉快的瞬间。节目最多90分钟。 如果不愉快时间大于15分钟那么就会立马关掉节目。问最多能看节目多少分钟。

思路:题意模拟就好。  

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack> 
#include<bitset>
#include<vector> 
#include<algorithm>
using namespace std; 
const int MAXN=100+5;
#define INF 0x3f3f3f3f
int Time[MAXN];
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	while(scanf("%d",&n)!=EOF){
		Time[0]=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&Time[i]);
		}	
		int ans=-1;
		for(int i=1;i<=n;i++){
			if(Time[i]-Time[i-1]>15){
				ans=Time[i-1]+15;
				break;
			}
		}
		if(ans==-1){
			ans=min(90,Time[n]+15);
		}
		printf("%d\n",ans);
	}	
	return 0;
}

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 0000 ≤ 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 3may 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 to 2, so they may be used together.


题意:有n个题目。把n个题目分成2个部分,div1和div2,并且div1的题目难度要大于div2.题目标号即为题目难度. 即:题目1的难度为1 。。。     现在有m条关系, 即u,v不能再同一个div里。并且每个div里不能为空,问有多少种方案满足要求。 不存在输出0

思路:由于每一条关系u,v不能在同一个div,那么我们可以肯定一个在div1,一个在div2, 发现把难度小的放在div2,难度大的放在div1这样之后的扩展性会比较好。因为div1难度要大于div2,那么我们可以记录div2的最难的题目和div1最简单的题目。 然后根据m个关系判断是否存在合理的分配。 然后把没有约束的题目难度小于maxdiv2的都要放在div2,难度大于mindiv1的都要放在div1,剩下的就可以随意分配了。假设剩下k题可以随意分配,那么就有k+1种分配方案。 注意下每个div不能为空。如果div2为空,就把第一题给div2[最简单的题], 如果div1为空,就把最后一个给div1[最难的题].

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack> 
#include<bitset>
#include<vector> 
#include<algorithm>
using namespace std; 
const int MAXN=100000+5;
#define INF 0x3f3f3f3f
int vis[MAXN];
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		bool flag=false;
		int ans=0,maxdiv2=-1,mindiv1=INF;
		memset(vis,0,sizeof(vis));
		for(int i=0;i<m;i++){
			int u,v;
			scanf("%d%d",&u,&v);
			if(u>v){
				swap(u,v);
			}
			if(vis[u]==2||vis[v]==1||maxdiv2>mindiv1){
				flag=true;
			}
			if(!flag){
				vis[u]=1;vis[v]=2;
				maxdiv2=max(maxdiv2,u);
				mindiv1=min(mindiv1,v);
			}
		}
		if(flag||maxdiv2>mindiv1){
			printf("0\n");
			continue;
		}
		if(maxdiv2==-1){
			maxdiv2=1;  vis[1]=1;
		}
		if(mindiv1==INF){
			mindiv1=n; vis[n]=2;
		}
		for(int i=1;i<=n;i++){
			if(vis[i]==0&&i>maxdiv2&&i<mindiv1){
				ans++;
			}
		}
		printf("%d\n",ans+1);
	}	
	return 0;
}

C. Bear and Colors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.

For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.

There are  non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.

Output

Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.

Examples
input
4
1 2 1 2
output
7 3 0 0 
input
3
1 1 1
output
6 0 0 
Note

In the first sample, color 2 is dominant in three intervals:

  • An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
  • An interval [4, 4] contains one ball, with color 2 again.
  • An interval [2, 4] contains two balls of color 2 and one ball of color 1.

There are 7 more intervals and color 1 is dominant in all of them.


题意:给定n个颜色,和一个n个颜色组成序列。问每个颜色被当成dominant color的次数。 dominant color的定义为:区间颜色出现次数最多的,如果存在相同则取编号最小的颜色。

思路:暴力,枚举起点L,然后区间长度从1开始递增R,用一个cnt统计每个颜色的出现次数。当R增大时。看能否更新结果。

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<functional>  
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack> 
#include<bitset>
#include<vector> 
#include<algorithm>
using namespace std; 
const int MAXN=5000+5;
#define INF 0x3f3f3f3f
typedef long long int LL;
int t[MAXN],ans[MAXN],cnt[MAXN];
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	while(scanf("%d",&n)!=EOF){
		for(int i=1;i<=n;i++){
			scanf("%d",&t[i]);
		}
		memset(ans,0,sizeof(ans));
		for(int i=1;i<=n;i++){
			int maxcnt=-1,minpos=INF;
			memset(cnt,0,sizeof(cnt));
			for(int j=i;j<=n;j++){
				cnt[t[j]]++;
				if(cnt[t[j]]>maxcnt){
					maxcnt=cnt[t[j]];
					minpos=t[j];
				}
				else if(cnt[t[j]]==maxcnt){
					minpos=min(minpos,t[j]);
				}
				ans[minpos]++;
			}
			
		}
		for(int i=1;i<=n;i++){
			printf("%d",ans[i]);
			printf("%c",i==n?'\n':' ');
		}
	}	
	return 0;
}

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

Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.

Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:

  • There is no road between a and b.
  • There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = avn = b and there is a road between viand vi + 1 for .

On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = cun = d and there is a road between ui and ui + 1 for .

Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.

Given nk and four distinct cities abcd, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.

Input

The first line of the input contains two integers n and k (4 ≤ n ≤ 1000n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.

The second line contains four distinct integers abc and d (1 ≤ a, b, c, d ≤ n).

Output

Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.

Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y)and (y, x) are the same road.

Examples
input
7 11
2 4 7 3
output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
input
1000 999
10 20 30 40
output
-1
Note

In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.


题意:给定n个顶点和k条边。 还有4个点,a b c d要求找出一个图包括n个点和不超过k条边。并且输出一条路径从a->...->b   另一条路径从c->....->d,并且每条路径要都经过所以顶点一次并且仅一次。 不存在这样的路径输出-1

思路:模拟写几组数据可以发现当n=4或者n>=k时不存在这样的图。其他情况都满足。 对于a->..->b的路径: a->c->[其他非a b c d的点]->d->b  . 对于c->..->d的路径:c->a->[其他非a b c d的点]->b->d。 因为同时满足这2个路径的要求至少有n+1条边。

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<functional>  
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack> 
#include<bitset>
#include<vector> 
#include<algorithm>
using namespace std; 
const int MAXN=5000+5;
#define INF 0x3f3f3f3f
typedef long long int LL;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(n==4||k<=n){
			printf("-1\n");
		}
		else{
			printf("%d %d ",a,c);
			for(int i=1;i<=n;i++){
				if(!(i==a||i==b||i==c||i==d)){
					printf("%d ",i);
				}
			}
			printf("%d %d\n",d,b);
			printf("%d %d ",c,a);
			for(int i=1;i<=n;i++){
				if(!(i==a||i==b||i==c||i==d)){
					printf("%d ",i);
				}
			}
			printf("%d %d\n",b,d);
		}
	}	
	return 0;
}

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值