难得的一次Unrated,避免了重回1500的尴尬

其实题目都还可以,但只不过所有人T1都炸了,可能是数据的锅(假的)

而且我因为T1SB的把T2弃了,没想到是千年水题

T3莫名爆炸,然后TM的40分(再一次感谢Unrated)

链接

T1

题意很简单,主要是思想太牛逼

当时一直在找规律,浪费了2hours。最后搞了一个O(n)的递推然后炸掉

先讲一下递推

  • f[i][0]表示到第i轮时不经过1号点的方案数

  • f[i][1]表示到第i轮时经过过1号店且当前不在1号点的方案数

  • f[i][2]表示到第i轮时经过过1号店且当前在1号点的方案数

所以:

  • f[i][0]=f[i-1][0]*(n-2)

  • f[i][1]=f[i-1][2]*(n-1)+f[i-1][1]*(n-2)

  • f[i][2]=f[i-1][1]+f[i-1][0]

其实还可以滚动优化,而且还有维数更小的

递推CODE

  1. #include<cstdio>
  2. const int P=1e9+7;
  3. long long n,t,f[100005][3];
  4. int main()
  5. {
  6. scanf("%lld%lld",&n,&t);
  7. register int i;
  8. n%=P; t%=P;
  9. for (f[1][0]=n-1,i=2;i<=t;++i)
  10. {
  11. f[i][0]=(f[i-1][0]*(n-2))%P;
  12. f[i][1]=(f[i-1][2]*(n-1)+f[i-1][1]*(n-2))%P;
  13. f[i][2]=(f[i-1][1]+f[i-1][0])%P;
  14. }
  15. printf("%lld",(f[t-1][0]+f[t-1][1])%P);
  16. return 0;
  17. }

满分算法:

令a[t]表示t轮以后回到kid1的方法数

考虑到进行到t轮时会有(n−1)^t种传法,因此不回到kid1的方法数就

有(n−1)^t−a[t]种,而除了kid1的小孩在下一轮都可以传给kid1,因此

a[t]+1=(n−1)t-a[t],即a[t]+a[t+1]=(n−1)t

⽤特征根法解这个递推关系可以得到答案是

  1. ((n-1)^t+(-1)^t*(n-1))/n

因此快速幂+逆元即可

CODE

  1. #include<cstdio>
  2. using namespace std;
  3. typedef long long LL;
  4. const LL P=1e9+7;
  5. LL n,t,ans;
  6. inline LL quick_pow(LL x,LL p)
  7. {
  8. LL tot=1;
  9. while (p)
  10. {
  11. if (p&1) tot=(tot*x)%P;
  12. x=(x*x)%P; p/=2;
  13. }
  14. return tot;
  15. }
  16. int main()
  17. {
  18. scanf("%lld%lld",&n,&t); n%=P;
  19. ans=quick_pow(n-1,t);
  20. if (t&1) ans=(ans-n+1+P)%P; else ans=(ans+n-1+P)%P;
  21. printf("%lld",(ans*quick_pow(n,P-2))%P);
  22. return 0;
  23. }

T2

类最小生成树裸题,然而我并没有看出来

题意简化后找一条连接在S到T的路径,使得上面的最长的边最短

将边排序后开一个并查集一条一条地加进去知道S与T联通即可

这里偷懒了一下,懒得写Trie或是Hash了,直接开了map

主要是距离的计算不要写错

