hdoj 5592 ZYB's Biology 【线段树】 hdoj 5590 ZYB's Biology 【字符串水题】

ZYB's Biology

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 340    Accepted Submission(s): 281


Problem Description
After getting 600 scores in NOIP ZYB(ZJ267) begins to work with biological questions.Now he give you a simple biological questions:
he gives you a DNA sequence and a RNA sequence,then he asks you whether the DNA sequence and the RNA sequence are
matched.

The DNA sequence is a string consisted of A,C,G,T ;The RNA sequence is a string consisted of A,C,G,U .

DNA sequence and RNA sequence are matched if and only if A matches U , T matches A , C matches G , G matches C on each position.
 

Input
In the first line there is the testcase T .

For each teatcase:

In the first line there is one number N .

In the next line there is a string of length N ,describe the DNA sequence.

In the third line there is a string of length N ,describe the RNA sequence.

1T10 , 1N100
 

Output
For each testcase,print YES or NO ,describe whether the two arrays are matched.
 

Sample Input
   
   
2 4 ACGT UGCA 4 ACGT ACGU
 

Sample Output
   
   
YES NO
 

Source


恩,题目大意就是说,给出一个序列到相应位置的逆序数,求原序列。本来想的是求当前位置的数前有几个数比它大就把它插到从后面数几个数之前,这个用for循环写的超时。。。然后现在是找到当前位置的数前有x个数比它大,那么它就是第x+1大的数,倒着插。(看的雨神代码,好久才懂)

<span style="font-family:Comic Sans MS;font-size:18px;">#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 50050
using namespace std;
int n,a[maxn],b[maxn];
struct Node
{
    int l,r,s;
};
Node node[maxn<<2];
void pushup(int o)
{
    node[o].s=node[o<<1].s+node[o<<1|1].s;
}
void build(int o,int l,int r)
{
    node[o].l=l;
    node[o].r=r;
    node[o].s=1;
    if(l==r)
        return ;
    int mid=(l+r)>>1;
    build(o<<1,l,mid);
    build(o<<1|1,mid+1,r);
    pushup(o);
}
void update(int o,int aim)
{
    if(node[o].l==node[o].r)
    {
        node[o].s=0;
        return ;
    }
    int mid=(node[o].l+node[o].r)>>1;
    if(aim<=mid)
        update(o<<1,aim);
    else
        update(o<<1|1,aim);
    pushup(o);
}
int query(int o,int aim)
{
    if(node[o].l==node[o].r)
        return node[o].l;
    if(node[o<<1].s>=aim)
        return query(o<<1,aim);
    else
        return query(o<<1|1,aim-node[o<<1].s);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        a[0]=0;
        build(1,1,n);
        for(int i=n;i>=1;i--)
        {
            int tem=a[i]-a[i-1];
            int p=query(1,tem+1);
            b[i]=n-p+1;
            update(1,p);
        }
        for(int i=1;i<=n;++i)
        {
            if(i==1)
                printf("%d",b[i]);
            else
                printf(" %d",b[i]);
        }
        printf("\n");
    }
    return 0;
}</span>





恩,打BC时的代码,本来以为做对了,又被hack掉了,超时。。。。(还是要用上面线段树做,这个是从前面开始的,其实思想都差不多)

<span style="font-family:Comic Sans MS;font-size:18px;background-color: rgb(192, 192, 192);">#include <iostream>
#include<cstdio>
#include<cstring>
#define maxn 50050
using namespace std;
int a[maxn],b[maxn];
void in(int x,int pos)
{
    for(int i=x;i>x-pos;--i)
    {
        b[i]=b[i-1];
    }
    b[x-pos]=x;
}
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        b[1]=1;
        int s=1;
        for(int i=2;i<=n;++i)
        {
            if(!a[i])
                b[i]=i;
            else
            {
                int tem=a[i]-a[i-1];
                in(i,tem);
            }
        }
        for(int i=1;i<=n;++i)
            a[b[i]]=i;
        for(int i=1;i<=n;++i)
        {
            if(i==1)
                printf("%d",a[i]);
            else
                printf(" %d",a[i]);
        }
        printf("\n");
    }
    return 0;
}</span>




ZYB's Biology

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 340    Accepted Submission(s): 281


Problem Description
After getting 600 scores in NOIP ZYB(ZJ267) begins to work with biological questions.Now he give you a simple biological questions:
he gives you a DNA sequence and a RNA sequence,then he asks you whether the DNA sequence and the RNA sequence are
matched.

The DNA sequence is a string consisted of A,C,G,T ;The RNA sequence is a string consisted of A,C,G,U .

DNA sequence and RNA sequence are matched if and only if A matches U , T matches A , C matches G , G matches C on each position.
 

Input
In the first line there is the testcase T .

For each teatcase:

In the first line there is one number N .

In the next line there is a string of length N ,describe the DNA sequence.

In the third line there is a string of length N ,describe the RNA sequence.

1T10 , 1N100
 

Output
For each testcase,print YES or NO ,describe whether the two arrays are matched.
 

Sample Input
  
  
2 4 ACGT UGCA 4 ACGT ACGU
 

Sample Output
  
  
YES NO
 

Source


恩,字符串水题


<span style="font-family:Comic Sans MS;font-size:18px;background-color: rgb(204, 204, 204);">#include <iostream>
#include<cstdio>
#include<cstring>
#define maxn 110
using namespace std;
char dna[maxn],rna[maxn];
int judge(int x)
{
    if(dna[x]=='A'&&rna[x]=='U')
        return 1;
    if(dna[x]=='C'&&rna[x]=='G')
        return 1;
    if(dna[x]=='T'&&rna[x]=='A')
        return 1;
    if(dna[x]=='G'&&rna[x]=='C')
        return 1;
    return 0;
}
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        getchar();
        for(int i=0;i<n;++i)
            scanf("%c",&dna[i]);
        getchar();
        for(int i=0;i<n;++i)
            scanf("%c",&rna[i]);
        int flag=0;
        for(int i=0;i<n;++i)
        {
            if(!judge(i))
            {
                flag=1;
                break;
            }
        }
        if(flag)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}</span>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值