此题为找规律。期望100 实际100

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. long long len1,len2;
  7. long long n,s1,t1,s2,t2;
  8. long long abss(long long x){
  9. if(x<) return -x;
  10. else return x;
  11. }
  12. long long maxx(long long x,long long y){
  13. if(x>y) return x;
  14. else return y;
  15. }
  16. int main(){
  17. freopen("grid.in","r",stdin);
  18. freopen("grid.out","w",stdout);
  19. cin>>n>>s1>>t1>>s2>>t2;
  20. len1=abss(s1-s2);len2=abss(t1-t2);
  21. cout<<maxx(len1,len2)<<endl;
  22. }

期望20~40  实际20  感觉第二部分的部分分可以枚举所有可行的字符串,然后判断是否可行,但是炸掉了。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. int T,type,n,tot,num;
  7. char s[];
  8. string ans[];
  9. void dfs(int be,string sbef){
  10. string smid;
  11. for(int i=be;i>=;i--){
  12. smid+=s[i];
  13. int lenn=smid.length();
  14. if(type==){
  15. if(smid!=sbef)
  16. if(smid.length()==||smid.length()==){
  17. ans[++num]=smid;
  18. dfs(i-,smid);
  19. }
  20. }
  21. else{
  22. if(smid.length()==||smid.length()==){
  23. ans[++num]=smid;
  24. dfs(i-,smid);
  25. }
  26. }
  27. if(smid.length()>) break;
  28. }
  29. }
  30. int main(){
  31. freopen("ling.in","r",stdin);
  32. freopen("ling.out","w",stdout);
  33. scanf("%d%d",&T,&type);
  34. while(T--){
  35. cin>>s;
  36. int len=strlen(s);
  37. if(len<=){
  38. dfs(len-,"abcd");
  39. for(int i=;i<=num;i++){
  40. int lenn=ans[i].length();
  41. string simm=ans[i];
  42. for(int j=;j<lenn;j++)
  43. ans[i][j]=simm[lenn-j-];
  44. }
  45. sort(ans+,ans++num);
  46. for(int i=;i<=num;i++)
  47. if(ans[i]!=ans[i-]) tot++;
  48. cout<<tot<<endl;
  49. for(int i=;i<=num;i++)
  50. if(ans[i]!=ans[i-]) cout<<ans[i]<<endl;
  51. num=;tot=;
  52. }
  53. else if(type==){
  54. for(int i=len-;i>=;i-=){
  55. string smid;
  56. for(int j=i;j>=;j--){
  57. smid+=s[j];
  58. if(i-j==||i-j==)
  59. ans[++num]=smid;
  60. if(i-j>) break;
  61. }
  62. }
  63. for(int i=len-;i>=;i-=){
  64. string smid;
  65. for(int j=i;j>=;j--){
  66. smid+=s[j];
  67. if(i-j==||i-j==)
  68. ans[++num]=smid;
  69. if(i-j>) break;
  70. }
  71. }
  72. for(int i=;i<=num;i++){
  73. int lenn=ans[i].length();
  74. string simm=ans[i];
  75. for(int j=;j<lenn;j++)
  76. ans[i][j]=simm[lenn-j-];
  77. }
  78. sort(ans+,ans++num);
  79. for(int i=;i<=num;i++)
  80. if(ans[i]!=ans[i-]) tot++;
  81. cout<<tot<<endl;
  82. for(int i=;i<=num;i++)
  83. if(ans[i]!=ans[i-]) cout<<ans[i]<<endl;
  84. num=;tot=;
  85. }
  86. }
  87. }

我们只要知道上次填的串多长,就可以知道上次使用的字符串。而且
对每个位置只需要知道它上次填2或3时是否可行。
f[i][2或3]表示当前到i,填以i开头、长度为2或3的后缀串是否可行。可以转移就记录答案。

