zoukankan      html  css  js  c++  java
  • poj 1068 Parencodings

    一个水题,全是小错误,整了一下午。

    题目:http://poj.org/problem?id=1068

    题意:给出一组括号:                   (((()()())))

    P是”)“前面有几个“(”:                   4      5      6  6  6  6

    S是“)”前面第几个“(”是对应的:   1    1      1   4  5   6

    让你根据给出的P求对应的S

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n,i,t,a[1500],b[1500],top,j,sum,ans,x;
    11     cin>>t;
    12     while(t--)
    13     {
    14         cin>>n; x=0;
    15         memset(b,0,sizeof(b));
    16         top=0;
    17         for(i=1; i<=n; i++)
    18         {
    19             cin>>b[i];
    20             for(j=1; j<=b[i]-b[i-1]; j++)
    21             {
    22                 a[++top]=-1;//左括号用-1表示
    23             }
    24             a[++top]=1;//右括号用1表示
    25 26         }
    27         for(i = 1; i <= top; i++)
    28         {
    29             if(a[i]==1)
    30             {
    31                 sum=1; ans=1;
    32                 for(j=i-1; ; j--)
    33                 {
    34                     ans+=a[j];
    35                     if(a[j]==1)//刚开始以为a[j]=-1,也是false了,唉
    36                     sum++;
    37 
    38                     if(ans==0)
    39                     {
    40                         x++;
    41                         printf("%d",sum);
    42                         if(x!=n)//输出格式上也错了好几遍
    43                             printf(" ");
    44                         else
    45                             printf("
    ");
    46                         break;
    47                     }
    48                 }
    49             }
    50         }
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    VMware虚拟机安装
    dmesg功能介绍
    Linux查看MAC地址方法
    linux介绍
    spring boot整合mybatis框架及增删改查(jsp视图)
    idea 热部署的配置
    idea注释类,方法
    idea2018破解
    BootStrap简单table
    解决bootstrap模态框居中问题
  • 原文地址:https://www.cnblogs.com/bfshm/p/3226183.html
Copyright © 2011-2022 走看看