ACM 基本算法
参与ACM期间部分题解
David__TT
这个作者很懒,什么都没留下…
展开
-
0/1背包问题
【动态规划】0/1背包问题时间限制: 1 Sec 内存限制: 64 MB提交: 139 解决: 84[提交][状态][讨论版][命题人:admin]题目描述张琪曼和李旭琳有一个最多能用m公斤的背包,有n块魔法石,它们的重量分别是W1,W2,…,Wn,它们的价值分别为C1,C2,…,Cn。若每种魔法石只有一件,问能装入的最大总价值。输入第一行为两整数m和n,以下n行中,每...原创 2018-05-21 22:17:38 · 253 阅读 · 0 评论 -
杭电5651 xiaoxin juju needs help
As we all known, xiaoxin is a brilliant coder. He knew **palindromic** strings when he was only a six grade student at elementry school. This summer he was working at Tencent as an intern. One...原创 2018-01-25 19:43:03 · 273 阅读 · 0 评论 -
神、上帝以及老天爷
HDU 2006'10 ACM contest的颁奖晚会隆重开始了! 为了活跃气氛,组织者举行了一个别开生面、奖品丰厚的抽奖活动,这个活动的具体要求是这样的: 首先,所有参加晚会的人员都将一张写有自己名字的字条放入抽奖箱中; 然后,待所有字条加入完毕,每人从箱中取一个字条; 最后,如果取得的字条上写的就是自己的名字,那么“恭喜你,中奖了!” 大家可以想象一下当时的气氛之热烈,毕竟中奖者的奖品是大家...原创 2018-01-25 19:46:12 · 108 阅读 · 0 评论 -
求组合数模版
求组合数模版#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#include<queue>#include<vector>#define LL long longusin原创 2018-01-25 19:49:03 · 95 阅读 · 0 评论 -
货币系统问题
【动态规划】货币系统问题时间限制: 1 Sec 内存限制: 64 MB提交: 85 解决: 59[提交][状态][讨论版][命题人:admin]题目描述 货币是在国家或经济体内的物资与服务交换中充当等价物,或是偿还债务的特殊商品,是用作交易媒介、储藏价值和记账单位的一种工具。魔法世界的货币的历史,可以追溯至史前以物易物的阶段,后来经过金属货币、金银、纸币以及金银本位制度,演化...原创 2018-05-21 22:32:15 · 422 阅读 · 0 评论 -
残缺棋盘
棋手楚继光和张琪曼一动不动地在期盼前已经沉默地坐了五个小时。他们全神贯注地盯着每粒棋子。突然,楚继光说:“原则上我是反对在下棋时说话的,但是我现在不得不开口问:现在究竟该谁下一步棋了?”张琪曼说:“谁先走都不重要了,现在的问题是:谁把这个棋盘上的格子损坏了?”如下图所示,有一正方形棋盘,其边长为2k(1<k<10),其中有一格损坏。现在想用下图中间所示形状的硬纸板将没有坏的所有格子盖起来。...原创 2018-07-16 19:19:03 · 478 阅读 · 0 评论 -
【分治】折半查找法
题目描述大魔导师培根曾经说过:“读书使人明智,读诗使人聪慧,演算使人精密,哲理使人深刻,伦理学使人有修养,逻辑修辞使人善辩。”由此可见书籍的重要性是不言而喻的。而与书籍天天打交道的图书管理员,更是夺天地之造化,吸日月之精华的“神之职业”。据史料记载,魔法世界从古至今诞生的众多不平凡的人物中,有不少人都曾经做过“图书管理员”,如道家学派创始人老子,威软公司创始人比耳、少林藏经阁的扫地神僧等等。...原创 2018-06-26 21:51:17 · 765 阅读 · 0 评论 -
01分数规划
Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and the score of the i-th course is c[i].At the university where she attended, the final score of her is ...原创 2018-08-02 20:25:57 · 90 阅读 · 0 评论 -
小奇画画
题目描述红莲清泪两行欲吐半点却无如初是你杳然若绯雾还在水榭畔画楼处是谁衣白衫如初谁红裳如故——《忆红莲》小奇想画几朵红莲,可惜它刚开始学画画,只能从画圆开始。小奇画了n个圆,它们的圆心都在x轴上,且两两不相交(可以相切)。现在小奇想知道,它画的圆把画纸分割成了多少块?(假设画纸无限大) 输入第一行包括1个整数n。接下来n行,每行两个整数x,r,表示小奇画了圆心在(x,0)...原创 2018-08-01 10:20:14 · 170 阅读 · 0 评论 -
异或序列
题目描述已知一个长度为n的整数数列a1,a2,…,an,给定查询参数l、r,问在al,al+1,…,ar区间内,有多少子序列满足异或和等于k。也就是说,对于所有的x,y(l≤x≤y≤r),满足ax⊕ax+1⊕⋯⊕ay=k的x,y有多少组。 输入输入第一行为3个整数n,m,k。第二行为空格分开的n个整数,即a1,a2,…,an。接下来m行,每行两个整数lj,rj,代表一次查询。 ...原创 2018-08-07 20:25:04 · 765 阅读 · 0 评论 -
数论 密码
题目描述有一个密码箱,0到n-1中的某些整数是它的密码。且满足:如果a和b都是它的密码,那么(a+b)%n也是它的密码(a,b可以相等,%表示整除取余数),某人试了k次密码,前k-1次都失败了,最后一次成功了。问:该密码箱最多有多少不同的密码。 输入第一行两个整数分别表示n,k(1≤k≤250000,k≤n≤1014)。第二行为k个用空格隔开的非负整数,表示每次试的密码。数据保证...原创 2018-07-28 20:09:14 · 719 阅读 · 0 评论 -
杭电多校第一场 线段树模板题 Naive Operations
题目描述In a galaxy far, far away, there are two integer sequence a and b of length n.b is a static permutation of 1 to n. Initially a is filled with zeroes.There are two kind of operations:1. add l ...转载 2018-08-01 10:14:54 · 121 阅读 · 0 评论 -
Sandglass
题目描述We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the up...原创 2018-07-30 10:21:22 · 118 阅读 · 0 评论 -
Babelfish
题目描述You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them. 输入...原创 2018-08-02 09:58:38 · 269 阅读 · 0 评论 -
最小化最大值
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that h...原创 2018-07-16 19:05:28 · 1066 阅读 · 0 评论 -
Small Multiple
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.Constraints2≤K≤105K is an integer. 输入Input is given from Standard Input in the following fo...原创 2018-08-07 19:18:16 · 161 阅读 · 0 评论 -
A Question of Ingestion
题目描述Stan Ford is a typical college graduate student, meaning that one of the most important things on his mind is where his next meal will be. Fortune has smiled on him as he’s been invited to a mul...原创 2018-09-03 20:34:17 · 190 阅读 · 0 评论 -
Crowd Control
题目描述The BAPC draws a large number of visitors to Amsterdam. Many of these people arrive at the train station, then walk from intersection to intersection through the streets of Amsterdam in a big pa...原创 2018-08-26 19:16:47 · 156 阅读 · 0 评论 -
序列合并
题目描述有两个长度都是N的序列A和B,在A和B中各取一个数相加可以得到N^2个和,求这N^2个和中最小的N个。 输入第一行一个正整数N;第二行N个整数Ai,满足Ai<=Ai+1且Ai<=10^9;第三行N个整数Bi, 满足Bi<=Bi+1且Bi<=10^9. 输出仅一行,包含N个整数,从小到大输出这N个最小的和,相邻数字之间用空格隔开。...原创 2018-08-10 16:29:04 · 259 阅读 · 0 评论 -
Swaps and Inversions
题目描述Long long ago, there was an integer sequence a.Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yua...原创 2018-08-19 19:05:58 · 123 阅读 · 0 评论 -
【二分和三分】愤怒的牛
题目描述农夫约翰建造了一座有n间牛舍的小屋,牛舍排在一条直线上,第i间牛舍在xi的位置,但是约翰的m头牛对小屋很不满意,因此经常互相攻击。约翰为了防止牛之间互相伤害,因此决定把每头牛都放在离其它牛尽可能远的牛舍。也就是要最大化最近的两头牛之间的距离。牛们并不喜欢这种布局,而且几头牛放在一个隔间里,它们就要发生争斗。为了不让牛互相伤害。John决定自己给牛分配隔间,使任意两头牛之间的最小距离尽...原创 2018-08-09 20:33:12 · 2695 阅读 · 0 评论 -
Ka Chang
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point.Then, you need to handle QQ operations. There're two types:1\ L\ X1 L X: Increase points by XX of all n...原创 2018-09-13 17:30:13 · 199 阅读 · 0 评论 -
牛客第十场: Rikka with Prefix Sum
题目描述Prefix Sum is a useful trick in data structure problems. For example, given an array A of length n and m queries. Each query gives an interval [l,r] and you need to calculate . How to solve thi...原创 2018-08-26 20:51:29 · 159 阅读 · 0 评论 -
Finite Encyclopedia of Integer Sequences
题目描述In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.Let the total numb...原创 2018-08-08 15:55:02 · 97 阅读 · 0 评论 -
【递归】冲突
题目描述监狱的每间牢房是一个不超过4×4的正方形,里面设有一些障碍,牢房里住着的犯人脾气都很大,只要两个犯人位于同一行或同一列即会发生冲突,但障碍物可以阻挡同行或同列犯人的冲突。问最多可放几个犯人而不会发生冲突。如下图所示,左边表示初始牢房样,右边4个显示了摆放方案,当然,最后两个方案是错误的。 输入有多组测试数据,每组数据第一行为一个整数N表示牢房大小。随后N行描述牢房,其中X表...原创 2018-08-10 16:17:49 · 558 阅读 · 2 评论 -
Keeping On Track
题目描述Acmar and Ibmar are at war! You are in charge of a rail network that transports important supplies throughout the great state of Acmar during this delicate time. The rail system is made up of a ...原创 2018-09-03 20:32:02 · 412 阅读 · 0 评论 -
Character Encoding
题目描述In computer science, a character is a letter, a digit, a punctuation mark or some other similar symbol. Since computers can only process numbers, number codes are used to represent characters, w...原创 2018-08-20 19:55:15 · 435 阅读 · 0 评论 -
Master of Phi
题目描述You are given an integer n. Please output the answer of modulo 998244353. n is represented in the form of factorization.φ(n) is Euler’s totient function, and it is defi ned more formally as t...原创 2019-08-01 20:28:38 · 82 阅读 · 0 评论 -
10551: 排队
题目描述聪明的海狸先生病了,所以他得去看医生。医生叫海狸先生去照心电图,但是心电图室门前排起了好长的队。海狸先生只好跟着排了队。站了3小时后,聪明的海狸先生发现很多人并不清楚谁应该站在他们自己前面,这可导致队伍变得一团糟。于是海狸先生数了下,发现队伍中包括他自己一共有n个人,他将这些人从1到n编号,同时他记自己的编号为x。之后,他走到每个人面前,问他在队伍中他前面应该是谁。当然,有人是不知道...原创 2019-08-01 20:29:30 · 132 阅读 · 0 评论 -
10543: 孤岛症候群
题目描述古泉带着SOS团去孤岛合宿!但在一天早上,房间的主人被人用刀捅死在了房间里。春日拿出房间的地图。房间是一个n×m的网格图,其中一些位置是障碍。在房间的一角发现了一个由L/R/U/D 构成的字符串。这显然表示着凶手的移动路径,L, R, U, D分别表示左、右、上、下。大门在网格图的左上方,因而路径的出发点是左上方的格子。然而,这个路径并不一定“合法”。一个路径是不合法的,如果在某一时...原创 2019-08-01 20:29:21 · 506 阅读 · 0 评论 -
花
题目描述某乔为了解花的生长习性,采集了很多春花来研究。但其中混杂了一些普通的花,为了区别它们,某乔研究出春花的一些特征:春花有S种形态,每天都会展现出某种形态。在N天中,如果有且仅有一次:连续3天都是某种形态,那么它就是一朵春花。例如:假设每天的形态分别为:AABBBC,那么这就是一朵春花。但例如:AAABCDDDEEF,AABBBBC,YHNDSB就不是春花。第一个因为A和D各有1次...原创 2019-01-22 20:02:59 · 104 阅读 · 0 评论 -
Operation
题目描述There is an integer sequence a of length n and there are two kinds of operations:0 l r: select some numbers from al...ar so that their xor sum is maximum, and print the maximum value.1 x: appe...原创 2019-08-01 20:29:49 · 231 阅读 · 0 评论 -
路哥从不低头
题目描述路哥是云南中医学院大一新生,对路哥来说任何人任何物都只是他的道具而已。过程不重要,只要最后胜利是属于路哥的。路哥每次出完手就把这锅扔给别人。而他自己,深藏功与名,事了拂衣去。毕竟,深藏不露是一种卓越的才能。某天,路哥被班主任叫去清理海报。这里有一块宽为W,高为H的海报栏。以左下角为原点建立直角坐标系。第i张贴上去的海报左下角为(x1_i,y1_i),右上角为(x2_i,y...原创 2019-08-01 20:29:39 · 81 阅读 · 0 评论 -
调酒壶里的酸奶 19赛季备战省赛
题目描述最近小w学了一手调酒的技巧,这么帅的操作,说不定能靠这个俘获女神的芳心,为了在女神面前露一手,他想在学校里建一个"pub",但是显然学校不可能让他真的建一个"pub",那么他退而求次,想建一个"Yogurt shop",不能用酒,那用酸奶也行啊!今天女神终于来光顾小w的酸奶店了!兴奋的小w拿出自己准备已久每天都仔细擦干净的装备——调酒壶、果汁机、隔冰器和计量杯、砧板、小刀....准备...原创 2019-04-03 09:50:07 · 109 阅读 · 0 评论 -
K Subsequence
题目描述Master QWsin is dating with Sindar. And now they are in a restaurant, the restaurant has n dishes in order. For each dish, it has a delicious value ai. However, they can only order k times. QWsi...原创 2019-08-03 09:54:57 · 244 阅读 · 0 评论 -
Lattice's basics in digital electronics
LATTICE is learning Digital Electronic Technology. He is talented, so he understood all those pieces of knowledge in 10^{-9}10−9 second. In the next 10^{-9}10−9 second, he built a data decoding device...原创 2018-10-04 19:35:40 · 108 阅读 · 0 评论 -
Spell Boost
题目描述Shadowverse is a funny card game. One day you are playing a round of this game.You have n cards, each with two attributes wi and xi. If you use card i, you will cost wi points of power and caus...原创 2018-10-04 19:36:16 · 242 阅读 · 0 评论 -
Modular Production Line
题目描述An automobile factory has a car production line. Now the market is oversupply and the production line is often shut down. To make full use of resources, the manager divides the entire production...原创 2019-08-03 11:01:54 · 159 阅读 · 0 评论 -
Master of Random
题目描述Hakase provides Nano with a problem. There is a rooted tree with values on nodes. For each query,you are asked to calculate the sum of the values in the subtree. However, Nano is a rookie so she...原创 2019-08-06 10:30:50 · 81 阅读 · 0 评论 -
hdu6653 Halt Hater
题目描述Cuber QQ has recently won a million dollars and bought a new car. He is now driving in the Infinite City and he doesn't want his car to stop, ever!The Infinite City, looks like an infinite grid...原创 2019-08-28 09:40:46 · 221 阅读 · 0 评论