![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
思维
哈哈哈哈哈v3v
这个作者很懒,什么都没留下…
展开
-
HDU - 6574 Rng(概率)
题意:随机选取[1, n] 中的一个整数 r 作为区间右端点,从 [1, r] 中随机选取一个整数作为区间左端点,问以这种方式生成的两个区间相交的概率是多少思路:计算不相交的概率,只考虑左区间的右端点和右区间的左端点,总方法数为 n ^ 2,不相交的情况有(n - 1) + (n - 2) + ... + 1 = (n - 1) * n / 2,所以相交的概率为 (n + 1) / (2 * n)#include <bits/stdc++.h>using namespace std.原创 2021-10-21 19:11:14 · 97 阅读 · 0 评论 -
Codeforces Round #722 (Div. 2) D. Kavi on Pairing Duty(思维)
传送门题意:将1~2n个点两两相连,使得任意两条线段要么相互包含,要么长度相同,问方案数思路:考虑最长线段的长度len(1)len > n 时,外层包含内层,方案数为n = 1,n = 2……,n = n - 1 的方案数总和(2)len <= n 时,所有线段长度相同,长度为len 的线段相互交叉需要2 * len个点,所以方案数为 n 的因子数综上,n 的方案数为前缀和 + n的因子数参考思路:https://blog.csdn.net/quinn18/artic原创 2021-06-02 21:39:14 · 224 阅读 · 0 评论 -
codeforces1454E. Number of Simple Paths(基环图 + 思维)
题意:给一个基环图(比一棵树多一条边的图),问图中原创 2021-06-02 19:58:31 · 113 阅读 · 0 评论 -
HDU - 6285 Vertex Cover(构造)
Alice and Bobo are playing a game on a graph withnnvertices numbered with0,1,…,(n−1)0,1,…,(n−1).The vertex numbered withiiis associated with weight2i2i.The game is played as follows.Firstly, Alice chooses a (possibly empty) subset of then(n−1)...原创 2021-05-03 16:20:16 · 91 阅读 · 0 评论 -
codeforces1496D. Let‘s Go Hiking(思维)
题意:有一个 1 ~ n的排列,Alice和Bob先后选择一个点作为自己的起始点,每人每步只能向相邻的数字移动且不可以走对方当前所占据的位置,Alice只能向更小的数移动,Bob只能向更大的数移动,当某人无法移动时输掉游戏,给定排列,问Alice有几个必胜的起始点可以选择思路:Alice肯定要选最长单调段最大的一端作为起始点,先求出最长单调段的长度 x 和长度为x 的单调段有多少个。如果只有一段,Bob可以在同段中选一个点向上堵Alice,先手必败;如果多于两段,先手必败;如果刚...原创 2021-03-16 20:28:30 · 133 阅读 · 0 评论 -
2018ICPC焦作站 B - Ultraman vs. Aodzilla and Bodzilla(贪心)
题意:怪兽A攻击力为a1,血量为h1,怪兽B攻击力为a2,血量为h2,奥特曼的第 i 秒的攻击力为 i,问在打死两个怪兽之前奥特曼受到的最小伤害,在伤害值最小的前提下求字典序最小的攻击顺序。思路:受到的伤害值最小肯定不能俩怪兽一会儿打一下,那必然是打完一个再去打另一个,所以考虑先打死A还是先打死B。首先求出打死AB的最短时间all,打死A的最短时间a,打死B的最短时间b1、先打死A(1)这时花费了a的时间打死了A,若剩余all - a秒可以打死B,就是前a秒打A,第a + 1秒到第all..原创 2021-02-28 19:32:38 · 301 阅读 · 0 评论 -
codeforces1490 G. Old Floppy Drive(思维)
题意:圆盘上有 n 个数,起初指针在第一个位置,m 次询问,每次询问回答指针至少移动多少次使得指针所经过的所有数的和 >= x(指针不可反向)思路:维护一个递增的前缀和 b[ ],并记录达到该前缀和的位置 id[ ]。(1)判断是否存在,若x > 前缀和的最大值且整个数组的和 <= 0,则不存在。(2)如果第一轮就可以找到 >= x 的数,直接lower_bound;如果需要 k 轮,并且最后加的一个数为b[i],即求一对 i,k 满足 k * sum + b[i..原创 2021-02-17 19:13:16 · 260 阅读 · 0 评论 -
codeforces1485D.Multiples and Power Differences(思维)
题意:构造一个矩阵b,使得对于每个i和j,b[i][j]都是a[i][j]的倍数且矩阵b中相邻两数差值为某正整数的4次方。思路:首先想到用a中所有数的lcm,进一步保证相邻两数不同,每隔一个数换成 lcm + a矩阵中该位置的数的四次方#include <bits/stdc++.h>using namespace std;typedef unsigned long long ll;const ll inf = 0x3f3f3f3f3f3f3f3f;const int mod..原创 2021-02-14 21:40:52 · 105 阅读 · 0 评论 -
Gym - 102920 C - Dessert Café (思维)
题意:一棵n个点的树上有k个特殊点,问满足以下条件的点a的个数:(1)到某个特殊点b的距离小于除a, b外的点到b的距离(2)到某个特殊点c的距离小于b到c的距离思路:求任意两个特殊点之间路径上点的个数#include <bits/stdc++.h>using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;const ll mod = 1e9 + 7;const int N = 1e5...原创 2021-01-31 14:17:49 · 539 阅读 · 0 评论 -
codeforces1478 D. Nezzar and Board(裴蜀定理)
题意:最初有n个数,每次操作可以选取两个数 x, y,将 2x - y 添加到数列里(x, y不擦除),问是否可以组合出数k思路:2x - y = x + (x - y),即每次操作相当于x + 任意差值的线性组合,可以发现a3 - a1 = (a3 - a2) + (a2 - a1),不相邻的两个数的差值可以由相邻的数的差值表示出来,所以只求相邻两数的差值即可。由n个数的裴蜀定理:可知这n - 1个差值能组合出的数一定是它们gcd的倍数,即 (k - a[i])一定是gcd的倍数...原创 2021-01-31 12:56:38 · 205 阅读 · 0 评论 -
Codeforces Global Round 12 C2. Errich-Tac-Toe (Hard Version)(思维)
C2. Errich-Tac-Toe (Hard Version)题意:给一个矩阵,里面有 k 个 'X' 或 'O' 标记,现在要修改不超过 k / 3 个标记('X'改成'O','O'改成'X'),使得矩阵中没有三个连续的相同的标记思路:对两种不同的标记分别修改(i + j)% 3 == opx,(i + j) % 3 == opo 的位置,前提是修改的个数要少于总标记数的三分之一,所以枚举opx和opo,然后判断是否合法#include <bits/stdc++.h>u原创 2020-12-07 19:33:08 · 211 阅读 · 0 评论 -
牛客编程巅峰赛S2第6场 - 钻石&王者 B Bang! Bang!(思维 + 组合数)
思路:m个重音符之间至少间隔k个音符,所以 (m - 1) * k个音符是必选的多余音符,然后再从n - (m - 1) * k个音符中选出m个音符即可,答案就是,提前判断一下n够不够选。#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>using namespace std;typedef lon..原创 2020-12-06 15:39:17 · 126 阅读 · 0 评论 -
2017ccpc杭州 K. Master of Sequence(HDU - 6274 向下取整拆分 + 二分)
题意:浅显易懂不需要解释思路:令,,原式子可以化简为,即当时,第 i 项的值为,否则为原式子转化为了所以预处理,用二维数组表示所有时b[i] % a[i] >= y 的数目,二分 t 即可(用了4种二分来练练手,都能ac)#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll mod = 998244353;const double eps ...原创 2020-11-09 16:46:57 · 183 阅读 · 0 评论 -
2017ccpc杭州 D - Master of Random(hdu6267 期望 + 找规律)
题意:有n个点,每个点对应一个权值,现在要建一颗树,给第 i 个点从点[0, i - 1]中随机选择一个父亲节点,求树中所有子树权值之和的期望思路:没啥思路 硬找规律n = 4的情况:发现0号点贡献了6次,6 = 3!1号点贡献了12次,12 = 3!+ 3!/ 12号点贡献了15次,15 = 3!+ 3!/ 1 + 3!/ 23号点贡献了17次,17 = 3!+ 3!/ 1 + 3!/ 2 + 3!/ 3于是 x 号点贡献的次数为 n! + n! / 1 ...原创 2020-11-08 19:44:59 · 186 阅读 · 0 评论 -
牛客练习赛72 C brz的序列(思维 + 凸壳)
链接:https://ac.nowcoder.com/acm/contest/8282/C来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 524288K,其他语言1048576K64bit IO Format: %lld题目描述巨佬 lzy\text{lzy}lzy 闲来无事,给了蒟蒻 brz\text{brz}brz 一个长度为 n 的序列 a,并且允许蒟蒻操作这个序列,巨佬 lzy\text{lzy}lzy 定义,一次操作要选定一个 i∈(1,n)i\in.原创 2020-11-07 11:22:13 · 266 阅读 · 0 评论 -
codeforces1428 E. Carrots for Rabbits(贪心)
E. Carrots for Rabbitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are some rabbits in Singapore Zoo. To feed them, Zookeeper boughtnncarrots with lengthsa1,a2,a3,…,ana1,a2,...原创 2020-10-20 09:26:39 · 500 阅读 · 0 评论 -
codeforces1428 D. Bouncing Boomerangs(思维)
D. Bouncing Boomerangstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo improve the boomerang throwing skills of the animals, Zookeeper has set up ann×nn×ngrid with some targets,wh...原创 2020-10-19 20:34:06 · 477 阅读 · 2 评论 -
CodeForces - 1430D String Deletion (思维)
You have a stringssconsisting ofnncharacters. Each character is either0or1.You can perform operations on the string. Each operation consists of two steps:select an integeriifrom11to the length of the stringss, then delete the charactersisi...原创 2020-10-13 23:51:17 · 461 阅读 · 0 评论 -
CodeForces - 1430E - String Reversal (树状数组)
You are given a stringss. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if yo.原创 2020-10-13 22:03:00 · 471 阅读 · 0 评论 -
HHKB Programming Contest 2020 D - Squares(思维)
Problem StatementGiven are integers N, A , and B .We will place a white square whose side is of length NN on the coordinate plane so that the vertices are at (0,0) , (N,0) , (0,N) , and (N,N)Then, we will place a blue square whose side is of length .转载 2020-10-12 11:26:03 · 147 阅读 · 0 评论 -
牛客练习赛71 C数学考试(思维 + dp)
链接:https://ac.nowcoder.com/acm/contest/7745/C来源:牛客网数学考试时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述牛牛在树剖姐姐的数学考试里出了一个题,但是树剖姐姐不会做,于是她向您求助。求 1∼n1\sim n1∼n的排列,有 m 个限制条件,第i个限制条件 pip_ipi表示前 pip_ipi个数不能是 1∼pi1\si...原创 2020-10-10 13:34:26 · 233 阅读 · 0 评论 -
CodeForces - 1408D Searchlights(思维)
There arennrobbers at coordinates(a1,b1)(a1,b1),(a2,b2)(a2,b2), ...,(an,bn)(an,bn)andmmsearchlight at coordinates(c1,d1)(c1,d1),(c2,d2)(c2,d2), ...,(cm,dm)(cm,dm).In one move you can move each robber to the right (increaseaiaiof each robber ...原创 2020-10-09 17:48:37 · 110 阅读 · 0 评论 -
HDU - 6736 Forest Program (思维 + 无向图暴力搜环)
The kingdom of Z is fighting against desertification these years since there are plenty of deserts in its wide and huge territory. The deserts are too arid to have rainfall or human habitation, and the only creatures that can live inside the deserts are th原创 2020-10-02 09:45:46 · 135 阅读 · 0 评论 -
EOJ Monthly 2020.9 B. 健康监测计划(贪心)
B. 健康监测计划单点时限:2.0 sec内存限制:256 MBQQ 小方接到了来自学校防控疫情指挥部的任务,协助指挥部部署校园内的健康监测站。华东师范大学共有n栋楼房,编号为1,2,…,n,并有n−1条双向联通的道路连接这些楼房,使得任意两栋楼房之间有且仅有一条简单路径(一条简单路径是指,从一栋大楼出发,不经过重复大楼,并在另一栋大楼结束的路径)。学校为了贯彻落实常态化疫情防控政策,决定选择一些楼房,在其中各设置一个健康监测点,实时监测路过的同学的健康状况。虽然自动化检查...原创 2020-10-02 08:58:31 · 153 阅读 · 0 评论 -
codeforces1426 E. Rock, Paper, Scissors(思维 || 最小费用最大流)
E. Rock, Paper, Scissorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob have decided to play the game "Rock, Paper, Scissors".The game consists of several rounds, each r原创 2020-09-29 22:13:47 · 2147 阅读 · 3 评论 -
Gym - 102394I Interesting Permutation (思维)
DreamGrid has an interesting permutation of1,2,…,n1,2,…,ndenoted bya1,a2,…,ana1,a2,…,an. He generates three sequencesff,ggandhh, all of lengthnn, according to the permutationaain the way described below:For each1≤i≤n1≤i≤n,fi=max{a1,a2,…,ai}fi...原创 2020-09-18 00:17:12 · 294 阅读 · 1 评论 -
牛客练习赛69 E 字串(思维 || 单调栈 + 扫描线 + 树状数组)
链接:https://ac.nowcoder.com/acm/contest/7329/E来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述给出一个长度为 n 排列 pi规定一个区间 [l,r](l<=r) 是 fair 的,当且仅当区间中最小值等于 l 并且最大值等于 r求 fair 区间的个数输入描述:第一行一个 n 代表排列长度...原创 2020-09-17 16:04:26 · 209 阅读 · 6 评论 -
HDU - 6438 Buy and Resell (贪心 + 优先队列)
The Power Cube is used as a stash of Exotic Power. There arenncities numbered1,2,…,n1,2,…,nwhere allowed to trade it. The trading price of the Power Cube in theii-th city isaiaidollars per cube. Noswal is a foxy businessman and wants to quietly make...原创 2020-09-16 19:27:15 · 124 阅读 · 0 评论 -
HDU - 6763 Total Eclipse(并查集 + 逆向思维)
There arenncities andmmbidirectional roads in Byteland. These cities are labeled by1,2,…,n1,2,…,n, the brightness of theii-th city isbibi.Magician Sunset wants to play a joke on Byteland by making a total eclipse such that the brightness of every ...原创 2020-08-30 20:26:28 · 155 阅读 · 0 评论 -
acpc2013 G. The Stones Game (思维)
题意:n个狮子石子,m个人轮流取,每个人有两步,第一步选择取一个或不取,第二步如果他的上一位玩家的第一步取了,当前玩家第二步不能取石子,否则当前玩家第二步取一个石子,问第 x 个人有没有必胜策略思路:https://blog.csdn.net/modiz/article/details/37999947#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll inf = 0x...原创 2020-07-23 13:58:14 · 137 阅读 · 0 评论 -
HDU - 6665 Calabash and Landlord(离散化 + dfs)
Calabash is the servant of a landlord. The landlord owns a piece of land, which can be regarded as an infinite 2D plane.One day the landlord set up two orthogonal rectangular-shaped fences on his land. He asked Calabash a simple problem: how many nonempt.原创 2020-07-09 18:40:19 · 211 阅读 · 0 评论 -
HDU - 6667 Roundgod and Milk Tea (Hall定理 || 贪心)
Roundgod and Milk TeaTime Limit: 6000/6000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1534Accepted Submission(s): 724Problem DescriptionRoundgod is a famous milk tea lover at Nanjing University second t...原创 2020-07-09 16:04:22 · 230 阅读 · 0 评论 -
Codeforces Round #641 (Div. 2)
A. Orac and Factors题意:进行 k 次操作:将原数加上它的最小因子(除1外)思路:如果 n 是偶数,每次加的都是 2如果 n 是奇数,第一次加上一个奇数,然后变成了一个偶数,之后都加2#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned long long ull;const int inf = 0x3f3f3f3f;con..原创 2020-05-13 15:43:38 · 203 阅读 · 3 评论 -
codeforces1348 D. Phoenix and Science
D. Phoenix and Sciencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPhoenix has decided to become a scientist! He is currently investigating the growth of bacteria.Initially, on da原创 2020-05-08 21:54:36 · 141 阅读 · 0 评论 -
codeforces1345 C. Hilbert's Hotel(贪心)
C. Hilbert's HotelHilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer,including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning t.原创 2020-05-08 19:31:15 · 243 阅读 · 0 评论 -
nowcoder20030 [HNOI2003]操作系统(优先队列)
链接:https://ac.nowcoder.com/acm/problem/20030来源:牛客网题目描述写一个程序来模拟操作系统的进程调度。假设该系统只有一个CPU,每一个进程的到达时间,执行时间和运行优先级都是已知的。其中运行优先级用自然数表示,数字越大,则优先级越高。如果一个进程到达的时候CPU是空闲的,则它会一直占用CPU直到该进程结束。除非在这个过程中,有一个比它优先...原创 2020-04-28 22:14:51 · 203 阅读 · 0 评论 -
codeforces1343 D. Constant Palindrome Sum(差分)
D. Constant Palindrome Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an arrayaaconsisting ofnnintegers (it...原创 2020-04-22 16:11:00 · 321 阅读 · 0 评论 -
ICPC Asia Taipei-Hsinchu Regional 2019 H.Mining a(思维)
Problem DescriptionBlockchain technology is used in many digital currency systems, such as Bitcoin and Ethereum. In this technology, distributed users share a common list of records (called the chai...原创 2020-04-03 16:49:06 · 714 阅读 · 0 评论 -
ICPC Asia Taipei-Hsinchu Regional 2019 The League of Sequence Designers(构造)
Problem DescriptionConsider the following sequence problem: givennnintegersa_{1}, a_{2}, \ldots, a_{n},a1,a2,…,an,where\left|a_{i}\right| \leq 10^{6}∣ai∣≤106for all1 \leq i \leq n1≤i≤nand...原创 2020-04-03 16:41:54 · 596 阅读 · 0 评论 -
UCF Local Programming Contest 2016 H. Count the Dividing Pairs(整除对数)
Number Theory provides many fascinating properties. You have most likely written programs dealing with different groups of numbers such as Prime, Perfect, Amicable, Happy, Powerful, and Untouchable nu...原创 2020-03-28 20:28:34 · 275 阅读 · 0 评论