占坑

做法是拆掉所有式子,拆完式子看一下,如果A=0,发现边被分为了终点走向n的边和不走向n的边。所以边就有了新的边权,并且可以相加。然后通过网络流建模的套路建模使得满足时间的限制,然后由于有负边,所以跑spfa,这里60分。然后还有两个点是一条链,送10分。

先放代码,还没测,可能会爆零。交上去的爆零了因为没写freopenQAQ


  1. //@winlere
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<queue>
  7. #define ERP(t,a) for(register int t=head[a];t;t=e[t].nx)
  8. using namespace std; typedef long long ll;
  9. inline int qr(){
  10. register int ret=0,f=0;
  11. register char c=getchar();
  12. while(c<48||c>57)f|=c==45,c=getchar();
  13. while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
  14. return f?-ret:ret;
  15. }
  16. namespace sol1{
  17. const int maxn=3e5+5;
  18. struct E{
  19. int fr,to,st,ed;
  20. E(){to=fr=st=ed=0;}
  21. E(const int&a,const int&b,const int&c,const int&d){
  22. fr=a;to=b;st=c;ed=d;
  23. }
  24. }data[maxn];
  25. ll w[maxn];
  26. int arc[maxn];
  27. int cnt;
  28. int nodecnt;
  29. typedef pair < ll , int > P;
  30. //priority_queue< P , vector<P>,greater <P> > q;
  31. queue<P> q;
  32. bool in[maxn<<2];
  33. vector < int > fr[maxn],to[maxn];
  34. vector < P > e[maxn<<2];
  35. inline bool cmp(const int&a,const int&b){
  36. return data[a].ed>data[b].ed;
  37. }
  38. int n,m,A,B,C;
  39. inline bool cmp2(const int&a,const int&b){
  40. return data[a].st>data[b].st;
  41. }
  42. ll d[maxn<<2];
  43. inline ll spfa(){
  44. for(register int t=1;t<maxn<<2;++t) d[t]=2e18;
  45. d[0]=0;in[0]=1;
  46. q.push(make_pair(0,0));
  47. while(!q.empty()){
  48. P cur=q.front();
  49. q.pop();in[cur.second]=0;
  50. for(register int t=0,edd=e[cur.second].size();t<edd;++t){
  51. //cout<<d[e[cur.second][t].second]<<' '<<d[cur.second]+e[cur.second][t].first<<endl;
  52. if(d[e[cur.second][t].second]>d[cur.second]+e[cur.second][t].first){
  53. d[e[cur.second][t].second]=d[cur.second]+e[cur.second][t].first;
  54. if(!in[e[cur.second][t].second])
  55. q.push(make_pair(d[e[cur.second][t].second],e[cur.second][t].second)),in[e[cur.second][t].second]=1;
  56. }
  57. }
  58. }
  59. return d[m+1];
  60. }
  61. inline void add(const int&fr,const int&to,const ll&w){
  62. //cout<<"fr="<<fr<<' '<<"to="<<to<<" w="<<w<<endl;
  63. e[fr].push_back(make_pair(w,to));
  64. }
  65. inline int init(const int&a,const int&b,const int&c,const int&d1,const int&e1){
  66. n=a;m=b;A=c;B=d1;C=e1;
  67. nodecnt=n;
  68. for(register int t=1,x,y,p,q;t<=m;++t){
  69. x=qr();y=qr();p=qr();q=qr();
  70. //cout<<x<<' '<<y<<' '<<p<<' '<<q<<endl;
  71. data[t]=E(x,y,p,q);
  72. w[t]=C+1ll*B*p+1ll*A*p*p;
  73. if(y!=n) w[t]=w[t]+1ll*A*q*q-1ll*B*q;
  74. if(y==n) w[t]=w[t]+0ll+q;
  75. fr[x].push_back(t);to[y].push_back(t);
  76. if(x==1) add(0,t,w[t]);
  77. if(y==n) add(t,m+1,0);
  78. }
  79. for(register int t=1;t<=n;++t){
  80. //if(fr[t].empty()||to[t].empty())continue;
  81. sort(to[t].begin(),to[t].end(),cmp);
  82. sort(fr[t].begin(),fr[t].end(),cmp2);
  83. int k=0;/*
  84. cout<<t<<' '<<fr[t].size()<<' '<<to[t].size()<<endl;
  85. cout<<"fr=";
  86. for(auto f:fr[t])
  87. cout<<f<<" ";
  88. putchar('\n');
  89. cout<<"to=";
  90. for(auto f:to[t])
  91. cout<<f<<" ";
  92. putchar('\n');
  93. */
  94. for(register int i=0,edd=to[t].size(),ed2=fr[t].size();i<edd;++i){
  95. if(i<edd-1)add(to[t][i+1],to[t][i],0);
  96. 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;
  97. }
  98. }
  99. cout<<spfa()<<endl;
  100. return 0;
  101. }
  102. }
  103. int main(){
  104. freopen("route.in","r",stdin);
  105. freopen("route.out","w",stdout);
  106. int a=qr(),b=qr(),c=qr(),d=qr(),e=qr();
  107. if(a<=100&&b==a-1&&c!=0){
  108. ll A=c,B=d,C=e;
  109. ll ans=1ll*a*C;
  110. ll t1=0,t2=0,t3=0;
  111. for(register int t=1;t<=b;++t){
  112. qr();qr();t1=qr();t2=qr();
  113. ans+=B*(t1-t3)+A*(t1-t3)*(t1-t3);
  114. t3=t2;
  115. }
  116. cout<<ans+t3<<endl;
  117. return 0;
  118. }
  119. return sol1::init(a,b,c,d,e);
  120. return 0;
  121. }