如果typt!=0则不需要判后缀是否相同。
复杂度O(n) 。
为了方便可以把串反过来。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #define pc putchar
  6. using namespace std;
  7. const int N=;
  8. bool f[N][],ok2[][],ok3[][][];
  9. char s[N];
  10. void Work(const int type){
  11. memset(f,,sizeof f);
  12. memset(ok2,,sizeof ok2), memset(ok3,,sizeof ok3);
  13. scanf("%s",s+);
  14. int n=strlen(s+);
  15. std::reverse(s+,s++n);
  16. int tot=; n-=;
  17. if(n>=) f[][]=, ++tot, ok2[s[]-'a'][s[]-'a']=;
  18. if(n>=) f[][]=, ++tot, ok3[s[]-'a'][s[]-'a'][s[]-'a']=;
  19. for(int i=; i<=n; ++i){
  20. int a=s[i]-'a', b=s[i-]-'a', c=s[i-]-'a';
  21. if(f[i-][]||(f[i-][]&&(type||s[i]!=s[i-]||s[i-]!=s[i-]))){
  22. f[i][]=;
  23. if(!ok2[a][b]) ++tot, ok2[a][b]=;
  24. }
  25. if(f[i-][]||(f[i-][]&&(type||s[i]!=s[i-]||s[i-]!=s[i-]||s[i-]!=s[i-]))){
  26. f[i][]=;
  27. if(!ok3[a][b][c]) ++tot, ok3[a][b][c]=;
  28. }
  29. }
  30. printf("%d\n",tot);
  31. for(int i=; i<&&tot; ++i){
  32. for(int j=; j<; ++j){
  33. if(ok2[i][j]) --tot,pc(i+'a'),pc(j+'a'),pc('\n');
  34. for(int k=; k<; ++k)
  35. if(ok3[i][j][k]) --tot,pc(i+'a'),pc(j+'a'),pc(k+'a'),pc('\n');
  36. }
  37. }
  38. }
  39. int main(){
  40. int T,type;
  41. for(scanf("%d%d",&T,&type); T--; Work(type));
  42. return ;
  43. }

期望10   实际10

也就只会写他是条链的暴力了。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. int T,q,num=,tot,deepmax;
  7. long double ans;
  8. int son[],deep[];
  9. int to[],net[],head[];
  10. void add(int u,int v){
  11. to[++tot]=v;net[tot]=head[u];head[u]=tot;
  12. }
  13. long double pow(long double x,int num){
  14. long double bns=x;
  15. for(int i=;i<num;i++)
  16. bns*=x;
  17. return bns;
  18. }
  19. void work(int now,int de){
  20. for(int i=head[now];i;i=net[i]){
  21. deep[de]+=son[to[i]];
  22. deepmax=(deepmax,de);
  23. work(to[i],de+);
  24. }
  25. }
  26. int main(){
  27. freopen("threebody.in","r",stdin);
  28. freopen("threebody.out","w",stdout);
  29. scanf("%d%d",&T,&q);
  30. if(q>&&q<=){
  31. for(int i=;i<=q;i++){
  32. int x,y;
  33. scanf("%d%d",&x,&y);
  34. if(x==) num++;
  35. else if(x==){
  36. for(int j=;j<num-y;j++)
  37. ans+=pow(0.5,j+)*j;
  38. ans+=pow(0.5,num-y)*(num-y);
  39. printf("%.10lf\n",double(ans));
  40. }
  41. ans=;
  42. }
  43. }
  44. else{
  45. for(int i=;i<=q;i++){
  46. int x,y;
  47. scanf("%d%d",&x,&y);
  48. if(x==){
  49. num++;son[y]++;
  50. add(y,num);
  51. }
  52. else if(x==){
  53. deep[]=son[y];
  54. work(y,);
  55. /*for(int j=1;j<=deepmax;j++) cout<<deep[i]<<" ";cout<<endl;*/
  56. for(int j=;j<=deepmax;j++){
  57. long double bns=1.0;
  58. for(int k=;k<=j;k++)
  59. bns=bns*(-pow(0.5,deep[k]));
  60. bns=bns*pow(0.5,deep[j+]);
  61. ans+=bns*j;
  62. }
  63. printf("%.10lf\n",double(ans));
  64. ans=;
  65. }
  66. }
  67. }
  68. }
  69. /*
  70. 0 6
  71. 2 1
  72. 1 1
  73. 1 2
  74. 1 3
  75. 1 4
  76. 2 1
  77. */

std

首先我们不需要考虑很大的深度。假如换h=100 ,需要一条长100 的链,即至少同时存在100 条
边,概率为,非常小。设需考虑的最大高度

对于询问,只要x 有一个子树的深度为h 且其它子树深度不超过 h,就可以用p(h)*h 更新答案。
所以记f[x ][h]表示以 x为根,deep[x]<=h 的概率。则答案为

考虑如何从 转移。每个子节点有两种情况,一是存在边,对f[x][h] 贡献 1/2*f[v][h-1]的概率;二是不存在该边,概率为1/2 。

类似多项式,把 项乘在一起,即

