Codeforces Beta Round #15

A - Cottage Village

A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses’ sides are parallel to the coordinate axes. It’s known that no two houses overlap, but they can touch each other.

The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn’t overlap any of the houses in the village.

Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

Input
The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output
Output the amount of possible positions of the new house.

Examples
Input
2 2
0 4
6 2
Output
4
Input
2 2
0 4
5 2
Output
3
Input
2 3
0 4
5 2
Output
2
Note
It is possible for the x-coordinate of the new house to have non-integer value.

这道题需要注意的地方是房子的位置可能不是整数,需要保存成浮点数类型

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e3 + 5;

struct st{
	double x, a;
}arr[N];

bool cmp(st a, st b)
{
	return a.x < b.x;
}

int main(void)
{
	int n, t, ans = 2;
	double d;
	cin >> n >> t;
	for (int i = 0; i < n; i++){
		cin >> arr[i].x >> arr[i].a;
	}
	sort(arr, arr + n, cmp);
	for (int i = 0; i < n - 1; i++){
		d = arr[i + 1].x - arr[i].x - (arr[i].a + arr[i + 1].a) / 2;
		if (d > t)
			ans += 2;
		else if (d == t)
			ans++;
	}
	cout << ans << endl;
	
	return 0;
} 

B - Laser

Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n × m cells and a robotic arm. Each cell of the field is a 1 × 1 square. The robotic arm has two lasers pointed at the field perpendicularly to its surface. At any one time lasers are pointed at the centres of some two cells. Since the lasers are on the robotic hand, their movements are synchronized — if you move one of the lasers by a vector, another one moves by the same vector.

The following facts about the experiment are known:

initially the whole field is covered with a chocolate bar of the size n × m, both lasers are located above the field and are active;
the chocolate melts within one cell of the field at which the laser is pointed;
all moves of the robotic arm should be parallel to the sides of the field, after each move the lasers should be pointed at the centres of some two cells;
at any one time both lasers should be pointed at the field. Petya doesn’t want to become a second Gordon Freeman.
You are given n, m and the cells (x1, y1) and (x2, y2), where the lasers are initially pointed at (xi is a column number, yi is a row number). Rows are numbered from 1 to m from top to bottom and columns are numbered from 1 to n from left to right. You are to find the amount of cells of the field on which the chocolate can’t be melted in the given conditions.

Input
The first line contains one integer number t (1 ≤ t ≤ 10000) — the number of test sets. Each of the following t lines describes one test set. Each line contains integer numbers n, m, x1, y1, x2, y2, separated by a space (2 ≤ n, m ≤ 109, 1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m). Cells (x1, y1) and (x2, y2) are distinct.

Output
Each of the t lines of the output should contain the answer to the corresponding input test set.

Examples
Input
2
4 4 1 1 3 3
4 3 1 1 2 2
Output
8
2

用两个矩形来表示两点能够到达的区域,如果两个矩形有相交的部分,需要减去。

题解链接:https://blog.csdn.net/codeswarrior/article/details/79330202

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

typedef long long ll;

int main(void)
{
	int t;
	ll m, n, x1, y1, x2, y2;
	ll dx, dy, cnt, ans;
	cin >> t;
	while (t--)
	{
		cin >> n >> m >> x1 >> y1 >> x2 >> y2;
		if (x1 > x2)
			swap(x1, x2);
		if (y1 > y2)
			swap(y1, y2);
		dx = n - x2 + x1;
		dy = m - y2 + y1;
		cnt = dx * dy * 2;
		if (dx * 2 > n || dy * 2 > m)
			cnt -= (dx * 2 - n) * (dy * 2 - m);
		ans = n * m - cnt;
		cout << ans << endl;
	}
	return 0;
}

C - Industrial Nim

There are n stone quarries in Petrograd.

Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.

Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses.

Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let’s call the one who takes the first stone «tolik» and the other one «bolik».

Input
The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.

Output
Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.

Examples
Input
2
2 1
3 2
Output
tolik
Input
4
1 1
1 1
1 1
1 1
Output
bolik

有 n 个 矿 场 , 每 个 矿 场 有 m i 个 翻 斗 车 , 第 i 个 矿 场 的 第 一 个 翻 斗 车 有 x i 个 石 子 , 第 二 个 翻 斗 车 有 x i + 1 个 石 子 . . . 第 m i 个 翻 斗 车 有 x i + m i − 1 个 石 子 有n个矿场,每个矿场有m_i个翻斗车,第i个矿场的第一个翻斗车有x_i个石子,第二个翻斗车有x_i+1个石子...第m_i个翻斗车有x_i+m_i-1个石子 nmiixixi+1...mixi+mi1

两 个 人 可 以 取 任 意 翻 斗 车 里 的 任 意 个 石 子 , 不 能 取 的 那 个 人 失 败 两个人可以取任意翻斗车里的任意个石子,不能取的那个人失败

可 以 看 出 是 尼 姆 博 弈 , 需 要 求 出 所 有 翻 斗 车 石 子 数 的 异 或 和 可以看出是尼姆博弈,需要求出所有翻斗车石子数的异或和

因 为 翻 斗 车 的 数 目 很 多 , 直 接 计 算 会 超 时 因为翻斗车的数目很多,直接计算会超时

又 因 为 每 个 矿 场 的 石 子 数 是 连 续 的 ( x i ~ x i + m i − 1 ) , 所 以 可 以 利 用 公 式 来 求 每 个 矿 场 石 子 数 的 异 或 和 又因为每个矿场的石子数是连续的(x_i~x_i+m_i-1),所以可以利用公式来求每个矿场石子数的异或和 xixi+mi1

题解链接:https://www.cnblogs.com/cbyyc/p/11493523.html

#include <cstdio>
using namespace std;
typedef long long ll;

ll f(ll x)
{
	if (x % 4 == 1) return 1;
    else if (x % 4 == 2) return x + 1;
    else if (x % 4 == 3) return 0;
    else return x; 
}

int main(void)
{
	ll n, x, m;
	ll ans = 0;
	scanf("%lld", &n);
	while (n--){
		scanf("%lld%lld", &x, &m);
		ans ^= f(x - 1) ^ f(x + m - 1);
	}
	if (ans)
		printf("tolik\n");
	else
		printf("bolik\n");
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值