链接:HDU - 6409:没有兄弟的舞会

题意:

题解:

求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中。枚举每一个最大值,那么每一个区间的对于答案的贡献就是一个等差数列的和(乘法分配律),将每一个和乘起来就是该最大值的对于答案的贡献。但是相同最大值可能来自于多个区间,如果枚举每一个可能出现最大值的区间,那么会超时,所以需要一个神奇的方法,我也不知道原理是什么,但是数学上就是直接的式子,可以分解出来。

#include <bits/stdc++.h>
using namespace std; const double EPS = 1e-;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
const int maxn = 1e4 + ;
int n;
int l[maxn], r[maxn]; void Exgcd(long long a, long long b, long long& x, long long& y)
{
if(!b){
y = ; x = ;
return ;
}
Exgcd(b, a % b, y, x);
y -= a / b * x;
} long long NY(long long a, long long b)
{
long long x, y;
Exgcd(a, b, x, y);
return (x % mod + mod) % mod;
} long long Inv(int l[], int r[], int n)
{
long long ans = ;
for(int i = ; i < n; i++){
ans = ans * (r[i] - l[i] + ) % mod;
}
return NY(ans, mod);
} int main()
{ int T;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int L = , R = ;
for(int i = ; i < n; i++){
scanf("%d%d", &l[i], &r[i]);
L = max(L, l[i]);
R = max(R, r[i]);
} long long ans = ;
for(int h = L; h <= R; h++){
long long cnt = , num = ;
for(int i = ; i < n; i++){
long long x = h - l[i] + , y = max(, h - r[i]) + ;
long long sum = (x + y) * (x - y + ) / ;
cnt = cnt * sum % mod; if(r[i] >= h) num = num * (sum - ) % mod;
else num = num * sum % mod;
}
ans = ((ans + cnt - num) % mod + mod) % mod;
} ans = ans * Inv(l, r, n) % mod; printf("%lld\n", ans);
}
return ;
}

HDU - 6409:没有兄弟的舞会(数学+思维)的更多相关文章

  1. HDU 6659 Acesrc and Good Numbers (数学 思维)

    2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...

  2. HDU 2674 N!Again(数学思维水题)

    题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...

  3. 程序设计中的数学思维函数总结(代码以C#为例)

    最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...

  4. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  5. UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律

    UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...

  6. B. Tell Your World(几何数学 + 思维)

    B. Tell Your World time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. HDU 4611 Balls Rearrangement (数学-思维逻辑题)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4611 题意:给你一个N.A.B,要你求 AC代码: #include <iostream> ...

  8. hdu 4710 Balls Rearrangement (数学思维)

    意甲冠军:那是,  从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号 ...

  9. HDU - 6304(2018 Multi-University Training Contest 1) Chiaki Sequence Revisited(数学+思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=6304 题意 给出一个数列的定义,a[1]=a[2]=1,a[n]=a[n-a[n-1]]+a[n-1-a[n-2 ...

随机推荐

  1. spring配置redis(xml+java方式)(最底层)

    条件:引用好架包 <dependency> <groupId>org.springframework.data</groupId> <artifactId&g ...

  2. CSS3-阴影参数基础

    box-shadow 语法:text-shadow: x-shadow y-shadow distance color; 值  描述  x-shadow  必需.水平阴影的位置.允许负值. y-sha ...

  3. 轻量ORM-SqlRepoEx (十一)扩展

    以下为 SqlRepoEx.MsSql.ServiceCollection 代码 public static IServiceCollection AddSqlRepo(this IServiceCo ...

  4. ssm调用后台oracle存储过程统计分析数据

    笔者所在项目需要一个统计本机构近6月收入情况(分两种).本机构下级机构收入情况的需求,数据量为百万级. 具体需求是时间.机构都不确定,可为入参. 综合考虑后决定使用后台存储过程统计. 基础表结构如下: ...

  5. datatable去掉表头默认排序

    禁用排序:"ordering":false 某一列禁用排序:"orderable":false 以某一列排序:"order":[[x,&qu ...

  6. shell习题第1题:每日一文件

    [题目要求] 请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件 例如生成的文件为2019-04-25.log,并且把磁盘使用情况写入到这个文件中 不用考虑cron,仅仅写脚本即可 [核心要 ...

  7. 「PHP」简单工厂模式

    引言   所属:创建型模式,常用设计模式之一 工厂模式分为:简单工厂模式.工厂方法模式.静态工厂模式.抽象工厂模式. 下面为简单工厂模式.   参考资料: <大话设计模式>程杰   模式概 ...

  8. freeswitch对话机320信令在专有网络情况下不生效的处理

    昨天处理客户提出的话机设置呼叫转移不生效的问题, 经过多次测试发现这个问题与freeswitch版本和配置没有关系, 后来分析freeswitch正常转移日志与不转移日志发现不转移的日志少了一行 Re ...

  9. 『Python基础-1 』 编程语言Python的基础背景知识

    #『Python基础-1 』 编程语言Python的基础背景知识 目录: 1.编程语言 1.1 什么是编程语言 1.2 编程语言的种类 1.3 常见的编程语言 1.4 编译型语言和解释型语言的对比 2 ...

  10. rails应用页面导出为pdf文档

    1.下载安装wkhtmltox https://wkhtmltopdf.org/downloads.html   2.gemfile添加 gem 'pdfkit' #页面导出pdf gem 'wkht ...