18.9.22 noip模拟赛
此题为找规律。期望100 实际100
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- long long len1,len2;
- long long n,s1,t1,s2,t2;
- long long abss(long long x){
- if(x<) return -x;
- else return x;
- }
- long long maxx(long long x,long long y){
- if(x>y) return x;
- else return y;
- }
- int main(){
- freopen("grid.in","r",stdin);
- freopen("grid.out","w",stdout);
- cin>>n>>s1>>t1>>s2>>t2;
- len1=abss(s1-s2);len2=abss(t1-t2);
- cout<<maxx(len1,len2)<<endl;
- }
期望20~40 实际20 感觉第二部分的部分分可以枚举所有可行的字符串,然后判断是否可行,但是炸掉了。
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- int T,type,n,tot,num;
- char s[];
- string ans[];
- void dfs(int be,string sbef){
- string smid;
- for(int i=be;i>=;i--){
- smid+=s[i];
- int lenn=smid.length();
- if(type==){
- if(smid!=sbef)
- if(smid.length()==||smid.length()==){
- ans[++num]=smid;
- dfs(i-,smid);
- }
- }
- else{
- if(smid.length()==||smid.length()==){
- ans[++num]=smid;
- dfs(i-,smid);
- }
- }
- if(smid.length()>) break;
- }
- }
- int main(){
- freopen("ling.in","r",stdin);
- freopen("ling.out","w",stdout);
- scanf("%d%d",&T,&type);
- while(T--){
- cin>>s;
- int len=strlen(s);
- if(len<=){
- dfs(len-,"abcd");
- for(int i=;i<=num;i++){
- int lenn=ans[i].length();
- string simm=ans[i];
- for(int j=;j<lenn;j++)
- ans[i][j]=simm[lenn-j-];
- }
- sort(ans+,ans++num);
- for(int i=;i<=num;i++)
- if(ans[i]!=ans[i-]) tot++;
- cout<<tot<<endl;
- for(int i=;i<=num;i++)
- if(ans[i]!=ans[i-]) cout<<ans[i]<<endl;
- num=;tot=;
- }
- else if(type==){
- for(int i=len-;i>=;i-=){
- string smid;
- for(int j=i;j>=;j--){
- smid+=s[j];
- if(i-j==||i-j==)
- ans[++num]=smid;
- if(i-j>) break;
- }
- }
- for(int i=len-;i>=;i-=){
- string smid;
- for(int j=i;j>=;j--){
- smid+=s[j];
- if(i-j==||i-j==)
- ans[++num]=smid;
- if(i-j>) break;
- }
- }
- for(int i=;i<=num;i++){
- int lenn=ans[i].length();
- string simm=ans[i];
- for(int j=;j<lenn;j++)
- ans[i][j]=simm[lenn-j-];
- }
- sort(ans+,ans++num);
- for(int i=;i<=num;i++)
- if(ans[i]!=ans[i-]) tot++;
- cout<<tot<<endl;
- for(int i=;i<=num;i++)
- if(ans[i]!=ans[i-]) cout<<ans[i]<<endl;
- num=;tot=;
- }
- }
- }
我们只要知道上次填的串多长,就可以知道上次使用的字符串。而且
对每个位置只需要知道它上次填2或3时是否可行。
f[i][2或3]表示当前到i,填以i开头、长度为2或3的后缀串是否可行。可以转移就记录答案。
如果typt!=0则不需要判后缀是否相同。
复杂度O(n) 。
为了方便可以把串反过来。
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pc putchar
- using namespace std;
- const int N=;
- bool f[N][],ok2[][],ok3[][][];
- char s[N];
- void Work(const int type){
- memset(f,,sizeof f);
- memset(ok2,,sizeof ok2), memset(ok3,,sizeof ok3);
- scanf("%s",s+);
- int n=strlen(s+);
- std::reverse(s+,s++n);
- int tot=; n-=;
- if(n>=) f[][]=, ++tot, ok2[s[]-'a'][s[]-'a']=;
- if(n>=) f[][]=, ++tot, ok3[s[]-'a'][s[]-'a'][s[]-'a']=;
- for(int i=; i<=n; ++i){
- int a=s[i]-'a', b=s[i-]-'a', c=s[i-]-'a';
- if(f[i-][]||(f[i-][]&&(type||s[i]!=s[i-]||s[i-]!=s[i-]))){
- f[i][]=;
- if(!ok2[a][b]) ++tot, ok2[a][b]=;
- }
- if(f[i-][]||(f[i-][]&&(type||s[i]!=s[i-]||s[i-]!=s[i-]||s[i-]!=s[i-]))){
- f[i][]=;
- if(!ok3[a][b][c]) ++tot, ok3[a][b][c]=;
- }
- }
- printf("%d\n",tot);
- for(int i=; i<&&tot; ++i){
- for(int j=; j<; ++j){
- if(ok2[i][j]) --tot,pc(i+'a'),pc(j+'a'),pc('\n');
- for(int k=; k<; ++k)
- if(ok3[i][j][k]) --tot,pc(i+'a'),pc(j+'a'),pc(k+'a'),pc('\n');
- }
- }
- }
- int main(){
- int T,type;
- for(scanf("%d%d",&T,&type); T--; Work(type));
- return ;
- }
期望10 实际10
也就只会写他是条链的暴力了。
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- int T,q,num=,tot,deepmax;
- long double ans;
- int son[],deep[];
- int to[],net[],head[];
- void add(int u,int v){
- to[++tot]=v;net[tot]=head[u];head[u]=tot;
- }
- long double pow(long double x,int num){
- long double bns=x;
- for(int i=;i<num;i++)
- bns*=x;
- return bns;
- }
- void work(int now,int de){
- for(int i=head[now];i;i=net[i]){
- deep[de]+=son[to[i]];
- deepmax=(deepmax,de);
- work(to[i],de+);
- }
- }
- int main(){
- freopen("threebody.in","r",stdin);
- freopen("threebody.out","w",stdout);
- scanf("%d%d",&T,&q);
- if(q>&&q<=){
- for(int i=;i<=q;i++){
- int x,y;
- scanf("%d%d",&x,&y);
- if(x==) num++;
- else if(x==){
- for(int j=;j<num-y;j++)
- ans+=pow(0.5,j+)*j;
- ans+=pow(0.5,num-y)*(num-y);
- printf("%.10lf\n",double(ans));
- }
- ans=;
- }
- }
- else{
- for(int i=;i<=q;i++){
- int x,y;
- scanf("%d%d",&x,&y);
- if(x==){
- num++;son[y]++;
- add(y,num);
- }
- else if(x==){
- deep[]=son[y];
- work(y,);
- /*for(int j=1;j<=deepmax;j++) cout<<deep[i]<<" ";cout<<endl;*/
- for(int j=;j<=deepmax;j++){
- long double bns=1.0;
- for(int k=;k<=j;k++)
- bns=bns*(-pow(0.5,deep[k]));
- bns=bns*pow(0.5,deep[j+]);
- ans+=bns*j;
- }
- printf("%.10lf\n",double(ans));
- ans=;
- }
- }
- }
- }
- /*
- 0 6
- 2 1
- 1 1
- 1 2
- 1 3
- 1 4
- 2 1
- */
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 ,所以暴力向上更新即可,也就是除掉之前的项,乘上新的项。
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define MAX_H 60
- #define MAXN 500010
- using namespace std;
- int T,Q,n,fa[MAXN];
- double f[MAXN][MAX_H];
- int main(){
- n=;scanf("%d%d",&T,&Q);
- for(int i=;i<MAX_H;i++) f[][i]=;
- while(Q--){
- int opt,x;
- scanf("%d%d",&opt,&x);
- if(opt==){
- fa[++n]=x;
- for(int i=;i<MAX_H;i++) f[n][i]=;
- double tmp1=f[x][],tmp2;
- f[x][]*=0.5;
- for(int Fa=fa[x],i=;Fa&&i<MAX_H;Fa=fa[x=Fa],i++){
- tmp2=f[Fa][i];
- f[Fa][i]/=0.5+0.5*tmp1;
- f[Fa][i]*=0.5+0.5*f[x][i-];
- tmp1=tmp2;
- }
- }
- else {
- double ans=;
- for(int i=;i<MAX_H;i++) ans+=(f[x][i]-f[x][i-])*i;
- printf("%.10lf\n",ans);
- }
- }
- }
18.9.22 noip模拟赛的更多相关文章
- 2018.9.22 NOIP模拟赛
*注意:这套题目应版权方要求,不得公示题面. 从这里开始 Problem A 妹子 Problem B 旅程 Problem C 老大 因为业务水平下滑太严重,去和高一考NOIP模拟,sad... P ...
- 【2019.7.22 NOIP模拟赛 T1】麦克斯韦妖(demon)(质因数分解+DP)
暴力\(DP\) 先考虑暴力\(DP\)该怎么写. 因为每个序列之后是否能加上新的节点只与其结尾有关,因此我们设\(f_i\)为以\(i\)为结尾的最长序列长度. 每次枚举一个前置状态,判断是否合法之 ...
- 5.22 noip模拟赛
本来我是不想写的,无奈不会写.蒟蒻 考场就是想不出来 今天得到了100分额外水过了100分我是真的失败.还有一个根本不会check 感觉自己非常之菜. 这道题是这样的 还行吧比较有意思 首先确立一个真 ...
- CH Round #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...
- 10.16 NOIP模拟赛
目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...
- 【HHHOJ】NOIP模拟赛 捌 解题报告
点此进入比赛 得分: \(30+30+70=130\)(弱爆了) 排名: \(Rank\ 22\) \(Rating\):\(-31\) \(T1\):[HHHOJ260]「NOIP模拟赛 捌」Dig ...
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
随机推荐
- 使用Glide加载Android图片
一.概述 Glide是一个在Android端非常好的图片缓冲工具,总体上来说,他有以下优点 使用简单 自适应程度高 支持常见的图片格式,如jpg,png等 支持多种数据源,网络,本地,资源,Asset ...
- IntentFilter的相关问题解析
IntentFilter是配合Intent而生的,你有目标行动或者结果,那么那些行动和结果就会有他完成的特定要求,这些要求就是IntentFilter,可以理解为Intent和IntentFilter ...
- JS获取服务器端控件ID
很多时候我们需要在JS中对服务器端控件进行一些简单处理,但是这个时候没有必要回发到服务器,让服务器去处理,这个时候就又要用到JS了 那么怎么去获取这个服务器端控件呢?我们知道服务器最终返回到用户界面的 ...
- Node.js——render封装
封装 挂在到res上
- python strip() 函数探究
strip()方法语法:str.strip([chars]); 声明:str为字符串,rm为要删除的字符序列 str.strip(rm) 删除字符串中开头.结尾处,位于rm删除序列的字符 eg1: # ...
- Winsock2_WSADATA
使用Winsock2进行win下网络编程的第一步是初始化Winsock.其中需要创建一个WSADATA类型的变量,这个变量用来保存Windows socket的实现信息. typedef struct ...
- HDU_3792_(素数筛+树状数组)
Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- PowerDesigner 操作手册
1.错误信息:Generation aborted due to errors detected during the verification of the model 解决方案: 把检查模型的选项 ...
- python 实现代理服务器
# encoding:utf-8 import socket import thread import re def getAddr(d): a = re.search("Host: (.* ...
- python使用zipfile解压文件中文乱码问题
中文在编程中真实后娘养的,各种坑爹,python3下中文乱码这个问题抓破了头皮,头疼.看了alex的文章,才有种恍然大悟的感觉(链接在底部). 一句话,就是转换成unicode,压缩前是什么编码,使用 ...