Codeforces #197 div2

上次掉回div2了。。。这次爬回来……


A水题。

#include 
#include 
#include 
using namespace std;

char str[1000005];
int a[1000005];

bool cmp(int x,int y)
{
    return x


B 水题,不过题目理解错了花了点时间

#include 
#include 
#include 
using namespace std;

int a[100005];

int main()
{
    int i,j,n,m,t,tmp;
    scanf("%d%d",&n,&m);
    t=0;
    for (i=0;i=tmp) ans+=a[i]-tmp;
        else ans+=n-tmp+a[i];
        tmp=a[i];
     //   printf("%I64d\n",ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


C 水dp,最后再算个路径就行了……m=1的时候跪了一次……

#include 
#include 
#include 
using namespace std;

int has[15];
int dp[1005][15][15];
int ans[1005];

int main()
{
    int i,j,n,up,m,k,l;
    for (i=1;i<=10;i++)
    {
        scanf("%1d",&has[i]);
    }
    scanf("%d",&m);
    memset(dp,0,sizeof(dp));
    for (i=1;i<=10;i++)
    {
        if (has[i]==0) continue;
        dp[0][i][i]=1;
    }
    for (i=0;i=0) continue;
                    dp[i+1][abs(j-l)][l]=1;
                }
            }
        }
    }
    for (i=1;i<=10;i++)
    {
        for (j=1;j<=10;j++)
        {
            if (dp[m-1][i][j]==1) break;
        }
        if (j<=10) break;
    }
    if (i>10)
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    int x=i;
    int y=j;
    for (i=m-1;i>0;i--)
    {
        ans[i]=y;
        x=abs(x-y);
        for (j=1;j<=10;j++)
        {
            if (dp[i-1][x][j]==1 && j!=y) break;
        }
        y=j;
        ans[i-1]=j;
    }
    if (m==1)
    {
        for (i=1;i<=10;i++)
        {
            if (has[i]==1)
            {
                printf("%d\n",i);
                return 0;
            }
        }
    }
    for (i=0;i

D 手敲线段树,居然还敲得出来……orz……

#include 
#include 
#include 
using namespace std;

typedef struct
{
    int l,r,val;
}Tree;

int a[1<<18];
Tree tree[1<<20];
int n,nn;

void Build(int t,int l,int r,int deep)
{
    tree[t].l=l;
    tree[t].r=r;
    if (l==r)
    {
        tree[t].val=a[l];
        return;
    }
    int mid=(l+r)/2;
    Build(2*t+1,l,mid,deep+1);
    Build(2*t+2,mid+1,r,deep+1);
    if (nn%2!=deep%2) tree[t].val=tree[2*t+1].val | tree[2*t+2].val;
    else tree[t].val=tree[2*t+1].val ^ tree[2*t+2].val;
  //  printf("%d %d %d\n",t,tree[t].val,deep);
}

void Update(int t,int p,int num,int deep)
{
 //   printf("%d %d %d %d %d\n",t,tree[t].l,tree[t].r,(tree[t].l+tree[t].r)/2,p);
    if (tree[t].l==p && tree[t].r==p)
    {
        tree[t].val=num;
        return;
    }
    int mid=(tree[t].l+tree[t].r)/2;
    if (mid>=p) Update(2*t+1,p,num,deep+1);
    else Update(2*t+2,p,num,deep+1);
    if (nn%2!=deep%2) tree[t].val=tree[2*t+1].val | tree[2*t+2].val;
    else tree[t].val=tree[2*t+1].val ^ tree[2*t+2].val;
}

int main()
{
    int i,j,m,x,y;
    scanf("%d%d",&n,&m);
    nn=n;
    n=1<


你可能感兴趣的:(Codeforces #197 div2)