10.22 simulated match

Posted yodel

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了10.22 simulated match相关的知识,希望对你有一定的参考价值。

 

#include<cstdio>
#include<cstring>
#define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
using namespace std;
int T,n,m;char s[30010],t[30010];
int main(){init("string");
    int i,j,k,l,u;scanf("%d",&T);//read the total_num of the data
    while(T--){scanf("%s%s",&s,&t);//read the two character strings,one with *,one without *
       n=strlen(s),m=strlen(t);//mark their length separately as n and m
       for(i=j=0;i<n;i=k,j=l){u=0;//make a loop from 0 to n in order to visit every element of the string with *
          for(k=i;k<n &&(s[k]==\'*\'||s[k]==s[i]);k++)
          //this loop is used to find the length of *,in a section only with same lectures and *
            if(s[k]==\'*\')u++;//mark the length of *
          for(l=j;l<m&&t[l]==t[j];l++);//we use this loop to find out the largest same part in the string without *
          //l means the tail of the largest same part in the string without *,and j means the head
          //by this ,we think that if we can change * into that same_lecture_section   
          if(!(s[i]==t[j]&&k-i-u<=l-j&&(u||k-i==l-j)))break;
          //if the three condition are all satisfied,just break
        }i<n||j<m?printf("No\\n"):printf("Yes\\n");}return 0;
        //to make a judge if it has satisfied
        //(if i<n,j<m.just means that we can\'t find the satisfied case during the loop,of course no solution)
        //or ,just means that it has found the satisfied case during the loop,of coursse have solution
}

 

 


 

 

 

 

#include<cstdio>
using namespace std;
int n,m,f[400010],l[100010],r[100010],x[100010],p;
#define init(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
void add(int i,int j,int k,int l,int r,int x){if(l<=j&&k<=r)f[i]|=x;
    else{if(l<=(j+k>>1))add(i<<1,j,j+k>>1,l,r,x);
       if(r>(j+k>>1))add(i<<1|1,(j+k>>1)+1,k,l,r,x);}}
int sum(int i,int j,int k,int l,int r){if(l<=j&&k<=r)return f[i];
    else{int p=(1<<30)-1;if(l<=(j+k>>1))p&=sum(i<<1,j,j+k>>1,l,r);
       if(r>(j+k>>1))p&=sum(i<<1|1,(j+k>>1)+1,k,l,r);
       return p;}}
int main()
{init("or");int i,j,k;scanf("%d%d",&n,&m);//read the length of wanted array and the total_num of conditions
    for(p=1;p<n;p<<=1);//make segment trees\'s N
    for(i=1;i<=m;i++)scanf("%d%d%d",&l[i],&r[i],&x[i]),x[i]^=(1<<30)-1,add(1,1,p,l[i],r[i],x[i]);
    //make a loop in order to read each conditions (a[l]|a[l-1]|...|a[r]=x)
    for(i=1;i<p;i++)f[i<<1]|=f[i],f[i<<1|1]|=f[i];//renew down(because we have change their father)
    for(i=p-1;i>0;i--)f[i]=f[i<<1]&f[i<<1|1];    for(i=1;i<=m;i++)if(sum(1,1,p,l[i],r[i])!=x[i])break;//to judge that if can satisfy each condition
    if(i<=m)printf("No\\n");//no solution case
    else{printf("Yes\\n");//have solution case
       for(i=1;i<=n;i++)printf("%d ",f[p+i-1]^(1<<30)-1);printf("\\n");//out the answer
    }return 0;}

 

 


 

 

 

 

#include<cstdio>
#include<algorithm>
#define L long long
#define O(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); 
#define fr(i,a,b)  for(int i=a;i<=b;i++)
using namespace std;
int n,m,w[100010];L s[100010];
struct goods{int v,x;}a[100010];
inline bool cmp(goods a,goods b){return a.v<b.v;}
int in(){int x=0,f=1;char c=getchar();
    for(;c<\'0\'||c>\'9\';c=getchar())if(c==\'-\')f=-1;
    for(;\'0\'<=c&&c<=\'9\';c=getchar())x=(x<<3)+(x<<1)+(c^48);return x*f;}
//read optimization
int main(){O("shop");int i,j,l,r;L k;n=in(),m=in();//read each day\'s goods_num and the total_num of dates 
    for(i=1;i<=n;i++)a[i].v=in(),a[i].x=in();//read each good\'s value and num of goods
    sort(a+1,a+n+1,cmp);//make a sort to set the array in order(increasing)
    fr(i,1,n)s[i]=s[i-1]+(L)a[i].v*a[i].x,w[i]=w[i-1]+a[i].x;//make a prefix array so that we can compare each day\'s buy_goods\' num
    //one to make a prefix against price ,and another to make a prefix against num
    while(m--){scanf("%lld",&k);//read the total num of money
        //i:right border,j:answer,k:money
       for(i=n,j=0;i>0&&k>=a[1].v;){//make a loop ,stop condition:has not been completely visited and can afford the smallest good\'s price
          for(l=1,r=i;l<r;)k>=a[l+r+1>>1].v?l=(l+r+1>>1):r=(l+r+1>>1)-1;
          //make a binary search to find the largest affordable good
          i=l;if(k>=s[i]){j+=w[i];break;}//if can afford all the goods under the affordable good,just buy them all and out answer
          //or we need to use the prefix to calculate the answer
          for(l=1,r=i;l<r;)k>=s[i]-s[l+r>>1]?r=(l+r>>1):l=(l+r>>1)+1;
          //we set the last_l as the right border and 1 as the left border to make a binary search(because we can\'t afford the good behind)
          //make a binary search to find the largest affordable sum of goods
          k-=s[i]-s[l];j+=w[i]-w[l]+k/a[l].v;k%=a[l].v;i=l-1;}
          //just buy them and renew the money,and renew the answer
          //because we may afford the good before,so we should add the remaining affordable good,renew the money and then try to make better
          //(just set the right_border as l-1,and jump into next loop_part)
          //if out ,has two case:case 1:can afford no good ,just out 0
          //                     case 2:has calculate out the solution,just out the solution
       printf("%d\\n",j);}return 0;
}

 

以上是关于10.22 simulated match的主要内容,如果未能解决你的问题,请参考以下文章

10.6 simulated match

9.24 simulated match

10.5 simulated match

10.27 simulated match

9.10 simulated match

PHP常用代码片段