0x18 总结与练习
这一章不太满意啊。。
还是有点痛苦,但就是做的挺慢啊。。。
1、就是例题
2、括号画家 感觉这种提高组类型的细节题都没什么信心啊,fail了几次才A
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- char ss[];
- int top,sta[],sum[];
- int main()
- {
- scanf("%s",ss+);int len=strlen(ss+);
- top=;int mmax=,nx=;
- memset(sum,,sizeof(sum));
- for(int i=;i<=len;i++)
- {
- if(ss[i]=='(')sta[++top]=;
- else if(ss[i]=='[')sta[++top]=;
- else if(ss[i]=='{')sta[++top]=;
- else if(ss[i]==')')
- {
- if(top>&&sta[top]==)
- {
- sum[top-]+=sum[top]+;
- sum[top]=,top--;
- nx=max(nx,sum[top]);
- }
- else
- {
- mmax=max(mmax,nx);nx=;
- while(top>)sum[top]=,top--;
- sum[top]=;
- }
- }
- else if(ss[i]==']')
- {
- if(top>&&sta[top]==)
- {
- sum[top-]+=sum[top]+;
- sum[top]=,top--;
- nx=max(nx,sum[top]);
- }
- else
- {
- mmax=max(mmax,nx);nx=;
- while(top>)sum[top]=,top--;
- sum[top]=;
- }
- }
- else if(ss[i]=='}')
- {
- if(top>&&sta[top]==)
- {
- sum[top-]+=sum[top]+;
- sum[top]=,top--;
- nx=max(nx,sum[top]);
- }
- else
- {
- mmax=max(mmax,nx);nx=;
- while(top>)sum[top]=,top--;
- sum[top]=;
- }
- }
- }
- printf("%d\n",max(mmax,nx));
- return ;
- }
括号画家
3&&6、更加细节题,怂了
upd 完了表达式计算这种NOIP水题都写了这么久还fail了几发姿势很丑
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- typedef long long LL;
- const LL p=(1LL<<);
- int quick_pow(int A,int p)
- {
- int ret=;
- while(p!=)
- {
- if(p%==)ret*=A;
- A*=A;p/=;
- }
- return ret;
- }
- char ss[];
- int top,nxt[],las;LL sta[];
- int readnum(int &i)
- {
- int ret=;
- while(''<=ss[i]&&ss[i]<='')
- ret=ret*+ss[i]-'', i++;
- i--;
- return ret;
- }
- int t,s[];
- int solve(int l,int r)
- {
- t=;
- if(sta[l+]==p+)sta[l+]=-sta[l+],l++;
- s[++t]=sta[l+];
- for(int i=l+;i<=r-;i+=)
- {
- if(sta[i-]>p+)
- {
- if(sta[i-]==p+)s[t]=s[t]*sta[i];
- if(sta[i-]==p+)s[t]=s[t]/sta[i];
- if(sta[i-]==p+)s[t]=quick_pow(s[t],sta[i]);
- }
- else
- {
- if(sta[i-]==p+)s[++t]=sta[i];
- if(sta[i-]==p+)s[++t]=-sta[i];
- }
- }
- int ret=;
- for(int i=;i<=t;i++)ret+=s[i];
- return ret;
- }
- int main()
- {
- scanf("%s",ss+);int n=strlen(ss+);n++;
- ss[]='(';ss[++n]=')';
- las=;top=;
- for(int i=;i<=n;i++)
- {
- if(''<=ss[i]&&ss[i]<='')sta[++top]=readnum(i);
- else if(ss[i]=='(')sta[++top]=p, nxt[top]=las,las=top;
- else if(ss[i]=='+')sta[++top]=p+;
- else if(ss[i]=='-')sta[++top]=p+;
- else if(ss[i]=='*')sta[++top]=p+;
- else if(ss[i]=='/')sta[++top]=p+;
- else if(ss[i]=='^')sta[++top]=p+;
- else if(ss[i]==')')
- {
- int r=top+;
- top=las, sta[top]=solve(las,r), las=nxt[las];
- }
- }
- printf("%d\n",sta[top]);
- return ;
- }
表达式计算4
4、poj1964 这个不就是2559嘛,枚举一下列就行了(鄙视rainbowcat卖狗粮)
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- int m,n,c[];
- char ss[];
- void sc()
- {
- for(int i=;i<=n;i++)
- {
- scanf("%s",ss+);
- if(ss[]=='R')c[i]=;
- else c[i]++;
- }
- }
- int top,sta[],w[];
- int solve()
- {
- int ret=;c[n+]=;
- top=;sta[++top]=;w[top]=;
- for(int i=;i<=n+;i++)
- {
- int L=;
- while(top>&&c[i]<=c[sta[top]])
- {
- ret=max(ret,c[sta[top]]*(w[top]+L));
- L+=w[top];top--;
- }
- sta[++top]=i;w[top]=L+;
- }
- return ret*;
- }
- int main()
- {
- int T;
- scanf("%d",&T);
- while(T--)
- {
- int mmax=;
- scanf("%d%d",&m,&n);
- memset(c,,sizeof(c));
- for(int T=;T<=m;T++)
- sc(), mmax=max(mmax,solve());
- printf("%d\n",mmax);
- }
- return ;
- }
poj1964
5、这题都做到烂了
7、Matrix 这题真是做到人心态血崩。。。首先A是到100的,我就直接把每一列长度为A的区间用两个long long存,然后xjb hash前10位弄个hash表,结果这狗逼数据居然故意卡我,弄个全是0的矩阵询问还只有最后一位1,然后我也很不要脸的把后10位hash了做。。。
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- typedef long long LL;
- char ss[][],sc[][];
- LL zt[][][],hh[][];
- int n,m,A,B;
- int nxt[],last[];
- int point(int x,int y){return (x-)*m+y;}
- int main()
- {
- scanf("%d%d%d%d",&n,&m,&A,&B);
- for(int i=;i<=n;i++)scanf("%s",ss[i]+);
- memset(zt,,sizeof(zt));
- for(int i=;i<=n-A+;i++)
- for(int j=;j<=m;j++)
- for(int k=;k<=A;k++)
- {
- LL x=ss[i+k-][j]-'';
- if(k<=)zt[i][j][]+=(x<<(k-));
- else zt[i][j][]+=(x<<(k-));
- }
- for(int i=;i<=n-A+;i++)
- for(int j=;j<=m-B+;j++)
- {
- int p=point(i,j);LL ke=;
- int li=min(B,);
- for(int k=B-li+;k<=B;k++)
- {
- LL d=(zt[i][j+k-][]*+zt[i][j+k-][])%;
- ke=(ke*+d)%;
- }
- nxt[p]=last[ke];
- last[ke]=p;
- }
- int Q;
- scanf("%d",&Q);
- while(Q--)
- {
- for(int i=;i<=A;i++)scanf("%s",sc[i]+);
- memset(hh,,sizeof(hh));
- for(int j=;j<=B;j++)
- for(int i=;i<=A;i++)
- {
- LL x=sc[i][j]-'';
- if(i<=)hh[j][]+=(x<<(i-));
- else hh[j][]+=(x<<(i-));
- }
- LL ke=;int li=min(B,);
- for(int k=B-li+;k<=B;k++)
- {
- LL d=(hh[k][]*+hh[k][])%;
- ke=(ke*+d)%;
- }
- int QAQ=;
- for(int k=last[ke];k;k=nxt[k])
- {
- int x,y;
- y=(k%m==)?m:k%m;
- x=(k-y)/m+;
- bool bk=true;
- for(int j=;j<=B;j++)
- if(hh[j][]!=zt[x][y+j-][]||
- hh[j][]!=zt[x][y+j-][])
- {bk=false;break;}
- if(bk==true){QAQ=;break;}
- }
- printf("%d\n",QAQ);
- }
- return ;
- }
Matrix
8、做KMP那章的时候没有最小表示法的例题,就随便找了道,结果就是这个0x15 KMP
9、poj2185 先把行hash,然后做kmp求循环节,同样把列这样搞一次,乘起来就行了
contest hunter里面还有道EXKMP的,懒得复习了zzz
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- int n,m;
- char ss[][];
- int ha[];
- bool check(int x,int y)
- {
- if(ha[x]!=ha[y])return false;
- for(int j=;j<=m;j++)
- if(ss[x][j]!=ss[y][j])return false;
- return true;
- }
- bool check2(int x,int y)
- {
- if(ha[x]!=ha[y])return false;
- for(int i=;i<=n;i++)
- if(ss[i][x]!=ss[i][y])return false;
- return true;
- }
- int p[];
- int main()
- {
- scanf("%d%d",&n,&m);
- for(int i=;i<=n;i++)scanf("%s",ss[i]+);
- for(int i=;i<=n;i++)
- {
- ha[i]=;
- for(int j=;j<=m;j++)
- ha[i]=(ha[i]*+(ss[i][j]-'A'+))%;
- }
- p[]=;int j=;
- for(int i=;i<=n;i++)
- {
- while(j>&&check(i,j+)==false)j=p[j];
- if(check(i,j+)==true)j++;
- p[i]=j;
- }
- int d1=n-p[n];
- for(int j=;j<=m;j++)
- {
- ha[j]=;
- for(int i=;i<=n;i++)
- ha[j]=(ha[j]*+(ss[i][j]-'A'+))%;
- }
- p[]=;j=;
- for(int i=;i<=m;i++)
- {
- while(j>&&check2(i,j+)==false)j=p[j];
- if(check2(i,j+)==true)j++;
- p[i]=j;
- }
- int d2=m-p[m];
- printf("%d\n",d1*d2);
- return ;
- }
poj2185
10、poj3630 水
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- struct Trie
- {
- int w[];bool b;
- Trie(){}
- void clean(){b=false;memset(w,,sizeof(w));}
- }tr[];int trlen;
- char ss[];
- bool maketree()
- {
- int now=,len=strlen(ss+);bool bk=false;
- for(int i=;i<=len;i++)
- {
- int x=ss[i]-'';
- if(tr[now].w[x]==)
- tr[now].w[x]=++trlen, tr[trlen].clean(), bk=true;
- now=tr[now].w[x];
- if(tr[now].b==true){bk=false;break;}
- }
- tr[now].b=true;
- return bk;
- }
- int main()
- {
- int T;
- scanf("%d",&T);
- while(T--)
- {
- int n;bool qwq=true;
- scanf("%d",&n);
- trlen=;tr[trlen].clean();
- for(int i=;i<=n;i++)
- {
- scanf("%s",ss+);
- if(qwq==true)qwq=maketree();
- }
- if(qwq==true)printf("YES\n");
- else printf("NO\n");
- }
- return ;
- }
poj3630
11、poj1442 难度在题意。
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- #include<queue>
- using namespace std;
- int a[],b[];
- priority_queue<int,vector<int>,greater<int> >q;
- priority_queue<int>d;
- int main()
- {
- int n,m,ti,tp=;
- scanf("%d%d",&n,&m);
- for(int i=;i<=n;i++)scanf("%d",&a[i]);
- for(int i=;i<=m;i++)
- {
- scanf("%d",&ti);
- while(tp<=n&&tp<=ti)
- {
- d.push(a[tp]);tp++;
- q.push(d.top());d.pop();
- }
- printf("%d\n",q.top());
- d.push(q.top()),q.pop();
- }
- return ;
- }
poj1442
12、bzoj2288: 【POJ Challenge】生日礼物
0x18 总结与练习的更多相关文章
- (.text+0x18): undefined reference to `main'
在将VS中的程序移植到ubuntu中出现的一个问题,主要原因是在vs中默认的主函数写成int _tmain(), 而在gcc编译时要找的是int main().改过来就可以了.
- Gradle 实现 Android 多渠道定制化打包
Gradle 实现 Android 多渠道定制化打包 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在项目中遇到需要实现 Apk 多渠道.定制化打包, Google .百度查找了一些资料, ...
- 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇)
微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这个新东西 这篇我将讲解如何破解这个内存限制 要看关键的可以直接跳到第6步,只需要替换 ...
- Response.Redirect引起的性能问题分析
现象: 最近做的一个系统通过单点登录(SSO) 技术验证用户登录.用户在SSO 系统上通过验证后,跳转到该系统的不同模块.而跳转的时间一直维持子啊几分钟左右. 分析步骤: 在问题复现时抓取Hang d ...
- 你所能用到的BMP格式介绍
原理篇: 一.编码的意义. 让我们从一个简单的问题开始,-2&-255(中间的操作符表示and的意思)的结果是多少,这个很简单的问题,但是能够写出解答过程的人并不 多.这个看起来和图片格式没有 ...
- 使用 GCC 和 GNU Binutils 编写能在 x86 实模式运行的 16 位代码
不可否认,这次的标题有点长.之所以把标题写得这么详细,主要是为了搜索引擎能够准确地把确实需要了解 GCC 生成 16 位实模式代码方法的朋友带到我的博客.先说一下背景,编写能在 x86 实模式下运行的 ...
- Windbg Extension NetExt 使用指南 【2】 ---- NetExt 的基本命令介绍
摘要 : 本章节介绍NetExt常用的命令. 并且对SOS进行一些对比. NetExt的帮助 要想玩好NetExt, 入门就得看帮助. 看NetExt的帮助可以调用!whelp 命令. 这样hi列举出 ...
- 一个由Response.Redirect 引起的性能问题的分析
现象: 某系统通过单点登录(SSO) 技术验证用户登录.用户在SSO 系统上通过验证后,跳转到某系统的主页上面.而跳转的时间很长,约1分钟以上. 分析步骤: 在问题复现时抓取Hang dump 进行分 ...
- C#调用SendMessage 用法
函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一. 函数原型:LRESUL ...
随机推荐
- MongoDB索引05-30学习笔记
MongoDB 索引 索引通常能够极大的提高查询的效率,如果没有索引,MongoDB在读取数据时必须扫描集合中的每个文件并选取那些符合查询条件的记录. 这种扫描全集合的查询效率是非常低的,特别在处理大 ...
- [转]解决C# WinForm 中 VSHOST.EXE 程序不关闭的问题
右击“解决方案”--属性-调试栏-启用调试器部分-“启用Visual studio宿主进程”不勾选
- Web移动端常见问题
一.按钮点击时出现黑色背景 解决方法: .class { -webkit-tap-highlight-color:rgba(0,0,0,0);} .class { -webkit-appearance ...
- MemCached总结二:数据管理指令
管理memcached中的数据包括添加(add).修改(set).删除(delete)及获取(get)等操作. 命令格式: 1.set set userId 0 0 5 12345 STORED ge ...
- houxiurong.com 关于Tomcat7部署 一台机器部署两个项目,一个用域名访问,一个用IP访问
该内容来自 http://houxiurong.com,转载请说明出处. 1.使用IP访问的项目放在Tomcat7 的webapps目录下面:比如:AAA 2.使用域名访问的项目放在Tomcat7的w ...
- 【从零开始】【Java】【0】装软件些
闲聊 其实最先写的是1,所以拐回头写的只能是0了. 因为要在不同的电脑上搞这个东西,必然涉及到装机,当然只是装我们用的这些,且是最基础的部分了. 大晚上的睡不着觉,起来,大概1个小时全部搞定,随便记下 ...
- 【ES6】 Promise / await / async的使用
为什么需要在项目中引入promise? 项目起因:我们在页面中经常需要多次调用接口,而且接口必须是按顺序串联调用 (即A接口调用完毕,返回数据后,再调用B接口) 这样就会造成多次回调,代码长得丑,而且 ...
- linux中errno使用(转)
当linux中的C api函数发生异常时,一般会将errno变量(需include errno.h)赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因,在实际编程中用这一招解决了不少 ...
- 优动漫PAINT如何打开图形文件
优动漫PAINT也就是我们常说的clip studio paint(CSP)的中文版本,在优动漫PAINT软件中打开文件的方式有很多,您可以直接拖拽至优动漫PAINT界面或者文档窗口,也可以执行文件菜 ...
- Windows下的chcp命令(更改该控制台的活动控制台代码页)
Chcp 显示活动控制台代码页数量,或更改该控制台的活动控制台代码页.如果在没有参数的情况下使用,则 chcp 显示活动控制台代码页的数量. 语法 chcp [nnn] 参数 指定代码页.下表列出了所 ...