CODE

  1. #include<cstdio>
  2. #include<map>
  3. #include<string>
  4. #include<algorithm>
  5. #include<cmath>
  6. using namespace std;
  7. typedef double DB;
  8. const int N=3005;
  9. map <string,int> rat;
  10. struct data
  11. {
  12. int l,r;
  13. DB s;
  14. }a[N*N];
  15. int n,x[N],y[N],r[N],cnt,father[N],s,t;
  16. DB ans;
  17. char temp[10];
  18. inline void read(int &x)
  19. {
  20. x=0; char ch=getchar(); int flag=1;
  21. while (ch<'0'||ch>'9') { if (ch=='-') flag=-1; ch=getchar(); }
  22. while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  23. x*=flag;
  24. }
  25. inline DB max(DB a,DB b)
  26. {
  27. return a>b?a:b;
  28. }
  29. inline void add(int p,int q)
  30. {
  31. a[++cnt].l=p; a[cnt].r=q;
  32. a[cnt].s=max(0.00,(DB)sqrt((DB)(x[p]-x[q])*(x[p]-x[q])+(DB)(y[p]-y[q])*(y[p]-y[q]))-r[p]-r[q]);
  33. }
  34. inline bool comp(data a,data b)
  35. {
  36. return a.s<b.s;
  37. }
  38. inline int getfather(int k)
  39. {
  40. return father[k]==k?k:father[k]=getfather(father[k]);
  41. }
  42. int main()
  43. {
  44. //freopen("B.in","r",stdin); freopen("B.out","w",stdout);
  45. register int i,j;
  46. for (read(n),i=1;i<=n;++i)
  47. {
  48. scanf("%s",&temp); rat[temp]=i; father[i]=i;
  49. read(x[i]); read(y[i]); read(r[i]);
  50. for (j=1;j<i;++j)
  51. add(i,j);
  52. }
  53. scanf("%s",&temp); s=rat[temp];
  54. scanf("%s",&temp); t=rat[temp];
  55. sort(a+1,a+cnt+1,comp);
  56. for (i=1;i<=cnt;++i)
  57. {
  58. int fx=getfather(a[i].l),fy=getfather(a[i].r);
  59. if (fx!=fy)
  60. {
  61. ans=a[i].s;
  62. father[fx]=fy;
  63. }
  64. if (getfather(s)==getfather(t)) break;
  65. }
  66. printf("%.6lf",ans);
  67. return 0;
  68. }

T3

这道题就是一道数据结构综合的毒瘤题了

并查集判连通性+离线建树+二进制处理数+树链剖分+线段树

首先这种把颜色转化成二进制再或(|)一下的题目也有类似的思想:Luogu P1558,只不过那道题是线性的,而这里变成了树上操作

所以我们自然想到LCT,但是其实这道题不用LCT也行(%%%X_o_r dalao LCT A了此题)

我们离线建树,用并查集判断操作的合法性

然后直接把树按原来的点权建出来

接下来对于修改树剖后直接单点修改即可,查询就是线段树上区间查询

