第十五次codeforces竞技结束 #267 Div 2

267这场打得不怎么样……

个人感觉就是……阶梯性好强……题和题之间跳跃性真的需要这么大么……


A. George and Accommodation

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.

The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Output

Print a single integer — the number of rooms where George and Alex can move in.

Sample test(s)
input
3
1 1
2 2
3 3
output
0
input
3
1 10
0 10
10 10
output
2

好萌好萌好萌的题哇~ 用来刚学会a+b problem的孩子们做最适合不过了~

有n个房间,每行是这个房间现在有几个人,总共能住几个人,问:有几个房间里有2个空位……

23333 代码如下

Code:

#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))

bool cmp(const int a, const int b)
{
	return a > b;
}

int main()
{
	int n=0;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(b-a>=2)cnt++;
	}
	cout<<cnt;
	return 0;
}

B. Fedor and New Game

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».

The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer xi. Consider binary representation of xi: if the j-th bit of number xi equal to one, then the army of the i-th player has soldiers of the j-th type.

Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.

Input

The first line contains three integers nmk (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000).

The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.

Output

Print a single integer — the number of Fedor's potential friends.

Sample test(s)
input
7 3 1
8
5
111
17
output
0
input
3 3 3
1
2
3
4
output
3


不知道孩纸们知不知道这个运算符 :' ^ '

按位异或,如果这一位上的二进制位相同则为0,不同则为1.

这题的意思是有这么多个玩家,他们用二进制表示他们有哪些种类的兵力,最后一行是菲德尔,问有多少个人和他的兵种差距不大于k种。

那么……就直接用菲德尔(人)的兵种那个数字和别人异或一下看看有几个1咯~

代码如下:

Code

#include <cmath> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))

bool cmp(const int a, const int b)
{
	return a > b;
}

int army[1024];

int cnt_s(int a)
{
	int cnt=0,	tmp=a;
	while(tmp!=0)
	{
		cnt+=tmp%2;
		tmp/=2;
	} 
	return cnt;
}

int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	memset(army,0,sizeof army); 
	for(int i=1;i<=m+1;i++)
		scanf("%d",&army[i]);
	int cnt=0;
	for(int i=1;i<=m;i++)
		if(cnt_s(army[i]^army[m+1])<=k)cnt++;
	cout<<cnt;
	return 0;
}

C. George and Job

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.

Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers:

[l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 < l2 ≤ r2 < ... < lk ≤ rk ≤ nri - li + 1 = m), 

in such a way that the value of sum  is maximal possible. Help George to cope with the task.

Input

The first line contains three integers nm and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).

Output

Print an integer in a single line — the maximum possible value of sum.

Sample test(s)
input
5 2 1
1 2 3 4 5
output
9
input
7 1 3
2 10 7 18 5 33 0
output
61

题意是,有这么多数字,每次挑取连续的m个数,挑k次,这么多数字的和要求最大,每个数最多只允许被挑到一次

先获得每一个数的sum数组(它及它之前的所有数字之和)

然后通过sum[i]-sum[i-m]获得每一个m连数组的和

dp获得结果


代码如下:

Code:

#include<stdio.h>
#include<string.h>
typedef __int64 ll;
ll pre[5005],cur[5005],sum[5005],a[5005];
int n,m,k;

int main(void){
	int i,j;
	while(~scanf("%d%d%d",&n,&m,&k)){
		sum[0]=0;
		for(i=1;i<=n;i++){
			scanf("%I64d",&a[i]);
			sum[i]=sum[i-1]+a[i];
		}
		memset(pre,-1,sizeof(pre));
		for(i=m;i<=n;i++)
			pre[i]=cur[i]=sum[i]-sum[i-m];
		for(i=2;i<=k;i++){
			memset(cur,0,sizeof(cur));
			ll temp=0;
			for(j=m;j+m<=n;j++){
				if(pre[j]==-1) continue;
				if(pre[j]>temp) temp=pre[j];
				cur[j+m]=temp+sum[j+m]-sum[j];
			}
			memcpy(pre,cur,sizeof(pre));
		}
		ll ans=0;
		for(i=1;i<=n;i++) if(cur[i]>ans) ans=cur[i];
		printf("%I64d\n",ans);
	}
	return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值