AtCoder Grand Contest 018 E - Sightseeing Plan

Problem Statement

Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the x-th from the west and the y-th from the north as (x,y).

Joisino thinks that a touring plan is good if it satisfies the following conditions:

  • Let (p,q) be the section where she starts the tour. Then, X1pX2 and Y1qY2 hold.

  • Let (s,t) be the section where she has lunch. Then, X3sX4 and Y3tY4 hold.

  • Let (u,v) be the section where she ends the tour. Then, X5uX6 and Y5vY6 hold.

  • By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.

Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way. Joisino would like to know how many different good touring plans there are. Find the number of the different good touring plans. Since it may be extremely large, find the count modulo 109+7.

Constraints

  • 1X1X2<X3X4<X5X6106
  • 1Y1Y2<Y3Y4<Y5Y6106

Input

Input is given from Standard Input in the following format:

X1 X2 X3 X4 X5 X6
Y1 Y2 Y3 Y4 Y5 Y6

Output

Print the number of the different good touring plans, modulo 109+7.


Sample Input 1

Copy
1 1 2 2 3 4
1 1 2 2 3 3

Sample Output 1

Copy
10

The starting section will always be (1,1), and the lunch section will always be (2,2). There are four good touring plans where (3,3) is the ending section, and six good touring plans where (4,3) is the ending section. Therefore, the answer is 6+4=10.


Sample Input 2

Copy
1 2 3 4 5 6
1 2 3 4 5 6

Sample Output 2

Copy
2346

Sample Input 3

Copy
77523 89555 420588 604360 845669 973451
2743 188053 544330 647651 709337 988194

Sample Output 3

Copy
137477680

题意:给三个矩形,从三个里面任取一个点,记为A,B,C,求从A到C经过B的方案数

题解:

记F(x, y)表示从(0, 0)走到(x, y)的方案数

那么有∑[x = 0 to X]F(x, Y) = F(X, Y + 1)

这个证明直接考虑从(0, 0)到(X, Y + 1)一定要从某纵坐标为Y的位置走到纵坐标Y+1的位置

然后就有∑[x = 0 to X][y = 0 to Y]F(x, y) = F(X + 1, Y + 1) - 1

故∑[x = x1 to x2][y = y1 to y2]F(x, y) = F(x2 + 1, y2 + 1) + F(x1, y1) - F(x1, y2 + 1) - F(x2 + 1, y1)

所以问题转为给一个点start,一个点end,中间一个给定矩形,枚举中间矩形内的每个点,求start到end经过这个点的方案数之和

我们可以计算一条start到end的路径跟矩形相交的部分的点数,那么这条路径的权值就是这个点数,我们就可以转为求路径权值和

再转化一下,一条路径跟矩形相交一定会从某个地方进去,某个地方出来,问题可以转为到4条直线的方案数*某个权值,这个直接统计就好了

权值很简单了,怎么构造见代码

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 2000005;
const int mod = 1e9 + 7;

int x[7], y[7], fac[MAXN], inv[MAXN], ans;

inline int C(int x, int y) { return 1LL * fac[x + y] * inv[x] % mod * inv[y] % mod; }
inline int F(int x1, int y1, int x2, int y2) { return (1LL * C(x2 + 1, y2 + 1) + C(x1, y1) - C(x1, y2 + 1) - C(x2 + 1, y1) + mod + mod) % mod; }

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	for (int i = 1; i <= 6; i ++)
		x[i] = Read();
	for (int i = 1; i <= 6; i ++)
		y[i] = Read();
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	for (int i = 2; i <= 2000000; i ++)
		fac[i] = 1LL * fac[i - 1] * i % mod, inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (int i = 2; i <= 2000000; i ++)
		inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
	for (int i = x[3]; i <= x[4]; i ++)
		ans = (1LL * (mod - y[3] - i) * F(i - x[2], y[3] - 1 - y[2], i - x[1], y[3] - 1 - y[1]) % mod * F(x[5] - i, y[5] - y[3], x[6] - i, y[6] - y[3]) + ans) % mod;
	for (int i = x[3]; i <= x[4]; i ++)
		ans = (1LL * (i + y[4] + 1) * F(i - x[2], y[4] - y[2], i - x[1], y[4] - y[1]) % mod * F(x[5] - i, y[5] - y[4] - 1, x[6] - i, y[6] - y[4] - 1) + ans) % mod;
	for (int i = y[3]; i <= y[4]; i ++)
		ans = (1LL * (mod - x[3] - i) * F(i - y[2], x[3] - 1 - x[2], i - y[1], x[3] - 1 - x[1]) % mod * F(y[5] - i, x[5] - x[3], y[6] - i, x[6] - x[3]) + ans) % mod;
	for (int i = y[3]; i <= y[4]; i ++)
		ans = (1LL * (i + x[4] + 1) * F(i - y[2], x[4] - x[2], i - y[1], x[4] - x[1]) % mod * F(y[5] - i, x[5] - x[4] - 1, y[6] - i, x[6] - x[4] - 1) + ans) % mod;
	return printf("%d\n", ans), 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AtCoder Practice Contest #B - インタラクティブ練習 (Interactive Sorting) 是一道比较有趣的题目。它是一道交互式的排序题目,需要你与一个神秘程序进行交互,以便将一串无序的数字序列排序。 具体来说,这个神秘程序会给你一个长度为 $N$ 的数字序列,然后你需要通过询问它两个数字的大小关系,来逐步确定这个序列的排序顺序。每次询问之后,神秘程序都会告诉你两个数字的大小关系,比如第一个数字比第二个数字小,或者第二个数字比第一个数字小。你需要根据这个信息,来调整这个数字序列的顺序,然后再向神秘程序询问下一对数字的大小关系,以此类推,直到这个数字序列被完全排序为止。 在这个过程中,你需要注意以下几点: 1. 你最多只能向神秘程序询问 $Q$ 次。如果超过了这个次数,那么你的程序会被判定为错误。 2. 在每次询问之后,你需要及时更新数字序列的顺序。具体来说,如果神秘程序告诉你第 $i$ 个数字比第 $j$ 个数字小,那么你需要将这两个数字交换位置,以确保数字序列的顺序是正确的。如果你没有及时更新数字序列的顺序,那么你的程序也会被判定为错误。 3. 在询问的过程中,你需要注意避免重复询问。具体来说,如果你已经询问过第 $i$ 个数字和第 $j$ 个数字的大小关系了,那么你就不需要再次询问第 $j$ 个数字和第 $i$ 个数字的大小关系,因为它们的大小关系已经被确定了。 4. 在排序完成之后,你需要将排序结果按照从小到大的顺序输出。如果你输出的结果不正确,那么你的程序也会被判定为错误。 总的来说,这道题目需要你熟练掌握交互式程序设计的技巧,以及排序算法的实现方法。如果你能够熟练掌握这些技巧,那么就可以顺利地完成这道非传统题了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值