CODE(真心累)

  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4. typedef long long LL;
  5. const int N=100005;
  6. struct edge
  7. {
  8. int to,next;
  9. }e[N<<1];
  10. struct ques
  11. {
  12. int opt,x,y;
  13. bool est;
  14. }q[3*N];
  15. LL tree[N<<2];
  16. int n,m,head[N],father[N],a[N],root,cnt,size[N],dep[N],son[N],id[N],top[N],s[N],tot;
  17. inline char tc(void)
  18. {
  19. static char fl[100000],*A=fl,*B=fl;
  20. return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
  21. }
  22. inline void read(int &x)
  23. {
  24. x=0; char ch=tc();
  25. while (ch<'0'||ch>'9') ch=tc();
  26. while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
  27. }
  28. inline void write(int x)
  29. {
  30. if (x/10) write(x/10);
  31. putchar(x%10+'0');
  32. }
  33. inline void add(int x,int y)
  34. {
  35. e[++cnt].to=y; e[cnt].next=head[x]; head[x]=cnt;
  36. }
  37. inline int getfather(int k)
  38. {
  39. return father[k]==k?k:father[k]=getfather(father[k]);
  40. }
  41. inline void up(int root)
  42. {
  43. tree[root]=tree[root<<1]|tree[root<<1|1];
  44. }
  45. inline void build(int root,int l,int r)
  46. {
  47. if (l==r)
  48. {
  49. tree[root]=(LL)1<<s[l];
  50. return;
  51. }
  52. int mid=l+r>>1;
  53. build(root<<1,l,mid); build(root<<1|1,mid+1,r);
  54. up(root);
  55. }
  56. inline void modify(int root,int l,int r,int id,int k)
  57. {
  58. if (l==r)
  59. {
  60. tree[root]=(LL)1<<k;
  61. s[l]=k;
  62. return;
  63. }
  64. int mid=l+r>>1;
  65. if (id<=mid) modify(root<<1,l,mid,id,k); else modify(root<<1|1,mid+1,r,id,k);
  66. up(root);
  67. }
  68. inline LL query(int root,int l,int r,int beg,int end)
  69. {
  70. if (l>=beg&&r<=end) return tree[root];
  71. int mid=l+r>>1;
  72. LL res=0;
  73. if (beg<=mid) res|=query(root<<1,l,mid,beg,end);
  74. if (end>mid) res|=query(root<<1|1,mid+1,r,beg,end);
  75. return res;
  76. }
  77. inline int count(LL x)
  78. {
  79. int res=0;
  80. while (x)
  81. {
  82. res+=x&1;
  83. x/=2;
  84. }
  85. return res;
  86. }
  87. inline void swap(int &a,int &b)
  88. {
  89. int t=a; a=b; b=t;
  90. }
  91. inline void DFS1(int now,int fa,int d)
  92. {
  93. size[now]=1; father[now]=fa; dep[now]=d;
  94. int res=-1;
  95. for (register int i=head[now];i!=-1;i=e[i].next)
  96. if (e[i].to!=fa)
  97. {
  98. DFS1(e[i].to,now,d+1);
  99. size[now]+=size[e[i].to];
  100. if (size[e[i].to]>res) res=size[e[i].to],son[now]=e[i].to;
  101. }
  102. }
  103. inline void DFS2(int now,int topf)
  104. {
  105. id[now]=++tot; s[tot]=a[now]; top[now]=topf;
  106. if (!son[now]) return;
  107. DFS2(son[now],topf);
  108. for (register int i=head[now];i!=-1;i=e[i].next)
  109. if (e[i].to!=father[now]&&e[i].to!=son[now]) DFS2(e[i].to,e[i].to);
  110. }
  111. inline void updata(int x,int z)
  112. {
  113. modify(1,1,tot,id[x],z);
  114. }
  115. inline int get_sec(int x,int y)
  116. {
  117. LL res=0;
  118. while (top[x]!=top[y])
  119. {
  120. if (dep[top[x]]<dep[top[y]]) swap(x,y);
  121. res|=query(1,1,tot,id[top[x]],id[x]);
  122. x=father[top[x]];
  123. }
  124. if (dep[x]<dep[y]) swap(x,y);
  125. res|=query(1,1,tot,id[y],id[x]);
  126. return count(res);
  127. }
  128. int main()
  129. {
  130. //freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
  131. register int i;
  132. memset(head,-1,sizeof(head));
  133. memset(e,-1,sizeof(e));
  134. read(n); read(m);
  135. for (i=1;i<=n;++i)
  136. read(a[i]),father[i]=i;
  137. for (i=1;i<=m;++i)
  138. {
  139. read(q[i].opt); read(q[i].x); read(q[i].y);
  140. int fx=getfather(q[i].x),fy=getfather(q[i].y);
  141. if (q[i].opt==1)
  142. {
  143. if (fx!=fy) father[fx]=fy,q[i].est=1,add(q[i].x,q[i].y),add(q[i].y,q[i].x),root=q[i].x;
  144. } else
  145. {
  146. if (fx==fy) q[i].est=1;
  147. }
  148. }
  149. memset(father,0,sizeof(father));
  150. DFS1(root,-1,0);
  151. DFS2(root,root);
  152. build(1,1,tot);
  153. for (i=1;i<=m;++i)
  154. {
  155. if (q[i].opt==1&&q[i].est)
  156. {
  157. int res=s[id[q[i].x]]+s[id[q[i].y]]>>1;
  158. updata(q[i].x,res); updata(q[i].y,res);
  159. }
  160. if (q[i].opt==2)
  161. {
  162. if (q[i].est) write(get_sec(q[i].x,q[i].y)),putchar('\n'); else puts("-1");
  163. }
  164. }
  165. return 0;
  166. }

发现我的树剖+线段树竟然远快于X_o_r dalao的LCT+Splay

