Problem A. Sherlock and Parentheses Google APAC 2017 University Test Round B
2017-02-05 20:42
986 查看
这一题比赛时纠结了好久才发现()()()...的形式是最优的,因为这样除了配对的括号之外,两个()之间可以有更多的组合。而((()))就不及前一种形式。
组合数就是单个配对的括号数,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;
}
组合数就是单个配对的括号数,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;
}
相关文章推荐
- Round B APAC Test 2017 Problem A. Sherlock and Parentheses
- Problem B. Sherlock and Watson Gym Secrets Google APAC 2017 University Test Round B
- Problem C. Watson and Intervals Google APAC 2017 University Test Round B
- Problem C. Not So Random Google APAC 2017 University Test Practice Round
- Problem A. Vote Google APAC 2017 University Test Round D
- Problem A. Diwali lightings Google APAC 2017 University Test Round E
- Problem A. Monster Path Google APAC 2017 University Test Round C
- Kickstart Practice Round 2017 Problem C. Sherlock and Parentheses
- Problem C. Codejamon Cipher Google APAC 2017 University Test Round D
- Problem B. Safe Squares Google APAC 2017 University Test Round C
- Problem B. Beautiful Numbers Google APAC 2017 University Test Round E
- Problem A. Lazy Spelling Bee Google APAC 2017 University Test Practice Round
- Problem C. Evaluation Google APAC 2017 University Test Round C
- Problem B. Robot Rock Band Google APAC 2017 University Test Practice Round
- Problem A. Country Leader Google APAC 2017 University Test Round A
- Problem C. Partioning Number Google APAC 2017 University Test Round E
- Problem C. Jane's Flower Shop Google APAC 2017 University Test Round A
- Round B APAC Test 2017 Problem B. Sherlock and Watson Gym Secrets
- Round B APAC Test 2017 Problem D. Sherlock and Permutation Sorting
- Google APAC test 2015 Round B Problem D-Parentheses Order