2016.8.6 做题汇报
来源:互联网 发布:深圳有名的公司 知乎 编辑:程序博客网 时间:2024/06/07 23:49
时间不够,只能发程序了
A:
/*1.在字符数组前面插个空: scanf("%s".chr+1); 注:这个空不能为0,最好附一个值,因为strlen是根据0的位置确定字符数组长度 2.在不能空一个位置的时候,可以选择把另一个数组的下标全部+1,数值不变。 */#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std ;int next[10005];char W[10005],T[1000005];int main(){ int n; cin>>n; for (int N=0;N<n;N++) { scanf("%s",W); scanf("%s",T); int lnW=strlen(W); int lnT=strlen(T); int ans=0,k; memset(next,0,sizeof 0); next[0]=next[1]=-1; k=-1; for (int i=1;i<lnW;i++) { while(k>-1&&W[i]!=W[k+1]) k=next[k+1]; if (W[i]==W[k+1]) k++; next[i+1]=k; } k=-1; for (int i=0;i<lnT;i++) { while(k>-1&&T[i]!=W[k+1]) k=next[k+1]; if (T[i]==W[k+1]) k++; if (k==lnW-1) { k=next[k+1]; ans++; } } cout<<ans<<endl; } return 0;}
B:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std ;int p[220005];int main(){ char str[110005],now[110005]; while ((scanf("%s",str))!=EOF) { int size=0; size=strlen(str); now[0]='!'; now[1]='#'; int x=1; for (int i=0;i<size;i++) { now[++x]=str[i]; now[++x]='#'; }// printf("%s\n",now); memset(p,0,sizeof p); int bj=0; int id=0; size=x; for (int i=1;i<=size;i++) { if (bj>i) if (p[2*id-i]<bj-i) p[i]=p[2*id-i]; else p[i]=bj-i; else p[i]=1; while(now[i-p[i]]==now[i+p[i]]) p[i]++; if (i+p[i]>bj) { bj=i+p[i]; id=i; } } int max_=0,ii; for (int i=1;i<size;i++) if (p[i]>max_) { max_=p[i]; ii=i; } max_--; int s=ii-max_; int e=ii+max_; int ans=0; for (int i=s;i<=e;i++) if (now[i]!='#') ans++; printf("%d\n",ans); } return 0;}
Price List
#include<cstdio>#include<algorithm>using namespace std ;int main(){ long long a,sum=0; int t,n,m; scanf("%d",&t); for (int T=0;T<t;T++) { sum=0; scanf("%d%d",&n,&m); for (int i=0;i<n;i++) { scanf("%I64d",&a); sum+=a; } for (int i=0;i<m;i++) { scanf("%I64d",&a); if (a<=sum) printf("0"); else printf("1"); } printf("\n"); } return 0;}
NanoApe Loves Sequence
#include<cstdio>#include<algorithm>#include<cstdlib>using namespace std ;int a[1000000];int b[1000000];int main(){ int t; scanf("%d",&t); for (int T=0;T<t;T++) { int n,max1=0,max2=0,max3=0; int tot=0; scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=2;i<=n;i++) { b[i]=abs(a[i]-a[i-1]); if (b[i]>max1) { max3=max2; max2=max1; max1=b[i]; } else if (b[i]>max2) { max3=max2; max2=b[i]; } else if (b[i]>max3) { max3=b[i]; } } for (int i=1;i<=n;i++) { if (i==1) { if (b[2]==max1) tot+=max2; else tot+=max1; } else if (i==n) { if (b[n]==max1) tot+=max2; else tot+=max1; } else { int now=abs(a[i-1]-a[i+1]); if (b[i]==max1) { if (b[i+1]==max2) tot+=max(max3,now); else tot+=max(max2,now); } else if (b[i+1]==max1) { if (b[i]==max2) tot+=max(max3,now); else tot+=max(max2,now); } else tot+=max(max1,now); } } printf("%d\n",tot); } return 0;}
NanoApe Loves Sequence Ⅱ
#include<cstdio>#include<algorithm>#include<cstring>using namespace std ;int a[200005], b[200005];bool use[200005];int main(){ int t,n,m,k; scanf("%d",&t); for (int T=0;T<t;T++) { int tot=0; scanf("%d%d%d",&n,&m,&k); for (int i=1;i<=n;i++) scanf("%d",&a[i]); a[n+1]=m; int flag=n+1; for (int i=n;i>=1;i--) { b[i]=flag; if (a[i]>m) flag=i; } b[n+1]=n+1; int c=0; bool now=false; flag=1; if (a[flag]>=m) { c++; now=true; } while (c!=k) { flag=b[flag]; c++; } if (now) c--; memset(use,true,sizeof use); for (int i=1;i<=n;i++) { if (a[i]>=m&&use[i]) c++; while (c<k) { c++; use[flag]=false; flag=b[flag]; use[flag]=false; } tot+=n-flag+1; if (a[i]>=m) c--; } printf("%d\n",tot); } return 0;}
0 0
- 2016.8.6 做题汇报
- 如何做汇报
- 做总结汇报ppt的经验
- 汇报
- 项目汇报XMind 6来帮您
- 遇到问题,得向领导汇报,不能自己做决定啊
- 对于产品经理来说,沟通汇报怎么做?
- 今天给山东省劳动厅做迁移和测试汇报,希望顺利
- 做的好不如说得好,老板为什么喜欢听过程汇报?
- 案件管理汇报系统 v2.6 免费下载--IT man
- 开源夏令营之项目汇报6(中期报告)
- 汇报进度。。。
- 关于汇报
- 汇报 ppt
- 汇报材料
- 打卡汇报
- 汇报心得
- 1.9汇报
- 单页面自动赚钱无敌策略
- 超级自我逆向行销学
- PAT 乙级 1016. 部分A+B (C语言版)
- 【《C++ Primer Plus》读书笔记】第11章 使用类
- 猴子大王 可并堆
- 2016.8.6 做题汇报
- leetcode 41. First Missing Positive
- 跟我一起写Makefile(10)--- 变量(嵌套变量+追加变量+overrid+多行变量+环境变量+目标变量+模式变量)
- iOS序列帧动画
- JDK8 十大新特性详解
- oj:回文字符串处理
- 排序检索-123 quick searching
- java中常用注解
- AS汇编器源码剖析-第1章-Arm操作码