本文共 595 字,大约阅读时间需要 1 分钟。
一看到此题就觉得是一个二分
**#include #include #include #include #include //头文件要加using namespace std;int w,n,wh,j,k,l,r,mid;string s[30001],fi;map cha; //定义mapint main(){ freopen("auto.in","r",stdin); freopen("auto.out","w",stdout); cin>>w>>n; for(int i=1; i<=w; i++) { cin>>s[i]; cha[s[i]]=i; } sort(s+1,s+1+w); for(int i=1; i<=n; i++) { cin>>wh>>fi; k=0,l=1,r=w; while(l<=r) //进行二分 { mid=(l+r)/2; if(s[mid] w||s[l+wh-1].find(fi,0)) //实用的map cout<<-1<
转载地址:http://xjle.baihongyu.com/