哈尔滨理工大学软件学院ACM程序设计全国邀请赛(网络同步赛)E 666 By Assassin 坑点水题
2016-12-04 09:19
573 查看
Description CA loves “6” very much. Now CA has a string S which consists of N digits. Now, she wonders that there are how many non-empty strings are substring of S and only contain number “6”. Input First line contains T denoting the number of testcases. T testcases follow. Each testcase contains a integer in the first line, denoting N, the length of string S. The second line is a string whose length is N. 1≤T≤10, 2≤N≤200000 Output For each test case, output answer. Sample Input 2
3
616
3
166
Sample Output
2
3
讲真这种题真不应该写个博客,但是重点就是没有想到用int
类型计算得到long long的过程中可能会爆炸,是我太菜了,发个博记录下。
3
616
3
166
Sample Output
2
3
讲真这种题真不应该写个博客,但是重点就是没有想到用int
类型计算得到long long的过程中可能会爆炸,是我太菜了,发个博记录下。
#include<bits/stdc++.h> #define input freopen("input.txt","r",stdin) using namespace std; int main(){ //freopen("input.txt","r",stdin); int n,i,j,t,start,end,flag; long long sum; string s; scanf("%d",&t); while(t--){ sum=0; scanf("%d",&n); cin>>s; s+='0'; start=end=0; for(flag=0,i=0;i<=n;i++){ if(flag==0&&s[i]=='6'){ flag=1; start=i; } else if(flag==1&&s[i]!='6'){ flag=0; sum+=(long long)((1+(long long)(i-start))*(i-start)/2); //就是这! } } cout<<sum<<endl; } return 0; }
相关文章推荐
- vmware workstation虚拟机网络配置
- 网络图片查看器
- 网络图片查看器
- 简单介绍Java网络编程中的HTTP请求
- bug宝典JAVA篇 package javax.servlet.http does not exis
- PHPSpider结合Fiddler查询HTTP CODE代码错误原因
- Web服务及http协议
- 安卓网络数据缓存策略
- HttpClient实现简单的网络爬虫功能
- iOS 开发 网络编程与通信之XML解析
- Python实现简单网络爬虫功能
- 计算机网络入门概念理解
- TCP/IP基础概念及通信过程举例
- URL类的使用
- javascript XMLHttpRequest 使用笔记
- 5、网络编程
- HttpServlet cannot be resolved to a type解决办法
- POJ-1698-网络流最大流构图
- go http transfer.go学习
- LoadingLayout封装网络请求的各种效果