
ACM
文章平均质量分 62
Cymbals
Public void effect()
展开
-
2020 CCPC Wannafly Winter Camp Day2 K.破忒头的匿名信(AC自动机)
题目:https://ac.nowcoder.com/acm/contest/4010一看到题面,很容易就往dp上想,而dp式也很容易想到,当前dp[i]可以从dp[i - (当前前缀i所有在字典中出现的后缀长度)]位置转移过来,所有转移加上该匹配后缀的cost取个min就是当前dp[i]的值。直觉上,dp的转移位置好像很多,似乎是n方级别的,这就不可做了。一眼看上去确实如此,于是我往许多方向...原创 2020-01-20 23:38:58 · 655 阅读 · 0 评论 -
Comet OJ #contest14 D.转转的数据结构题(珂朵莉树)
题目:https://cometoj.com/contest/73/problem/D?problem_id=4120由于有“将一段区间全部变成v”这一操作,考虑使用珂朵莉树维护。将所有查询离线按右端点排序,在每个查询询问前,将1到R的操作全部做完,然后使用线段树/树状数组查询大于当前询问的L的操作产生的贡献。在珂朵莉树的节点中记录一下当前节点是由第几次操作产生,assigan时消除上次的贡...原创 2019-11-13 16:13:49 · 351 阅读 · 0 评论 -
2019哈尔滨CCPC L.LRU Algorithm(模拟+字典树)
给出一个LRU算法的操作序列,q个查询,询问在内存池大小为m时,LRU操作过程中会不会出现查询给出的内存池状态。我们发现内存池大小的限制因为LRU算法的特殊性质,仅仅只是把当前状态限制成了无限内存池大小的一个前缀。这题就变成了一个前缀匹配问题。由于n比较小,可以考虑n方的算法,模拟LRU算法的过程,不加内存限制,对于每一个中间状态,都去跑一遍查询建立的字典树,在字典树上经过的前缀显然就是答案Y...原创 2019-11-04 14:44:05 · 1025 阅读 · 0 评论 -
[网络流24题]飞行员配对方案问题(最大流)
二分图匹配。使用最大流求解。博客中终于有网络流分类了…建反向边,开两倍空间。#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int, int> pii;const int maxn = 1e5 + 15;int n, m;struct edge...原创 2019-11-02 22:19:00 · 382 阅读 · 0 评论 -
Tarjan求强连通分量模板
int dfn[maxn], low[maxn], scc[maxn], tot, scc_cnt;stack<int> st;void tarjan(int x) { dfn[x] = low[x] = ++tot; st.push(x); for (auto v:G[x]) { if (!dfn[v]) { ta...原创 2019-10-28 14:40:13 · 252 阅读 · 0 评论 -
HDU 5934 Bomb(强连通分量缩点)
题目:https://vjudge.net/contest/338569#problem/P显然可以想到引爆花费最小需要选择能引爆尽量多的,如果A能引爆B,B能引爆C,一定是引爆A最优。如果有一些点可以相互引爆,那么就引爆这些点里花费最小的。“能互相引爆”这显然是一个强连通分量,因此用tarjan求强连通分量之后,对于每个拓扑序最开头(入度为0)的连通分量,选择花费最小的进行引爆,即可求出答...原创 2019-10-28 14:38:10 · 193 阅读 · 0 评论 -
CF-932G Palindrome Partition(回文树等差优化)
给定一个串,把串分为偶数段假设分为了s1,s2,s3…sk求,满足s1=sk,s2=sk−1… 的方案数。当你把原串S变成S′=S[1]S[n]S[2]S[n−2]… 后,这题的问题就变成了有多少种切分S’的方法使得每一段都是回文串。(这个转化已经很神仙了,这道题就出到这里我都觉得已经很nb了)回文切分方法这个东西是一个经典的n方dp,dp[i]表示当前前缀i有多少种切分方法,dp[i]...原创 2019-10-15 20:28:35 · 490 阅读 · 0 评论 -
CodeForces - 598D Igor In the Museum (存储搜索结果)
Igor is in the museum and he wants to see as many pictures as possible.Museum can be represented as a rectangular field of n × m cells. Each cell is either empty or impassable. Empty cells are marke...原创 2018-02-26 01:04:42 · 378 阅读 · 0 评论 -
Nim-硬币游戏2(Java)
n堆硬币,每堆各有xi枚硬币。给定k个数字 a1,a2,a3,…,ak。两人轮流选出一堆硬币,从中取出一些硬币。每次所取硬币枚数一定要在a1,a2,a3,…,ak中。模板题,贴上java代码public class Main { public static void main(String[] args) { Scanner reader = new Scann...原创 2018-02-13 20:33:34 · 628 阅读 · 0 评论 -
POJ 2367 Genealogical tree(Java)
The system of Martians’ blood relations is confusing enough. Actually, Martians bud when they want and where they want. They gather together in different groups, so that a Martian can have one parent ...原创 2018-03-07 22:51:38 · 353 阅读 · 0 评论 -
poj 2960 S-Nim(Java)
这题题目贼长…….Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows: The starting position has a number of heaps, all containing some, not necessar...原创 2018-02-17 02:00:38 · 268 阅读 · 0 评论 -
(挖坑)ACM里常用的流(Stream)操作——Java 8大法好
现在Java 8已经是各大oj的主流配置了吧,对stream的操作是我在打题时吃的最爽的新版糖。然而网上的Java题解本来就少,用stream来解题的….我是一个没看到。stream能找最大值最小值,还能排序,打起来也很爽。关于stream的性能可以看网上的各种测试,似乎跟环境有关系…有空多拿几个oj测一测。于是先挖个坑在这,慢慢填。一、把数组转成流用到java.util.Arrays包里...原创 2018-02-17 10:19:54 · 394 阅读 · 1 评论 -
Nim-硬币游戏1(Java)
Alice和Bob在玩这样一个游戏。给定k个数字a[1],a[2],…,a[k]。一开始,有x枚硬币,Alice和Bob轮流取硬币。每次所取硬币的枚数一定要在a[1],a[2],…,a[k]当中。Alice先取,取走最后一枚硬币的一方获胜。当双方都采取最优策略时,谁会获胜?题目假定a[1],a[2],…,a[k]中一定有1。限制条件:1<=x<=100001<=k&l...原创 2018-02-08 17:14:12 · 828 阅读 · 0 评论 -
回过头看HDU 5011 Game(2014西安区域赛)
Here is a game for two players. The rule of the game is described below: ● In the beginning of the game, there are a lot of piles of beads. ● Players take turns to play. Each turn, player choose a...原创 2018-02-18 22:39:43 · 254 阅读 · 0 评论 -
HDU 1236 排名(Java)
今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑 每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的 考生,并将他们的成绩按降序打印。 Input 测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N < 1000 )、考题数M ( 0 < M < = 10 ...原创 2018-03-14 19:35:39 · 278 阅读 · 0 评论 -
POJ - 1125 Stockbroker Grapevine(Java)
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock m...原创 2018-03-15 13:40:28 · 375 阅读 · 0 评论 -
POJ 3278 Catch That Cow (Java,bfs)
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,0...原创 2018-02-22 00:44:58 · 345 阅读 · 0 评论 -
poj 3984 迷宫问题-水的要死却非要写一堆代码(Java)
定义一个二维数组: int maze[5][5] = {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。Input 一个5 × 5的二维数...原创 2018-02-23 01:19:26 · 904 阅读 · 0 评论 -
hdu1711 记录一个kmp模板
Given two sequences of numbers : a[1], a[2], …… , a[N], and b[1], b[2], …… , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b...原创 2018-03-02 23:38:17 · 267 阅读 · 0 评论 -
获取程序运行时间
long startTime = System.currentTimeMillis();//获取当前时间 //doSomeThing(); //要运行的java程序 long endTime = System.currentTimeMillis(); System.out.println(“程序运行时间:”+(endTime-startTime)+”ms”);...转载 2018-03-03 23:50:45 · 277 阅读 · 0 评论 -
hdu 2577 How to type(Java)
Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some...原创 2018-03-11 22:42:28 · 330 阅读 · 0 评论 -
Codeforces Round #468 (Div. 2)B-World Cup(Java)
The last stage of Football World Cup is played using the play-off system.There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining t...原创 2018-03-05 13:18:25 · 593 阅读 · 0 评论 -
POJ 1745 Divisibility(Java)
Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us,...原创 2018-03-12 17:17:43 · 353 阅读 · 0 评论 -
Gym - 101532A Subarrays Beauty(位操作找规律)
You are given an array a consisting of n integers. A subarray (l, r) from array a is defined as non-empty sequence of consecutive elements al, al + 1, …, ar.The beauty of a subarray (l, r) is calcul...原创 2018-03-19 21:10:18 · 900 阅读 · 0 评论 -
HDU - 2063 过山车(匈牙利算法模板)
RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner。考虑...原创 2018-03-23 20:52:58 · 188 阅读 · 0 评论 -
uva 11636 Hello World!(宽....宽搜.....)
When you first made the computer to print the sentence “Hello World!”, you felt so happy, not knowing how complex and interesting the world of programming and algorithm will turn out to be. Then you...原创 2018-03-29 23:22:21 · 413 阅读 · 1 评论 -
[UVA-11039] Building designing(贪心)
An architect wants to design a very high building. The building will consist of some floors, and each floor has a certain size. The size of a floor must be greater than the size of the floor immediat...原创 2018-03-30 14:46:31 · 412 阅读 · 0 评论 -
2018广工赛L-作弊药水(Java开挂)
题目描述 在一个风雨交加的夜晚,来自异世界的不愿透露姓名的TMK同学获得了两种超强药水A、B。根据说明书,TMK知道了这两种药水的作用: (1)药水A能使人的生命值提高,每饮用1个单位能使他生命值变成原来的x倍,即每饮用p个单位能使他的生命值变成原来的x^p(x的p次方)倍。 (2)药水B能使人的能量值提高,每饮用1个单位能使他能量值变成原来的y倍,即每饮用q个单位...原创 2018-03-30 23:12:20 · 288 阅读 · 0 评论 -
2018华工赛 Youhane's Undergraduate Thesis(丧病大模拟)
大家都知道想从华南理工大学的本科毕业并不是一件简单的事情,作为一名大四即将毕业的学生,优酱正在为她的毕业论文愁眉不展,为什么呢?并不是毕业设计的课题太难了,而是毕业论文有着非常奇怪的格式要求,其中最令人头痛的就是如何正确地引用参考文献。而众所周知,某工是一个制度非常严格而且变化速度非常快的学校。因此发生在毕业论文的Deadline当晚突然宣布参考文献的格式要求产生了变化以致于必须通宵改论文这样...原创 2018-04-07 23:34:06 · 398 阅读 · 0 评论 -
2018华工赛 E-Youhane Assembler(暴力水过)
最长公共前后缀查询问题 我们给出一个字符串的集合,在这个集合中有个字符串,编号为的字符串的长度为。我们给出个查询,每个查询是一个整数对,表示我们假定号串在左边,号串在右边,我们要查询的是最大的长度使号串的前缀与号串的后缀相等。如我们有串:”ACGT”、”AACCGGTT”、“AAAA”,则查询(2,3)的结果为0,因为”AAAA”在右面欲与左面的”AACCGGTT”进行拼接,显然并没有公共的...原创 2018-04-08 14:44:42 · 414 阅读 · 0 评论 -
Gym - 101733D Triangle Construction
Little Andrey wants to work in IT. He already knows that he should exercise in mathematics and algorithms.Andrey likes to play with a set of wooden sticks of various lengths. Experimentally he found...原创 2018-03-21 18:25:06 · 405 阅读 · 0 评论 -
Gym - 101733B Permutation Recovery(极端暴力)
Vladislav invented a new algorithm of the distributed key construction.The distributed key consists of 2n numerical sequences of length n. To construct the key Vladislav gets some permutation p of l...原创 2018-03-21 20:03:23 · 368 阅读 · 0 评论 -
广外oj 亚丝娜和桐人的战斗(线段树or树状数组)
最近市面出现了一款全新的游戏,Absolute Counter Online,简称ACO。Asuna跟她的男票Kirito也都跑去玩这个了。ACO有一个特殊的战斗模式,就是完全反击模式,在这个模式里,Boss跟小怪会来进攻Kirito他们的领地,在他们领地的前面,有N个魔法阵,这些魔法阵排成一条横线,从左往右第i个魔法阵有初始魔力M[i],这些魔法阵会不停消耗魔力攻击接近领地的敌人,并且它们要进入...原创 2018-04-14 20:50:47 · 313 阅读 · 0 评论 -
CodeForces April Fools Day Contest 2018 B-A Map of the Cat
outputstandard output If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. However, s...原创 2018-04-02 18:50:56 · 366 阅读 · 0 评论 -
Codeforces 877E Danil and a Part-time Job(dfs序+线段树)
Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher.Danil works in a rooted tree (undirected connected acyclic graph) with ...原创 2018-04-15 20:10:25 · 277 阅读 · 0 评论 -
hdu 3974 Task assign(哈希暴力 or dfs时间戳+线段树)
There is a company that has N employees(numbered from 1 to N),every employee in the company has a immediate boss (except for the leader of whole company).If you are the immediate boss of someone,that ...原创 2018-04-10 16:20:44 · 458 阅读 · 0 评论 -
spfa模板(链式前向星,bfs,判环)
说起来我该印一份自己的模板了。public class Main { static Set<Integer> visited = new HashSet<>(); static Edge[] edges = new Edge[1005]; static int[] head = new int[1005]; static int[] di...原创 2018-04-03 16:46:53 · 334 阅读 · 0 评论 -
Gym - 101606L Lizard Lounge(最长上升子序)
Monitor lizards are a kind of reptile known mainly for their cold-bloodedness and addiction to computer screens. Due to their love for digital displays, these scaly creatures spend most of their tim...原创 2018-04-04 12:57:43 · 474 阅读 · 0 评论 -
2018 ACM-ICPC B. Goldbach(Java玄学)
Many times, there are more than one way to represent even numbers as two prime numbers. For example, 18=5+13=7+11, 64=3+61=5+59=11+53=17+47=23+41, etc.Now this problem is asking you to divide a po...原创 2018-04-23 20:36:32 · 469 阅读 · 0 评论 -
HDU-4027 Can you answer these queries?(那些年我们踩过的坑)
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of end...原创 2018-05-02 21:59:04 · 249 阅读 · 0 评论