Regular Bracket Sequence(思维)

A string is called bracket sequence if it does not contain any characters other than “(” and “)”. A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters “+” and “1” into this sequence. For example, “”, “(())” and “()()” are regular bracket sequences; “))” and “)((” are bracket sequences (but not regular ones), and “(a)” and “(1)+(1)” are not bracket sequences at all.
You have a number of strings; each string is a bracket sequence of length 2
. So, overall you have 𝑐𝑛𝑡1 strings “((“, 𝑐𝑛𝑡2 strings “()”, 𝑐𝑛𝑡3 strings “)(” and 𝑐𝑛𝑡4 strings “))”. You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length 2(𝑐𝑛𝑡1+𝑐𝑛𝑡2+𝑐𝑛𝑡3+𝑐𝑛𝑡4)
. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either. 继续阅读Regular Bracket Sequence(思维)

【思维/模拟】Self Numbers

传送门:POJ1316
In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), …. For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence
33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, …The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number. There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.

Write a program to output all positive self-numbers less than or equal 1000000 in increasing order, one per line.

继续阅读【思维/模拟】Self Numbers

【思维】Purification

You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:

The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells. 继续阅读【思维】Purification

【数学/思维】出题

小B准备出模拟赛。
她把题目按难度分为四等,分值分别为6,7,8,9。
已知小B共出了m道题,共n分。
求小B最少出了多少道6分题。

分析:

有解条件为

若有解:

设有  道6分题,则剩下的m-x题共n-6x分,

则剩下的题有解的充要条件为

解得

因此答案为max(0,7m-n)。

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long long n,m;
    cin>>n>>m;
    assert(max(n,m)<=1e12);
    if(n<6*m||n>9*m)puts("jgzjgzjgz");
    else cout<<max(0LL,7*m-n);
}

 

【二进制】炫酷路途

传送门:炫酷路途

题目描述

小希现在要从寝室赶到机房,路途可以按距离分为N段,第i个和i+1个是直接相连的,只需要一秒钟就可以相互到达。

炫酷的是,从第i个到第

i+2p

个也是直接相连的(其中p为任意非负整数),只需要一秒钟就可以相互到达。

更炫酷的是,有K个传送法阵使得某些u,v之间也是直接相连的,只需要一秒钟就可以相互到达,当然,由于设备故障,可能会有一些u=v的情况发生。

现在小希为了赶路,她需要在最短的时间里从寝室(编号为1)到达机房(编号为N),她不希望到达这N个部分以外的地方(不能到达位置N+1),也不能走到比自己当前位置编号小的地方(比如从5走到3是非法的)。

她想知道最短的时间是多少。 继续阅读【二进制】炫酷路途

【思维】Applese的取石子游戏

链接:https://ac.nowcoder.com/acm/contest/330/A
来源:牛客网

Applese 和 Bpplese 在玩取石子游戏,规则如下:

一共有偶数堆石子排成一排,每堆石子的个数为 。两个人轮流取石子,Applese先手。每次取石子只能取最左一堆或最右一堆,且必须取完。最后取得的石子多者获胜。假设双方都足够聪明,最后谁能够获胜呢?

继续阅读【思维】Applese的取石子游戏