zoukankan      html  css  js  c++  java
  • noip模拟赛#42

    T1:给len=1e5的数字串,操作为将某个位置起始的后缀搬到最前面。求有多少个不重复的比原串大和多少个小。

    =>maya这铁定可以找出些什么规律来。然后就over 了。

    =>字符串hash一下就可以了。

    //map的常数还是很大的。hash的时候o->to一定要ll!!! 23333 999983

    #include<cstdio>
    #include<cstring>
    #include<cctype>
    #include<algorithm>
    #include<map>
    using namespace std;
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    #define ll unsigned long long
    #define qwq(x) for(edge *o=head[x];o;o=o->next)
    int read(){
    	int x=0;char c=getchar();
    	while(!isdigit(c)) c=getchar();
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x;
    }
    const int nmax=2e5+5;
    const int inf=0x7f7f7f7f;
    const int mod=999983;
    char s[nmax];ll p[nmax],eo[nmax];
    ll cal(int l,int r){
    	return p[r]-p[l-1]*eo[r-l+1];
    }
    int find(int tl,int tr){
    	int ans=0,mid,l=1,r=tr-tl+1;
    	while(l<=r){
    		mid=l+r>>1;
    		if(cal(1,mid)==cal(tl,tl+mid-1)) ans=mid,l=mid+1;
    		else r=mid-1;
    	}
    	return ans;
    }
    struct edge{
    	ll to;edge *next;
    };edge es[mod<<1],*pt=es,*head[mod<<1];
    bool check(ll x){
    	int t=x%mod;
    	qwq(t) if(o->to==x) return 1;return 0;
    }
    void add(ll x){
    	int t=x%mod;
    	pt->to=x;pt->next=head[t];head[t]=pt++;
    }
    int main(){
    	freopen("number.in","r",stdin);freopen("number.out","w",stdout);
    	scanf("%s",s+1);int n=strlen(s+1);
    	rep(i,1,n) s[i+n]=s[i];
    	eo[0]=1;rep(i,1,n+n) eo[i]=eo[i-1]*233ll;
    	p[0]=1;rep(i,1,n+n) p[i]=p[i-1]*233ll+s[i]-'0';
    	int ans=0,res=0,cur;ll ts;
    	rep(i,2,n){
    		ts=cal(i,i+n-1);cur=find(i,i+n-1);
    		if(cur==n||check(ts)) continue;
    		if(s[i+cur]>s[cur+1])  res++,add(ts);else  ans++,add(ts);
    	}
    	printf("%d 1 %d
    ",ans,res);
    	fclose(stdin);fclose(stdout);
    	return 0;
    }
    

    T2:每次可以捞出一条任意品种的鱼或者捞不出什么鱼。n个品种。给出每一次捞出某个品种的鱼的概率。求捞出全部品种的鱼的期望次数。

    =>http://blog.csdn.net/u011787119/article/details/40151201 里的题差不多。。。然而我最后/tm我一开始总是写成(1-tm)。。。

    #include<cstdio>
    #include<cstring>
    #include<cctype>
    #include<algorithm>
    using namespace std;
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    int read(){
    	int x=0,f=1;char c=getchar();
    	while(!isdigit(c)){
    		if(c=='-') f=-1;c=getchar();
    	}
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x*f;
    }
    const int nmax=3050000;
    const int inf=0x7f7f7f7f;
    double p[nmax],dp[nmax];int t[26];
    int main(){
    	freopen("fish.in","r",stdin);freopen("fish.out","w",stdout);
    	int n=read();p[n+1]=1.0;
    	rep(i,1,n) scanf("%lf",&p[i]),p[n+1]-=p[i];
    	int st=(1<<n)-1;dp[st]=0.0;double tm=0;
    	dwn(i,st-1,0){
    		rep(j,1,n) t[j]=0;t[0]=0;tm=0;
    		for(int tp=i;tp;tp>>=1) t[++t[0]]=tp&1;
    		rep(j,1,n) if(t[j]==0) dp[i]+=dp[i+(1<<(j-1))]*p[j],tm+=p[j];
    		dp[i]+=1.0;dp[i]/=tm;
    	}
    	printf("%.2lf
    ",dp[0]);
    	fclose(stdin);fclose(stdout);
    	return 0;
    }
    

    T3:????不懂。。。

  • 相关阅读:
    CCF CSP 201503-1 图像旋转
    CCF CSP 201403-1 相反数
    CCF CSP 201312-1 出现次数最多的数
    CCF CSP 201703-3 Markdown
    CCF CSP 201709-3 JSON查询
    CCF CSP 201709-2 公共钥匙盒
    CCF CSP 201709-1 打酱油
    CCF CSP 201604-4 游戏
    CCF CSP 201604-1 折点计数
    CCF CSP 201612-1 中间数
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/6022848.html
Copyright © 2011-2022 走看看