Problem A. Diwali lightings Google APAC 2017 University Test Round E
来源:互联网 发布:软件找不到指定模块 编辑:程序博客网 时间:2024/06/17 12:34
可以先根据前缀和和后缀和算出在pattern S内每个position前后有多少个blue bulbs(包括 当前position)。
然后分类讨论I,J的情况。
如果I,J属于同一个pattern,直接前缀和相减即可。
如果I在J之前的一个pattern,I的后缀和+J的前缀和即可。
如果I和J之间相隔多个pattern,可以计算相隔的pattern中有多少个blue bulbs,再考虑I,J所在的pattern中有多少个blue bulb。
#include<iostream>#include<stdio.h>#include<cstdio>#include<string>#include<cmath>#include<stdlib.h>#include<algorithm>#include<string.h>#include<cstring>#include<vector>#include<queue>#include<map>using namespace std;//2017 RoundE Problem A. Diwali lightingsconst int maxn=110;int T;int S;long long I;long long J;char str[maxn];int preblue[maxn];int nextblue[maxn];int bluenum;long long ans=0;int main(){ freopen("A-large-practice.in","r",stdin);//input.txt freopen("output.txt","w",stdout); scanf("%d",&T); for(int ca=1;ca<=T;ca++) { memset(preblue,0,sizeof(preblue)); memset(nextblue,0,sizeof(nextblue)); bluenum=0; ans=0; scanf("%s",&str); //cout<<str<<endl; scanf("%lld %lld",&I,&J); I--; J--; S=strlen(str); for(int i=0;i<S;i++) { if(str[i]=='B') { bluenum++; if(i==0) { preblue[i]=1; //nextblue[i]=1; } else { preblue[i]=preblue[i-1]+1; } } else { if(i==0) { preblue[i]=0; //nextblue[i]=1; } else { preblue[i]=preblue[i-1]; } } } for(int i=S-1;i>=0;i--) { if(str[i]=='B') { if(i==S-1) { nextblue[i]=1; } else { nextblue[i]=nextblue[i+1]+1; } } else { if(i==S-1) { nextblue[i]=0; } else { nextblue[i]=nextblue[i+1]; } } } long long groupi=I/S; long long groupj=J/S; int idxi=I%S; int idxj=J%S; if(groupi==groupj) { if(str[idxi]=='B') { ans=preblue[idxj]-preblue[idxi]+1; } else { ans=preblue[idxj]-preblue[idxi]; } } else if(groupi+1==groupj) { ans=nextblue[idxi]+preblue[idxj]; } else { ans=(long long)(groupj-groupi-1)*bluenum; ans+=nextblue[idxi]+preblue[idxj]; } printf("Case #%d: %lld\n",ca,ans); } return 0;}
0 0
- Problem A. Diwali lightings Google APAC 2017 University Test Round E
- Round E APAC Test 2017 Problem A. Diwali lightings (C++)
- Problem A. Vote Google APAC 2017 University Test Round D
- Problem B. Rain Google APAC 2017 University Test Round A
- Google APAC 2017 University Test Round E
- Kickstart Practice Round 2 2017 Problem A. Diwali lightings
- Google APAC 2017 University Test Round A
- Problem A. gRanks Google APAC 2016 University Test Round C
- Problem A. Travel Google APAC 2016 University Test Round B
- Problem B. gCube Google APAC 2016 University Test Round A
- Problem C. gCampus Google APAC 2016 University Test Round A
- Problem B. Beautiful Numbers Google APAC 2017 University Test Round E
- Problem C. Partioning Number Google APAC 2017 University Test Round E
- Problem A. Country Leader Google APAC 2017 University Test Round A
- Problem C. Evaluation Google APAC 2017 University Test Round C
- Problem D. Soldiers Google APAC 2017 University Test Round C
- Problem C. Jane's Flower Shop Google APAC 2017 University Test Round A
- Problem A. Monster Path Google APAC 2017 University Test Round C
- Android 6.0 运行时权限
- mybatis实战教程(mybatis in action),mybatis入门到精通
- MySQL5.7.10 安装文档
- 15 套接字和标准IO
- vtk中vtkDICOMImageReader调用流程分析
- Problem A. Diwali lightings Google APAC 2017 University Test Round E
- [Android]Eclipse用正式签名创建debug签名。
- Python元类编程
- securecrt 多窗口执行命令
- spring mvc官方文档提炼总结
- Node.js的文件系统的Api
- 遍历List<Map<String, Object>>
- oracle 11g 完全卸载
- 剑指offer35——数组中的逆序对