http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3985 题意: 给定一个字符串,由c和p组成,可以添加c或者p. 串中出现一个ccpc 价值+1(ccpc可以出现部分重叠),但是如果添加x个字母,那么花费为x-1.问“价值-花费”的总价值 最大. 最多总价值可以比原来串中的ccpc数目增加1,因为只有第一个字母不要钱,其他字母即使生成一个ccpc,花费也会随应的增加1. 只有一种情况可以再增加1个字母的时候生成两个,那就…
BaoBao has just found a string  of length  consisting of 'C' and 'P' in his pocket. As a big fan of the China Collegiate Programming Contest, BaoBao thinks a substring  of  is "good", if and only if  'C', and  'P', where  denotes the -th charact…
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3992 题意: 走迷宫,一个一维字符串迷宫,由'L'.'R'组成,分别代表向左一步.向右一步,若遇见”死胡同“,可将当前字符替换,比如'L'换成'R',‘R’换成‘L’,从始发地出发,求最少替换多少个字符就可以走出迷宫. 思路: 从起点分别向左向右简单模拟即可. 代码: #include<iostream> #include<cstdio> using…
题意: 一个机器人在长为M的圆形轨道上送气球,当机器人到达M号点的时候下一站会回到1号点,且全程不会停止运动.现在在长为M的轨道上有N个队伍,队伍会在某个时间做需要一个气球,机器人需要送过去.一共有P次请求,每一次请求a.b 表示a号在b时间需要气球.现在给定P次请求和N个队伍在轨道上的位置,机器人在0时刻可在轨道上的任意节点开始.计算从那个节点开始每个请求收到气球的时间t-请求的时间b的差的和的最小值. 思路: 任意选择一个起点 ,算出每次请求的t-b的值并保存在数组h中,值的范围在(0~m-…
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3983 题意: 给定9个血槽,有三种物品,每次可以把连续相同的物品抵消掉,但是只有把连续三个的物品抵消才有价值,问你用哪种方案,能够使获得的价值最大. 思路: 暴力就行,总有6种方案,维护一个最大值即可. 代码: #include <iostream> #include <map> #include <vector> #include <…
题意: 给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n,并且要使得这m个数的或值最小. 思路: 从二进制的角度分析,如果这m个数中有一个数某一位为1,那么最后或起来这一位肯定是为1的,所以如果某一位为1了,那么我们尽量就让其余位也等于1.所以我们从最高位开始枚举,看看这一位是否需要为1,如果需要为1的话,那么剩下的几个数也尽量让这一位等于1. 代码: 不懂啊,还是看别人的代码写的,觉得有用就拿去吧.(卧槽,第一次开我的IDEA写java还不错的嘛) import java.mat…
题意: 定义一种集合,只有两个数,两个数不同且加起来为素数.要从n个数里抽出数字组成该集合(数字也可以是1~n,这个好懵圈啊),要求你选择最多k个该种集合组成一个有最多元素的集合,求出元素的数量. 思路: 代码: #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; +…
题意: 给出两个半径R,r,R表示第一次的大圈半径,r表示第二次的小圈半径.第一次大圈的圆心位于(0,0),第二次小圈的圆心未知,但在大圈内,给你一个n,然后给出n个屋子的位置,问这些屋子中,第二次在小圈的概率最大的屋子有几个,都是哪些. 思路: 首先分析到如果小圈是一个很小很小的圈,那么靠近原点的区域的这些点的概率是一样的,因为都可以使小圈360度绕着这个点旋转.那么接着分析,如果小圈是个较大的圆,那么原点(0,0)可能是100%被包含的,那么就要找到这个临界情况,发现当R=2*r时,原点是恰…
A - Balloon Robot Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3981 Description The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be \(n\) teams participating…
PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding getting killed themselves. BaoBao is a big fan of the game, bu…
BaoBao is trapped in a one-dimensional maze consisting of  grids arranged in a row! The grids are numbered from 1 to  from left to right, and the -th grid is marked with a character , where  is either 'L' or 'R'. Starting from the -th grid, BaoBao wi…
The 2017 China Collegiate Programming Contest Qinhuangdao Site is coming! There will be  teams participating in the contest, and the contest will be held on a huge round table with  seats numbered from 1 to  in clockwise order around it. The -th team…
DreamGrid has a nonnegative integer . He would like to divide  into nonnegative integers  and minimizes their bitwise or (i.e.  and  should be as small as possible). Input There are multiple test cases. The first line of input contains an integer , i…
Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the game world, and the only hope for your kingdom is to save the Goddesses so that they can unleash their power to fight against the witch. In order to s…
Given an array of  integers , we say a set  is a prime set of the given array, if  and  is prime. BaoBao has just found an array of  integers  in his pocket. He would like to select at most  prime set of that array to maximize the size of the union o…
Problem: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3985 题意: 给出一个长度为n的字符串,全部由'C'和'P'组成: then,可以在原有字符串的基础上添加任意多个’C’或’P’,每次添加一个就要花费一些 $value$,第 i 次添加所花费的 $value = i - 1$: 在任意的地方只要组成”CCPC”就可以获得 1 单位的 $value$,问你到最后可以获得最多多少单位的 $value$. 题解: 观…
热身赛 B题 Smartphone: 大整数相乘 Time Limit: 1 Second Memory Limit: 65536 KBHelianthuswolf Co. Ltd. is a multinational “Intestnet” company. Its revenue from global markets grew year by year. Helianthuswolf unveiled its new smartphone Q10 in the spring of 201…
Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring wonderful substring when the times it appears in that string is between AA and BB (A \le times \le BA≤times≤B). Can you calculate the number of wonderful…
String to Integer (atoi) time=272ms   accepted 需考虑各种可能出现的情况 public class Solution { public int atoi(String str) { int length=str.length(); long result=0; int flag=1; Boolean bFlag=false,bSpace=false,bNum=false; if(length<=0) return (int) result; else…
Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB DreamGrid has a nonnegative integer n . He would like to divide n into m nonnegative integers a1,a2,...am and minimizes their bitwise or (i.e.a1+a2+...+am=n  and a1 OR a2 OR a3...OR am should…
题目描述: 把字符串转化为整数值 原文描述: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for…
这是悦乐书的第230次更新,第242篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第97题(顺位题号是443).给定一组字符,就地压缩它.压缩后的长度必须始终小于或等于原始数组.数组的每个元素都应该是长度为1的字符(不是int).在就地修改输入数组后,返回数组的新长度.例如: 输入:["a","a","b","b","c","c","c"…
Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24157    Accepted Submission(s): 9311 Problem Description Ignatius likes to write words in reverse way. Given a single line of text…
题意: 询问一共有有多少个CCPC,每个得1分,可以自己在任意位置添加字母,第i次添加需要耗费i-1分 思路: 既然每次添加需要耗分,添加第二个字母,相当于没有添加,所以只需要添加一次就好 先计算出原始字符串中的CCPC,在不破坏CCPC的前提下,添加字母即可 代码: #include<iostream> #include<cstdio> using namespace std; const int maxn = 2e5+10; int flag[maxn]; char str[m…
Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 16    Accepted Submission(s): 12 Problem Description Given a maze of size n×m. The rows are numbered 1, 2, · · · , n from top to bottom w…
Decimal Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 103    Accepted Submission(s): 49 Problem Description Given a positive integer n, determine if 1n is an infinite decimal in decimal base…
Invoker Time Limit: 15000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 117    Accepted Submission(s): 35 Problem Description In dota2, there is a hero named Invoker. He has 3 basic skills in the game, whic…
链接:https://ac.nowcoder.com/acm/contest/884/I来源:牛客网 题目描述 We call a,ba,ba,b non-equivalent if and only if a≠ba \neq ba​=b and a≠rev(b)a \neq rev(b)a​=rev(b), where rev(s)rev(s)rev(s) refers to the string obtained by reversing characters of sss, for e…
题目链接 传送门 题意 给你一个字符串,要你构造一个长为\(k\)的子串使得每个字母出现的次数在\([L_i,R_i](0\leq i\leq26)\)间且字典序最小. 思路 做这种题目就是要保持思路清晰,博主就是因为写的时候没有想清楚写了一晚上\(+\)一个早上-- 首先我们对于第\(i\)个位置有如果这个位置可以摆放,那么\(L[s[i]-'a'],R[s[i]-'a'],k\)均减少\(1\),如果不能摆放(条件为:\(\sum\limits_{i=0}^{26}L[i]\leq tot-…