题目链接

题目大意

给你一个边长为n的正方形和边长为a和b的正方形,要求把边长为a和b的正方形放在长度为n的正方形内,且没有覆盖(可以相邻)求有多少种放法(mod 1e9+7)

题目思路

这个思路不是很容易想

假设a正方形在b正方形左边

那么只考虑纵坐标,还剩下n-a-b个空格,根据插空法则有C(n-a-b+1,2)种方法,然而需要注意可以这两个三角形可以插在一个空格里面则要加n-a-b+1,则总方案为C(n-a-b+2,2)然后考虑横坐标,那么a正方形有(n-a+1)种方法,b三角形有(n-b+1)种放法

那么总共可以有\(C(n-a-b+1,2)*(n-a+1)*(n-b+1)\)

还可以让a在b右边,上面,下面。由于是正方形所以直接答案4

但是你会发现会有重复的,为什么有的即是他的左边也是他的上面即同时满足两个条件的...

就是满足两个条件即\(C(n-a-b+1,2)*C(n-a-b+1,2)\)

显然也需要乘以4

那么ans=\(4*(C(n-a-b+1,2)*(n-a+1)*(n-b+1)-C(n-a-b+1,2)*C(n-a-b+1,2))\)

注意取模即可

代码

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
//#include<unordered_map>
#define fi first
#define se second
#define debug printf(" I am here\n");
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const double pi=acos(-1);
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=2e3+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-10;
ll n,a,b;
signed main(){
int _;scanf("%d",&_);
while(_--){
scanf("%lld%lld%lld",&n,&a,&b);
if(n<a+b){
printf("0\n");
}else{
ll ans1=2*(n-a-b+2)%mod*(n-a-b+1)%mod*(n-a+1)%mod*(n-b+1)%mod;
ll ans2=(n-a-b+2)*(n-a-b+1)%mod*(n-a-b+2)%mod*(n-a-b+1)%mod;
printf("%lld\n",((ans1-ans2)%mod+mod)%mod);
}
}
return 0;
}

HHKB Programming Contest 2020 D - Squares 题解(思维)的更多相关文章

  1. HHKB Programming Contest 2020【ABCE】

    比赛链接:https://atcoder.jp/contests/hhkb2020/tasks A - Keyboard 代码 #include <bits/stdc++.h> using ...

  2. Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 D题题解

    将题意转换为一开始\(t = 0\),第\(i\)个操作是令\(t \leftarrow (a_i + 1) t + (a_i + b_i + 1)\).记\(A_i = a_i + 1, B_i = ...

  3. Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 C题题解

    首先,我们将题目理解成若\(i\)与\(j\)距离恰好为\(3\),则不可能\(p_i \equiv p_j \equiv 1 \space or \space 2 (\bmod 3)\).这就相当于 ...

  4. M-SOLUTIONS Programming Contest 2020 题解

    M-SOLUTIONS Programming Contest 2020 题解 目录 M-SOLUTIONS Programming Contest 2020 题解 A - Kyu in AtCode ...

  5. atcoder Keyence Programming Contest 2020 题解

    比赛地址 A 题意:给一个\(n*m\)的初始为白色的矩阵,一次操作可以将一行或一列染成 黑色,问至少染出\(k\)个黑点的最少操作次数. \(n\),\(m\)<=100,\(k\)<= ...

  6. 2021.7.27--Benelux Algorithm Programming Contest 2020 补提

    I Jigsaw 题目内容: 链接:https://ac.nowcoder.com/acm/contest/18454/I 来源:牛客网 You have found an old jigsaw pu ...

  7. Atcoder Panasonic Programming Contest 2020

    前三题随便写,D题是一道dfs的水题,但当时没有找到规律,直接卡到结束 A - Kth Term /  Time Limit: 2 sec / Memory Limit: 1024 MB Score ...

  8. 2017, X Samara Regional Intercollegiate Programming Contest E. Bonuses and Teleports (思维,模拟)

    题意:在\(x\)轴上有很多传送点和钻石,当位于传送点上时,可以传送到其他任意传送点(不记操作数),位于钻石上时可以吃掉它,每次可以移动一个单位,问最少多少次可以吃掉所有的钻石. 题解:对于某个位置上 ...

  9. AtCoder AIsing Programming Contest 2020 D - Anything Goes to Zero (二进制,模拟)

    题意:给你一个长度为\(n\)的\(01\)串,从高位到低位遍历,对该位取反,用得到的十进制数\(mod\)所有位上\(1\)的个数,不断循环直到为\(0\),输出每次遍历时循环的次数. 题解:根据题 ...

随机推荐

  1. localStorage 用法

    localStorage使用总结   一.什么是localStorage.sessionStorage 在HTML5中,新加入了一个localStorage特性,这个特性主要是用来作为本地存储来使用的 ...

  2. ServletUtils取值(限foton)

    1.String query = ServletUtils.getStringValue(request, "query", null); 2.boolean reload = S ...

  3. 【转】Hello SDL: Your First Graphics Window

    FROM: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php Hello SDL: Your First Graphics Window ...

  4. IOCP 模型1

    // IOCP.cpp : Defines the entry point for the console application. // // #include "stdafx.h&quo ...

  5. 修改redo log 的大小

    alert日志中含有大量警告信息:"Thread 1 cannot allocate new log, sequence 320xx Checkpoint not complete" ...

  6. SpringCloud之Gateway

    一.为什么选择SpringCloud Gateway而不是Zuul? Gateway和Zuul的职责一样,都承担着请求分发,类似Nginx分发到后端服务器. 1.SpingCloud Gateway ...

  7. 「APIO2015」巴邻旁之桥 Palembang Bridges

    贪心 先转化一下题意 首先如果一个人的家和办公室在河同一侧那么建桥的时候不用去考虑它,最终把答案加上即可 在河两侧的家和办公室互换不影响答案,那么可以把这个抽象到一个区间$[l,r]$,距离就是$|l ...

  8. 9_Palindrome Number

    9.Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome when it ...

  9. 【17】进大厂必须掌握的面试题-50个Angular面试

    我们整理了一份主要的Angular面试问题清单,分为三部分: 角度面试问题–初学者水平 角度面试问题–中级 角度面试问题–高级 初学者水平–面试问题 1.区分Angular和AngularJS. 特征 ...

  10. OJ-1:时钟问题【九度1553】

    题目描述: 如图,给定任意时刻,求时针和分针的夹角(劣弧所对应的角). 输入: 输入包含多组测试数据,每组测试数据由一个按hh:mm表示的时刻组成. 输出: 对于每组测试数据,输出一个浮点数,代表时针 ...