【题解】[NOI2019Route](70分)的更多相关文章

  1. 洛谷P4559 [JSOI2018]列队 【70分二分 + 主席树】

    题目链接 洛谷P4559 题解 只会做\(70\)分的\(O(nlog^2n)\) 如果本来就在区间内的人是不用动的,区间右边的人往区间最右的那些空位跑,区间左边的人往区间最左的那些空位跑 找到这些空 ...

  2. 「PKUSC2018」星际穿越 (70分做法)

    5371: [Pkusc2018]星际穿越 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 27  Solved: 11[Submit][Status] ...

  3. 洛谷P1979 华容道(70分 暴力)

    P1979 华容道 题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少 ...

  4. 洛谷P1081 开车旅行70分

    https://www.luogu.org/problem/show?pid=1081 太遗憾了明明写出来了,却把最小值初始值弄小了,从第二个点开始就不可能对了.70分! #include<io ...

  5. 华容道 noip2013 70分搜索

    题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...

  6. ccf 201712-4 行车路线(70分)

    ccf 201712-4 行车路线 解题思路: 首先Dijkstra是基于贪心算法的,即每一次作出的选择都具有贪心选择性.此题由于有“如果连续走小道,小明的疲劳值会快速增加,连续走s公里小明会增加s2 ...

  7. Cogs 1264. [NOIP2012] 开车旅行(70分 暴力)

    1264. [NOIP2012] 开车旅行 ★★☆   输入文件:drive.in   输出文件:drive.out   简单对比时间限制:2 s   内存限制:128 MB [题目描述] 小A 和小 ...

  8. 【NOI2016】优秀的拆分 题解(95分)

    题目大意: 求一个字符串中形如AABB的子串个数. 思路: 用哈希做到O(1)判断字符串是否相同,O($n^2$)预处理,ans[i]为开头位置为i的形如AA的子串个数.再用O($n^2$)枚举出AA ...

  9. ACM: 限时训练题解-Runtime Error-二分查找

    Runtime Error   Bahosain was trying to solve this simple problem, but he got a Runtime Error on one ...

随机推荐

  1. uva 10566 Crossed Ladders (二分)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. BERT-Pytorch demo初探

    https://zhuanlan.zhihu.com/p/50773178 概述 本文基于 pytorch-pretrained-BERT(huggingface)版本的复现,探究如下几个问题: py ...

  3. 2018-5-28-win10-uwp-动态修改ListView元素布局

    title author date CreateTime categories win10 uwp 动态修改ListView元素布局 lindexi 2018-05-28 15:15:54 +0800 ...

  4. 2018-11-19-win10-uwp-使用-Matrix3DProjection-进行-3d-投影

    title author date CreateTime categories win10 uwp 使用 Matrix3DProjection 进行 3d 投影 lindexi 2018-11-19 ...

  5. oracle避免使用耗费资源的操作

    带有DISTINCT,UNION,MINUS,INTERSECT,ORDER BY的SQL语句会启动SQL引擎 执行耗费资源的排序(SORT)功能. DISTINCT需要一次排序操作, 而其他的至少需 ...

  6. Laravel5.5 支付宝手机网站支付的教程

    https://segmentfault.com/a/1190000015559571 这篇文章主要介绍了Laravel5.5 支付宝手机网站支付的教程,小编觉得挺不错的,现在分享给大家,也给大家做个 ...

  7. CSS画矩形、圆、半圆、弧形、半圆、小三角、疑问框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. java面向接口编程之适配器模式

    使用一个现成的类,但是它的接口不完全符合你的需求,我只想要它其中的一个方法,不想覆写其他的方法. 比如,窗体有变大,变小,关闭的行为,但是我现在只需要关闭行为;   package reviewDem ...

  9. Argus--[优先队列]

    Description A data stream is a real-time, continuous, ordered sequence of items. Some examples inclu ...

  10. H3C DHCP中继工作原理