EZ 2018 04 21 NOIP2018 模拟赛(十) -LoliconAutomaton的退役赛的更多相关文章

  1. EZ 2018 04 21 NOIP2018 模拟赛(九)

    终于停止了掉Rating的浪潮! 猥琐的链接 这次200分才Rank10,而且很多人并列 庆幸T2最后20分钟发现期望的算法打错了,然后拿到了50pts,250收场 T1 水题*1 这道题不仅做过,而 ...

  2. EZ 2018 04 13 NOIP2018 模拟赛(八)

    这次的题目都是什么鬼? 玄学乱搞+肉眼看CODE+倒着搜索? 好吧是我ZZ了 链接在此 T1 玄学乱搞 由于考场上写的部分分做法忘记讨论n<=2000时的情况,少得了30pts 很容易得到一个基 ...

  3. EZ 2018 04 06 NOIP2018 模拟赛(七)

    我是链接 这次是真的惨,码了将近2hours的可持久化线段树炸掉了! 而且本地拍了一万年也没发现哪里炸了. T1 压位的入门题,话说这道题能拿个99分就可以了(100分要FFT) 对于暴力,就是暴力找 ...

  4. EZ 2018 06 17 NOIP2018 模拟赛(十九)

    这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...

  5. EZ 2018 06 10 NOIP2018 模拟赛(十八)

    好久没写blog&&比赛题解了,最近补一下 这次还是很狗的,T3想了很久最后竟然连并查集都忘写了,然后T2map莫名爆炸. Rating爆减......链接不解释 好了我们开始看题. ...

  6. EZ 2018 05 20 NOIP2018 模拟赛(十五)

    这次的比赛充满着玄学的气息,玄学链接 首先讲一下为什么没有第十四场 其实今天早上9点时看到题目就叫了:原题! 没错,整套试卷都做过,我还写了题解 然后老叶就说换一套,但如果仅仅是这样就没什么 但等13 ...

  7. EZ 2018 06 24 NOIP2018 模拟赛(二十)

    很久之前写的一套题了,由于今天的时间太多了,所以记起来就写掉算了. 这一场尽管T2写炸了,但也莫名Rank4涨了Rating.不过还是自己太菜. A. 环游世界 首先我们先排个序,想一下如果不用走回来 ...

  8. EZ 2018 05 26 NOIP2018 模拟赛(十六)

    这次难道就是传说中的标准分大赛?而且这次比赛的链接不翼而飞了 一堆人153pts然后就有Rank4?看来这个Rank4不值钱了,才涨了50+的Rating. 不过还好最后5min的时候想出了T1正解, ...

  9. EZ 2018 06 02 NOIP2018 模拟赛(十七)

    这次的比赛是真心比较狗,我TM的写了30min的树剖ZZ地直接memset超时了 话说我既然想到差分就应该去写差分的啊! 好了不过这次Rank还挺高的,终于要打进前10了当然是假的了. 好了下面开始讲 ...

随机推荐

  1. flume使用场景 flume与kafka的比较

    Is Flume a good fit for your problem? If you need to ingest textual log data into Hadoop/HDFS then F ...

  2. 将window的shell脚本通过ftp传输到Linux服务器后, shell脚本中执行时提示“没有那个文件或目录”的解决办法

    出现bad interpreter:No such file or directory的原因,是文件格式的问题.这个文件是在Windows下编写的.换行的方式与Unix不一样,但是在vim下面如果不S ...

  3. C#读取AD域用户信息

    private const string domainName = "本机IP地址或域名"; private const string adAdmin = "管理员帐号& ...

  4. 微信小程序审核 出现85085 提交审核数量过多问题

    前段时间发布了一个新版本小程序(错误代码:85085,说明:submit audit reach limit, please try later hint: [OKYBha04570729]),由于我 ...

  5. Python3编写网络爬虫02-基本请求库requests的使用

    一.requests 库使用 需要安装 pip install requests import requests #导入requests库 request = requests.get("h ...

  6. 天地图api地址

    天地图地址 http://lbs.tianditu.com/api-new/examples.html 参考资料 http://lbs.tianditu.com/api-new/class.html

  7. 企业案例--生产环节更改mysql字符集

    查看数据库字符集: show database create dbname \G; 查看数据库表字符集: show table create tbname \G; 查看现有数据库字符集设置: show ...

  8. CentOS7下安装NVIDIA独立显卡驱动出现X service error问题解决方法

    问题症状: 最近在CentOS7下安装NVIDIA独立显卡驱动的过程中出现X service error问题,如下图所示: 解决方法: 0.到NVIDIA 官网上下载驱动文件(.run 格式) : N ...

  9. 无法找到“XXX.exe”的调试信息,或者调试信息不匹配。未使用调试信息生成二进制文件

    1.问题症状 已经处于Debug模式,运行时完全正常,但是一调试就出现对话框,显示出错信息:“无法找到“XXX.exe”的调试信息,或者调试信息不匹配.未使用调试信息生成二进制文件.” 2.解决方法 ...

  10. 十分钟教你使用NoteExpress

    http://www.a-site.cn/article/761794.html 如果你正走在读研的路上,不管是什么专业,日常生活中都少不了读文献.读文献和读文献. 与其等到文献堆积如山,给阅读和使用 ...