(比如,深度为0,对应 深度为1,对应 个 1/2与一个……

复杂度

如果新建节点 ,则影响的点有

因为深度不超过70 ,所以暴力向上更新即可,也就是除掉之前的项,乘上新的项。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #define MAX_H 60
  6. #define MAXN 500010
  7. using namespace std;
  8. int T,Q,n,fa[MAXN];
  9. double f[MAXN][MAX_H];
  10. int main(){
  11. n=;scanf("%d%d",&T,&Q);
  12. for(int i=;i<MAX_H;i++) f[][i]=;
  13. while(Q--){
  14. int opt,x;
  15. scanf("%d%d",&opt,&x);
  16. if(opt==){
  17. fa[++n]=x;
  18. for(int i=;i<MAX_H;i++) f[n][i]=;
  19. double tmp1=f[x][],tmp2;
  20. f[x][]*=0.5;
  21. for(int Fa=fa[x],i=;Fa&&i<MAX_H;Fa=fa[x=Fa],i++){
  22. tmp2=f[Fa][i];
  23. f[Fa][i]/=0.5+0.5*tmp1;
  24. f[Fa][i]*=0.5+0.5*f[x][i-];
  25. tmp1=tmp2;
  26. }
  27. }
  28. else {
  29. double ans=;
  30. for(int i=;i<MAX_H;i++) ans+=(f[x][i]-f[x][i-])*i;
  31. printf("%.10lf\n",ans);
  32. }
  33. }
  34. }

18.9.22 noip模拟赛的更多相关文章

  1. 2018.9.22 NOIP模拟赛

    *注意:这套题目应版权方要求,不得公示题面. 从这里开始 Problem A 妹子 Problem B 旅程 Problem C 老大 因为业务水平下滑太严重,去和高一考NOIP模拟,sad... P ...

  2. 【2019.7.22 NOIP模拟赛 T1】麦克斯韦妖(demon)(质因数分解+DP)

    暴力\(DP\) 先考虑暴力\(DP\)该怎么写. 因为每个序列之后是否能加上新的节点只与其结尾有关,因此我们设\(f_i\)为以\(i\)为结尾的最长序列长度. 每次枚举一个前置状态,判断是否合法之 ...

  3. 5.22 noip模拟赛

    本来我是不想写的,无奈不会写.蒟蒻 考场就是想不出来 今天得到了100分额外水过了100分我是真的失败.还有一个根本不会check 感觉自己非常之菜. 这道题是这样的 还行吧比较有意思 首先确立一个真 ...

  4. CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

    A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...

  5. 10.16 NOIP模拟赛

    目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...

  6. 【HHHOJ】NOIP模拟赛 捌 解题报告

    点此进入比赛 得分: \(30+30+70=130\)(弱爆了) 排名: \(Rank\ 22\) \(Rating\):\(-31\) \(T1\):[HHHOJ260]「NOIP模拟赛 捌」Dig ...

  7. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  8. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  9. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

随机推荐

  1. 使用Glide加载Android图片

    一.概述 Glide是一个在Android端非常好的图片缓冲工具,总体上来说,他有以下优点 使用简单 自适应程度高 支持常见的图片格式,如jpg,png等 支持多种数据源,网络,本地,资源,Asset ...

  2. IntentFilter的相关问题解析

    IntentFilter是配合Intent而生的,你有目标行动或者结果,那么那些行动和结果就会有他完成的特定要求,这些要求就是IntentFilter,可以理解为Intent和IntentFilter ...

  3. JS获取服务器端控件ID

    很多时候我们需要在JS中对服务器端控件进行一些简单处理,但是这个时候没有必要回发到服务器,让服务器去处理,这个时候就又要用到JS了 那么怎么去获取这个服务器端控件呢?我们知道服务器最终返回到用户界面的 ...

  4. Node.js——render封装

    封装 挂在到res上

  5. python strip() 函数探究

    strip()方法语法:str.strip([chars]); 声明:str为字符串,rm为要删除的字符序列 str.strip(rm) 删除字符串中开头.结尾处,位于rm删除序列的字符 eg1: # ...

  6. Winsock2_WSADATA

    使用Winsock2进行win下网络编程的第一步是初始化Winsock.其中需要创建一个WSADATA类型的变量,这个变量用来保存Windows socket的实现信息. typedef struct ...

  7. HDU_3792_(素数筛+树状数组)

    Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. PowerDesigner 操作手册

    1.错误信息:Generation aborted due to errors detected during the verification of the model 解决方案: 把检查模型的选项 ...

  9. python 实现代理服务器

    # encoding:utf-8 import socket import thread import re def getAddr(d): a = re.search("Host: (.* ...

  10. python使用zipfile解压文件中文乱码问题

    中文在编程中真实后娘养的,各种坑爹,python3下中文乱码这个问题抓破了头皮,头疼.看了alex的文章,才有种恍然大悟的感觉(链接在底部). 一句话,就是转换成unicode,压缩前是什么编码,使用 ...