Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem
题目链接:传送门
题目大意:给你n个区间,求任意k个区间交所包含点的数目之和。
题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt与k的组合数) ans=ans+(len*C(cnt,k))%mod;
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #include <cstring>
- #include <stack>
- #include <cctype>
- #include <queue>
- #include <string>
- #include <vector>
- #include <set>
- #include <map>
- #include <climits>
- #define lson root<<1,l,mid
- #define rson root<<1|1,mid+1,r
- #define fi first
- #define se second
- #define ping(x,y) ((x-y)*(x-y))
- #define mst(x,y) memset(x,y,sizeof(x))
- #define mcp(x,y) memcpy(x,y,sizeof(y))
- using namespace std;
- #define gamma 0.5772156649015328606065120
- #define MOD 1000000007
- #define inf 0x3f3f3f3f
- #define N 200005
- #define maxn 1050
- typedef pair<int,int> PII;
- typedef long long LL;
- int n,k,m,cnt;
- LL fac[N];
- struct Node{
- int x,v;
- bool operator<(const Node&a)const{
- if(x==a.x)return v>a.v;
- return x<a.x;
- }
- }node[N<<];
- int a[N<<],sum[N<<];
- int has[N<<];
- LL ksm(LL a,LL b){
- LL res=;
- while(b){
- if(b&)res=res*a%MOD;
- b>>=;
- a=a*a%MOD;
- }
- return res;
- }
- LL C(LL n,LL m){
- if(n<m||m<)return ;
- LL s1=fac[n],s2=fac[n-m]*fac[m]%MOD;
- return s1*ksm(s2,MOD-)%MOD;
- }
- int main(){
- int i,j,group,x,y,v;
- fac[]=;cnt=;
- for(i=;i<N;++i)fac[i]=fac[i-]*i%MOD;
- scanf("%d%d",&n,&k);
- for(i=;i<=n;++i){
- scanf("%d%d",&x,&y);
- node[cnt].x=x;node[cnt++].v=;
- node[cnt].x=y+;node[cnt++].v=-;
- }
- sort(node,node+cnt);
- LL ans=,la,num=; ///la是区间左端点
- for(i=;i<cnt;++i){
- if(num>=k) ans=(ans+(node[i].x-la*1ll)*C(num,k))%MOD;
- la=node[i].x;
- num+=node[i].v;
- }
- printf("%I64d\n",ans);
- return ;
- }
Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem的更多相关文章
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元
E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...
- Codeforces Round #361 (Div. 2) B. Mike and Shortcuts bfs
B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mi ...
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- Codeforces Round #361 (Div. 2)——B. Mike and Shortcuts(BFS+小坑)
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #361 (Div. 2)A. Mike and Cellphone
A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- 系统流畅/性能受限 谷歌Nexus4详细评测
http://mobile.it168.com/a2012/1220/1437/000001437938_8.shtml
- 异常:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z/Caused by: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreign
Spring3.0 + Hibernate3.5:启动服务器报:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany. ...
- linux磁盘满时,如何定位并删除文件
原文链接: http://www.cnblogs.com/yinxiangpei/articles/4211743.html @1.一般情况 一般情况下先df看一下,然后cd到要满的盘,执行: d ...
- C# 共享内存(转)
以下是一个C#操作内存的一个类,只要将下面的类添加到相应的项目中,该项目就可以对内存进行直接操作! using System.Runtime.InteropServices; //添加如下命名空 ...
- unity3d的NGUI简易登录界面
1.拖两个文本框和一个按钮在界面上,并做相应的重命名处理,结果如下图: 2.新建一个脚本,附加到“Login”上,脚本内容如下: public UIInput name; public UIInput ...
- C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库
C# DateTime的11种构造函数 别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...
- mysql事务块处理
begin ,rollback,commit .当然有的人用begin /begin work .推荐用START TRANSACTION 是SQL-99标准启动一个事务. start transac ...
- unity5, assert
assert可以实现“三步一岗五步一哨”可以说是保证代码正确性(安全编程)的最有力工具.在用c++写程序的时候assert语句总是要占整个程序的大部分篇幅. 但是转到unity c#,一开始没找到as ...
- layui基础上的tree菜单动态渲染;
var layout=[ { title:'脚本对象名称', treeNodes:true, headerClass:'value_col', colClass:'value_col', style: ...
- ListView嵌套GridView使用详解及注意事项
ListView嵌套GridView即ListView的每个Item中都包含一个GridView:需要注意的是由于ListView和GridView都是可滑动的控件. 所以需要自定义GridView, ...