[BZOJ5407]girls
也是CF985G。。。
容斥+三元环计数
CF数据太弱啦
vis没赋初值-1竟然过了QAQ
所以又调了我半个小时才搞掉QAQ
数数真难QAQ
记得要写#include<vector>!!!
Dev给加的奇奇怪怪的编译选项会给你自动填补的!!!
QAQ长个记性QAQ
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#define ull unsigned long long
#define ll long long
#define inf 20021225
#define N 400010
#define it vector<int>::iterator
using namespace std; int sz[N],deg[N],n,m;
vector<ull> sum[N];
vector<int> ed[N];
struct edge{int to,lt;}e[N];
int in[N],cnt; int vis[N];
void add(int x,int y){e[++cnt].to=y;e[cnt].lt=in[x];in[x]=cnt;}
void go(int x){for(int i=in[x];i;i=e[i].lt) vis[e[i].to]=x;}
ull calc(int x){if(x<) return ; return (ll)x*(x-)/;}
ull up(int l,int r){if(l>r) return ; return (ll)(r+l)*(r-l+)/;}
int main()
{
scanf("%d%d",&n,&m); ull A,B,C,res=;
scanf("%llu%llu%llu",&A,&B,&C); int x,y;
//scanf("%I64d%I64d%I64d",&A,&B,&C); int x,y;
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
ed[x].push_back(y);
ed[y].push_back(x);
}
//ull edg=(ull)n*(n-1)>>1;
//at least 0
for(int i=;i<n;i++)
res+=A*i*calc(n-i-),
res+=B*i*i*(n-i-),
res+=C*i*calc(i),
sort(ed[i].begin(),ed[i].end()),
sum[i].push_back();
//printf("%llu\n",res);
for(x=;x<n;x++) for(it i=ed[x].begin();i!=ed[x].end();i++)
sz[x]=(*i)>x?sz[x]:sz[x]+,++deg[x],sum[x].push_back(sum[x][deg[x]-]+(*i));
//at least 1
for(x=;x<n;x++) for(it i=ed[x].begin();i!=ed[x].end();i++)
if((*i)<x)
{
y=*i;
//x as B
res-=B*x*(n-x-);
res-=A*y*(n-x-);
res-=C*up(x+,n-);
//x as C
res-=A*up(,y-);
res-=B*y*y;
res-=B*up(y+,x-);
res-=A*y*(x-y->?x-y-:);
res-=C*x*(x-);
}
//printf("%llu\n",res);
//at least 2
//int dig;
//printf("%llu\n",res);
for(x=;x<n;x++) for(int i=;i<=deg[x];i++)
{
//printf("%d %llu\n",x,sum[x][i]);
//x has 2 edges out
y=ed[x][i-];
if(y>x)
{
//x is A
res+=A*x*(deg[x]-i); res+=B*y*(deg[x]-i);
res+=C*(sum[x][deg[x]]-sum[x][i]);
//printf("%d %d %llu\n",x,y,res);
}
else// if(y<x)
{
//x is B
res+=B*x*(deg[x]-sz[x]); res+=A*y*(deg[x]-sz[x]);
res+=C*(sum[x][deg[x]]-sum[x][sz[x]]);
//x is C
res+=C*x*(i-); res+=B*y*(i-);
res+=A*sum[x][i-];
}
}
//printf("%llu\n",res);
//at least 3
/**for(int i=1;i<=n;i++)
{
if(deg[i]<=top)
{
for(int j=0;j<deg[i];j++)
{
for(int k=j+1;k<deg[i];k++)
{
x=i; y=ed[x][j]; z=ed[x][k];
if(x>y) swap(x,y);
if(x>z) swap(x,z);
res-=A*x+B*y+C*z;
}
}
}
else big.push_back(i);
}*/
for(x=;x<n;x++) for(int i=;i<deg[x];i++)
if(deg[ed[x][i]]<deg[x] || (deg[ed[x][i]]==deg[x]&&ed[x][i]<x))
add(x,ed[x][i]);
memset(vis,-,sizeof(vis));
for(x=;x<n;x++)
{
go(x);
for(int i=in[x];i;i=e[i].lt)
{
y=e[i].to;
for(int j=in[y];j;j=e[j].lt)
{
if(vis[e[j].to]==x)
{
int xx=x,yy=y,zz=e[j].to;
if(xx>yy) swap(xx,yy);
if(xx>zz) swap(xx,zz);
if(yy>zz) swap(yy,zz);
res-=A*xx+B*yy+C*zz;
}
}
}
}
printf("%llu\n",res);
//printf("%I64u\n",res);
return ;
}
/**
4 1
2 3 4
1 0
*/
由于这个题调的我太过痛苦 写作业都写不进去
bug列举一下
1.我不会冒泡排序排三个数
2.(0,n-1)看成(1,n)重调系数非常蛋疼
3.初值就是忘了赋
4.系数和值少一个
5.手贱
[BZOJ5407]girls的更多相关文章
- 2013成都网络赛 C We Love MOE Girls(水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 123——Appium Girls活动
有感于Ruby Girls和Python Girls,在15年就想组织一次移动测试的妹子活动,框架选择Appium, 从15年夏天开始准备,申请Google的会议室,招募教练,开放报名,审核报名,到正 ...
- HDU 5145 NPY and girls 莫队+逆元
NPY and girls Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more! ...
- 回文串--- Girls' research
HDU 3294 Problem Description One day, sailormoon girls are so delighted that they intend to resear ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- 数学+高精度 ZOJ 2313 Chinese Girls' Amusement
题目传送门 /* 杭电一题(ACM_steps 2.2.4)的升级版,使用到高精度: 这次不是简单的猜出来的了,求的是GCD (n, k) == 1 最大的k(1, n/2): 1. 若n是奇数,则k ...
- Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Acdream Chinese Girls' Amusement
A - Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Jav ...
- HDU----(3294)Girls' research(manacher)
Girls' research Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)T ...
随机推荐
- SQL Server性能调优--索引
序言 索引的概念 索引是什么 数据库中的索引类似于一本书的目录,在一本书中使用目录可以快速找到你想要的信息,而不需要读完全书.在数据库中,数据库程序使用索引可以快速查询到表中的数据,而不必扫描整个表. ...
- Queue1循环队列
循环队列 1 #include<iostream> using namespace std; //#define maxSize 20 template <class T> c ...
- Java Web学习笔记之---EL和JSTL
Java Web学习笔记之---EL和JSTL (一)EL (1)EL作用 Expression Language(表达式语言),目的是代替JSP页面中复杂的代码 (2)EL表达式 ${变量名} ( ...
- 调试 & 常数优化:我有特别的 debug 技巧
rxz 的调试技巧(https://www.zhihu.com/question/60719584/answer/179363450): #define DEBUG printf("Pass ...
- js中的window对象:打开窗口
~~ window.open():打开一个窗口 里面需要放三个参数: 1.打开窗口(网页)的位置: 2.打开的方式(自身页面,新开页面): 其中_blank新开一个窗口 3.打开网页的属性: wind ...
- 如何获取url里面的参数
想必大家经常会遇到这样的问题吧,每次获取url参数的时候就一阵头疼,那现在我就教大家一个简单的方法,将url的参数转换成一个对象,用的时候直接用对象点出来就好了.不多说,直接上代码 function ...
- koa2 源码解读 application
koa2的源码比较简单,重点解读aplication, 其中context源码比较简单,主要是一些error cookies等,重点可以关注下delegate,delegate模块中,主要通过prot ...
- poj3669 Meteor Shower (宽度优先搜索)
Description - 题目描述 Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平面坐标系的原点放牧,打算在群星 ...
- python3 -tensorflow-dataset 之map函数 lambda隐函数的应用
###隐函数lanbda及map函数的应用实例 ''' lambda 参数1,参数2,参数3,...:表达式 ''' f = lambda x,y :x+y print(f(1,2)) ###输出3 ...
- python3标准库总结
Python3标准库 操作系统接口 os模块提供了不少与操作系统相关联的函数. ? 1 2 3 4 5 6 >>> import os >>> os.getcwd( ...