%300为0的个数(牛客第四场)-- number
题意:
给你一串数,问你如题。
思路:

我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系:
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<long long, vector<long long>, greater<long long> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register long long a=b;a<=c;++a)
#define fr(a,b,c) for(register long long a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
void swapp(long long &a,long long &b);
double fabss(double a);
long long maxx(long long a,long long b);
long long minn(long long a,long long b);
long long Del_bit_1(long long n);
long long lowbit(long long n);
long long abss(long long a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const long long inf=(<<);
const double ESP=1e-;
const long long mod=(long long)1e9+;
const long long N=(long long)1e6+; char s[N];
long long ans=; int main()
{
sc("%s",s+);
s[]='&';
long long l=strlen(s)-;
long long cont=;
long long cnt[]={,,,},temp=;
fr(i,l,)
{
temp+=s[i]-'';
temp%=;
cnt[temp]++;
if(s[i]=='')
cont++;
}
fr(i,l,)
{
if(s[i]==s[i+]&&s[i]=='')
ans+=cnt[];
temp=s[i]-'';
temp%=;
if(temp==)
cnt[]--;
else if(temp==)
{
long long a=cnt[],b=cnt[],c=cnt[];
cnt[]=b-;cnt[]=a,cnt[]=c;
}
else
{
long long a=cnt[],b=cnt[],c=cnt[];
cnt[]=a-,cnt[]=c,cnt[]=b;
}
} pr("%lld\n",ans+cont);
return ;
} /**************************************************************************************/ long long maxx(long long a,long long b)
{
return a>b?a:b;
} void swapp(long long &a,long long &b)
{
a^=b^=a^=b;
} long long lowbit(long long n)
{
return n&(-n);
} long long Del_bit_1(long long n)
{
return n&(n-);
} long long abss(long long a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} long long minn(long long a,long long b)
{
return a<b?a:b;
}
%300为0的个数(牛客第四场)-- number的更多相关文章
- 3的倍数 或运算构造x(牛客第四场)-- triples I
题意: 给你一个数,希望你能用最少的3的倍数或运算成它,让你输出答案. 思路: 进制%3有规律,1.2.4.8.16%3是1.2.1.2.1 ... 利用这一点分情况取一些位合成一些数就是答案了. # ...
- 分层最短路(牛客第四场)-- free
题意: 给你边权,起点和终点,有k次机会把某条路变为0,问你最短路是多长. 思路: 分层最短路模板题.题目有点坑(卡掉了SPFA,只能用dijkstra跑的算法). #include<iostr ...
- 笛卡尔树--牛客第四场(sequence)
思路: O(n)建一颗笛卡尔树,再O(n)dfs向上合并答案就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include &l ...
- 线性基求交(线段树)--牛客第四场(xor)
题意: 给你n个基,q个询问,每个询问问你能不能 l~r 的所有基都能表示 x . 思路: 建一颗线性基的线段树,up就是求交的过程,按照线段树区间查询的方法进行check就可以了. #define ...
- 最短meeting路线(树的直径)--牛客第四场(meeting)
题意: 给你一棵树,树上有些点是有人的,问你选一个点,最短的(最远的那个人的距离)是多少. 思路: 其实就是树的直径,两遍dfs,dfs第二遍的时候遇到人就更新直径就行了,ans是/2,奇数的话+1. ...
- 最小的K个数 牛客网 剑指Offer
最小的K个数 牛客网 剑指Offer 题目描述 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. class Solution ...
- 第K个数 牛客网 程序员面试金典 C++ Python
第K个数 牛客网 程序员面试金典 C++ Python 题目描述 有一些数的素因子只有3.5.7,请设计一个算法,找出其中的第k个数. 给定一个数int k,请返回第k个数.保证k小于等于100. 测 ...
- 牛客网第一场 A Monotonic Matrix
链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Count the number of n x m matrices A satisfying ...
- 牛客第四次多校Maximum Mode
链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 题目描述 The mode of an integer sequence is the valu ...
随机推荐
- Java中的Error和Exception
Exception和Error都是继承了Throwable类,在Java中只有Throwable类型的实例才可以被抛出(throw)或者捕获(catch),它是异常处理机制的基本组成类型. Excep ...
- HTML状态消息和方法
参考链接1 参考链接2 当浏览器从 web 服务器请求服务时,可能会发生错误. HTML消息 1xx: 信息 消息: 描述: 100 Continue 服务器仅接收到部分请求,但是一旦服务器并没有拒绝 ...
- 使用SpringBoot校验客户端传来的数据
前端的数据校验都是辣鸡!后端天下第一! 很多时候我们后端需要前端传数据过来, 比如注册, 修改用户名, 修改密码等等.很可能有些用户就喜欢搞事, 喜欢发一大堆乱七八糟的数据到后端来, 甚至有些前端老哥 ...
- 19个JavaScript简化编码小技巧
这篇文章适合任何一位基于JavaScript开发的开发者.我写这篇文章主要涉及JavaScript中一些简写的代码,帮助大家更好理解一些JavaScript的基础.希望这些代码能从不同的角度帮助你更好 ...
- Mysql中两个select语句的连接
Mysql中两个select语句连接需要用到操作符 SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥 ...
- LC 856. Score of Parentheses
Given a balanced parentheses string S, compute the score of the string based on the following rule: ...
- LC 833. Find And Replace in String
To some string S, we will perform some replacement operations that replace groups of letters with ne ...
- Selenium 2自动化测试实战26(unittest单元测试框架)
一.unittest单元测试框架 1.认识单元测试 1.断言方法 #计算器类 #coding:utf-8 #计算器类 class Count: def __init__(self,a,b): self ...
- js中||与&&的用法
|| 或 &&与常用法 func a()和func b() a() && b() 如果a执行成功返回true则执行b返回b结果的值,如果a执行返回false则不执行b ...
- jQuery页面加载完毕事件及jQuery与JavaScript的比较
1.jQuery概述 jQuery是一个JavaScript库,它集成了JavaScript.DOM.CSS和Ajax,简化了JavaScript编程,提倡write less, do more. 2 ...