【题解】[NOI2019Route](70分)
占坑
做法是拆掉所有式子,拆完式子看一下,如果A=0,发现边被分为了终点走向n的边和不走向n的边。所以边就有了新的边权,并且可以相加。然后通过网络流建模的套路建模使得满足时间的限制,然后由于有负边,所以跑spfa,这里60分。然后还有两个点是一条链,送10分。
先放代码,还没测,可能会爆零。交上去的爆零了因为没写freopenQAQ
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ERP(t,a) for(register int t=head[a];t;t=e[t].nx)
using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
namespace sol1{
const int maxn=3e5+5;
struct E{
int fr,to,st,ed;
E(){to=fr=st=ed=0;}
E(const int&a,const int&b,const int&c,const int&d){
fr=a;to=b;st=c;ed=d;
}
}data[maxn];
ll w[maxn];
int arc[maxn];
int cnt;
int nodecnt;
typedef pair < ll , int > P;
//priority_queue< P , vector<P>,greater <P> > q;
queue<P> q;
bool in[maxn<<2];
vector < int > fr[maxn],to[maxn];
vector < P > e[maxn<<2];
inline bool cmp(const int&a,const int&b){
return data[a].ed>data[b].ed;
}
int n,m,A,B,C;
inline bool cmp2(const int&a,const int&b){
return data[a].st>data[b].st;
}
ll d[maxn<<2];
inline ll spfa(){
for(register int t=1;t<maxn<<2;++t) d[t]=2e18;
d[0]=0;in[0]=1;
q.push(make_pair(0,0));
while(!q.empty()){
P cur=q.front();
q.pop();in[cur.second]=0;
for(register int t=0,edd=e[cur.second].size();t<edd;++t){
//cout<<d[e[cur.second][t].second]<<' '<<d[cur.second]+e[cur.second][t].first<<endl;
if(d[e[cur.second][t].second]>d[cur.second]+e[cur.second][t].first){
d[e[cur.second][t].second]=d[cur.second]+e[cur.second][t].first;
if(!in[e[cur.second][t].second])
q.push(make_pair(d[e[cur.second][t].second],e[cur.second][t].second)),in[e[cur.second][t].second]=1;
}
}
}
return d[m+1];
}
inline void add(const int&fr,const int&to,const ll&w){
//cout<<"fr="<<fr<<' '<<"to="<<to<<" w="<<w<<endl;
e[fr].push_back(make_pair(w,to));
}
inline int init(const int&a,const int&b,const int&c,const int&d1,const int&e1){
n=a;m=b;A=c;B=d1;C=e1;
nodecnt=n;
for(register int t=1,x,y,p,q;t<=m;++t){
x=qr();y=qr();p=qr();q=qr();
//cout<<x<<' '<<y<<' '<<p<<' '<<q<<endl;
data[t]=E(x,y,p,q);
w[t]=C+1ll*B*p+1ll*A*p*p;
if(y!=n) w[t]=w[t]+1ll*A*q*q-1ll*B*q;
if(y==n) w[t]=w[t]+0ll+q;
fr[x].push_back(t);to[y].push_back(t);
if(x==1) add(0,t,w[t]);
if(y==n) add(t,m+1,0);
}
for(register int t=1;t<=n;++t){
//if(fr[t].empty()||to[t].empty())continue;
sort(to[t].begin(),to[t].end(),cmp);
sort(fr[t].begin(),fr[t].end(),cmp2);
int k=0;/*
cout<<t<<' '<<fr[t].size()<<' '<<to[t].size()<<endl;
cout<<"fr=";
for(auto f:fr[t])
cout<<f<<" ";
putchar('\n');
cout<<"to=";
for(auto f:to[t])
cout<<f<<" ";
putchar('\n');
*/
for(register int i=0,edd=to[t].size(),ed2=fr[t].size();i<edd;++i){
if(i<edd-1)add(to[t][i+1],to[t][i],0);
while(k<ed2&&data[fr[t][k]].st>=data[to[t][i]].ed) add(to[t][i],fr[t][k],w[fr[t][k]]),++k;
}
}
cout<<spfa()<<endl;
return 0;
}
}
int main(){
freopen("route.in","r",stdin);
freopen("route.out","w",stdout);
int a=qr(),b=qr(),c=qr(),d=qr(),e=qr();
if(a<=100&&b==a-1&&c!=0){
ll A=c,B=d,C=e;
ll ans=1ll*a*C;
ll t1=0,t2=0,t3=0;
for(register int t=1;t<=b;++t){
qr();qr();t1=qr();t2=qr();
ans+=B*(t1-t3)+A*(t1-t3)*(t1-t3);
t3=t2;
}
cout<<ans+t3<<endl;
return 0;
}
return sol1::init(a,b,c,d,e);
return 0;
}
【题解】[NOI2019Route](70分)的更多相关文章
- 洛谷P4559 [JSOI2018]列队 【70分二分 + 主席树】
题目链接 洛谷P4559 题解 只会做\(70\)分的\(O(nlog^2n)\) 如果本来就在区间内的人是不用动的,区间右边的人往区间最右的那些空位跑,区间左边的人往区间最左的那些空位跑 找到这些空 ...
- 「PKUSC2018」星际穿越 (70分做法)
5371: [Pkusc2018]星际穿越 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 27 Solved: 11[Submit][Status] ...
- 洛谷P1979 华容道(70分 暴力)
P1979 华容道 题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少 ...
- 洛谷P1081 开车旅行70分
https://www.luogu.org/problem/show?pid=1081 太遗憾了明明写出来了,却把最小值初始值弄小了,从第二个点开始就不可能对了.70分! #include<io ...
- 华容道 noip2013 70分搜索
题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...
- ccf 201712-4 行车路线(70分)
ccf 201712-4 行车路线 解题思路: 首先Dijkstra是基于贪心算法的,即每一次作出的选择都具有贪心选择性.此题由于有“如果连续走小道,小明的疲劳值会快速增加,连续走s公里小明会增加s2 ...
- Cogs 1264. [NOIP2012] 开车旅行(70分 暴力)
1264. [NOIP2012] 开车旅行 ★★☆ 输入文件:drive.in 输出文件:drive.out 简单对比时间限制:2 s 内存限制:128 MB [题目描述] 小A 和小 ...
- 【NOI2016】优秀的拆分 题解(95分)
题目大意: 求一个字符串中形如AABB的子串个数. 思路: 用哈希做到O(1)判断字符串是否相同,O($n^2$)预处理,ans[i]为开头位置为i的形如AA的子串个数.再用O($n^2$)枚举出AA ...
- ACM: 限时训练题解-Runtime Error-二分查找
Runtime Error Bahosain was trying to solve this simple problem, but he got a Runtime Error on one ...
随机推荐
- HZOJ 方程的解
乍一看还以为是道水题,没想到这玩意这么难搞. 看题显然是exgcd,然而exgcd求的是一个解而不是解的个数(考试的时候不记得通解的式子然后挂了). 对于40%的数据,直接枚举计数即可. 对于另为20 ...
- 关于XIFF开发IM的一些想法
因为发现网上XIFF的资料真的不多,何况现在gg又被和谐,查询资料很是不便.我写这篇文章的目的除了跟大家分享一些开发心得,也希望有类似经验的朋友看到文章后有机会多多交流. 之前我没有怎么接触过flas ...
- H3C OSI参考模型层次结构
- JavaScript的一些SAO操作
IE判断检测 jQuery 在 1.9 版本之前,提供了一个浏览器对象检测的属性 使用率极高.但是在版本发布之后,大家钟爱的这个属性被无情的抛弃了.大家开始着手寻找.browser 的替代方案.于是各 ...
- Python--day69--ORM聚合查询和分组查询
聚合查询和分组查询 聚合 aggregate()是QuerySet 的一个终止子句,意思是说,它返回一个包含一些键值对的字典. 键的名称是聚合值的标识符,值是计算出来的聚合值.键的名称是按照字段和聚合 ...
- H3C 用debugging ppp all命令调试PPP
- Pytorch的LSTM的理解
class torch.nn.LSTM(*args, **kwargs) 参数列表 input_size:x的特征维度 hidden_size:隐藏层的特征维度 num_layers:lstm隐层的层 ...
- 1、Python 日期时间格式化输出
今天帮朋友写自动化脚本,又需要用格式化日期,又忘记怎么写了,还是写到自己博客里面,方便日后需要的时候看一眼吧.So,临时加一篇 Python 的文章. 1.Python的time模块 import t ...
- js(一) 三大事件 实现注册验证
ps:小声比比,为什么一周多没更,因为js真的好难啊. 上一周做了一整周的jsp+sevlet+mysql做了一个MVC模式的最基本的新闻系统源码会有空搞出来的 好累 好多的. 三大事件 (鼠标事件. ...
- CentOS7 添加FTP用户并设置权限
step 1 安装配置Vsftp服务器 一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewal ...