Problem A. Sherlock and Parentheses Google APAC 2017 University Test Round B

这一题比赛时纠结了好久才发现()()()...的形式是最优的,因为这样除了配对的括号之外,两个()之间可以有更多的组合。而((()))就不及前一种形式。

组合数就是单个配对的括号数,e.g., () +任意两个()及其中间的配对括号的数目, e.g., ()()...()()。我开始还以为要用组合数计算,后来发现就是(n-1)n/2

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<ctype.h>
#include<map>
#include<time.h>
#include<set>
#include<bitset>
#include<sstream>
using namespace std;
//Google APAC2017 Round B Problem A. Sherlock and Parentheses

const int maxn=100010;
int T;
long long L;
long long R;
long long ans;
long long comb[maxn][maxn];
void init()
{
    memset(comb,0,sizeof(comb));
    comb[0][0]=1;
    for(int i=0;i<maxn;i++)
    {
        comb[i][0]=1;
        comb[i][i]=1;
        
    }
    for(int i=1;i<maxn;i++)
    {
        for(int j=1;j<2;j++)
        {
            comb[i][j]=comb[i-1][j]+comb[i-1][j-1];
            //cout<<i<<" "<<j<<" "<<comb[i][j]<<endl;
        }
    }
}
int main()
{
    freopen("A-large.in","r",stdin);
    freopen("B-small-practice.out","w",stdout);
    scanf("%d",&T);
//    init();
    for(int ca=1;ca<=T;ca++)
    {
        scanf("%lld %lld",&L,&R);
        ans=0;
        long long tmp=min(L,R);
        ans=tmp+tmp*(tmp-1)/2;
        printf("Case #%d: %lld\n",ca,ans);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值