思维
文章平均质量分 80
cherish__lin
I want to be better!
展开
-
B2. Cat Party (Hard Edition)(思维)
This problem is same as the previous one, but has larger constraints.Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her ...原创 2019-05-10 17:53:49 · 322 阅读 · 0 评论 -
L1-006 连续因子 (20 分)(简单模拟)
L1-006连续因子(20 分)一个正整数N的因子中可能存在若干连续的数字。例如 630 可以分解为 3×5×6×7,其中 5、6、7 就是 3 个连续的数字。给定任一正整数N,要求编写程序求出最长连续因子的个数,并输出最小的连续因子序列。输入格式:输入在一行中给出一个正整数N(1<N<231)。输出格式:首先在第 1 行输出最长连续因子的个数;然...原创 2019-03-13 08:45:48 · 6684 阅读 · 0 评论 -
I - Mirrored String II (简单模拟)
Note: this is a harder version of Mirrored string I.The gorillas have recently discovered that the image on the surface of the water is actually a reflection of themselves. So, the next thing for th...原创 2019-03-13 07:29:37 · 315 阅读 · 0 评论 -
H - Mirrored String I (简单模拟)
The gorillas have recently discovered that the image on the surface of the water is actually a reflection of themselves. So, the next thing for them to discover is mirrored strings.A mirrored string...原创 2019-03-13 07:24:17 · 407 阅读 · 0 评论 -
C - Cheap Kangaroo(水题gcd)
There areNkangaroos going out to eat at an Indian restaurant. Theithkangaroo wants to eatexactlyxifood. The kangaroos all want to order the same size of plates, but each one can order more than...原创 2019-03-12 23:44:58 · 332 阅读 · 0 评论 -
K - Owl Geeks(水题)
The owls have the following equation:Y = a × x2 + b × xWitha,b, andNgiven, they decide to put into a set the integer values ofYthat are less than or equal to N and that are outputted from th...原创 2019-03-12 23:30:26 · 293 阅读 · 0 评论 -
L3-002 特殊堆栈 (30 分)
堆栈是一种经典的后进先出的线性结构,相关的操作主要有“入栈”(在堆栈顶插入一个元素)和“出栈”(将栈顶元素返回并从堆栈中删除)。本题要求你实现另一个附加的操作:“取中值”——即返回所有堆栈中元素键值的中值。给定 N 个元素,如果 N 是偶数,则中值定义为第 N/2 小元;若是奇数,则为第 (N+1)/2 小元。输入格式:输入的第一行是正整数 N(≤105)。随后 N 行,每行给出一句...原创 2019-03-16 20:02:10 · 1399 阅读 · 0 评论 -
数据结构实验之图论四:迷宫探索(DFS深搜)
Problem Description有一个地下迷宫,它的通道都是直的,而通道所有交叉点(包括通道的端点)上都有一盏灯和一个开关;请问如何从某个起点开始在迷宫中点亮所有的灯并回到起点?Input连续T组数据输入,每组数据第一行给出三个正整数,分别表示地下迷宫的结点数N(1 < N <= 1000)、边数M(M <= 3000)和起始结点编号S,随后M行对应M条边,每行...原创 2019-03-16 18:32:26 · 152 阅读 · 0 评论 -
L2-026 小字辈 (25 分)(简单DFS)
本题给定一个庞大家族的家谱,要请你给出最小一辈的名单。输入格式:输入在第一行给出家族人口总数 N(不超过 100 000 的正整数) —— 简单起见,我们把家族成员从 1 到 N 编号。随后第二行给出 N 个编号,其中第 i 个编号对应第 i 位成员的父/母。家谱中辈分最高的老祖宗对应的父/母编号为 -1。一行中的数字间以空格分隔。输出格式:首先输出最小的辈分(老祖宗的辈分为 1,...原创 2019-03-16 12:16:46 · 344 阅读 · 0 评论 -
L2-005 集合相似度 (25 分)(set巧用)
给定两个整数集合,它们的相似度定义为:Nc/Nt×100%。其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数。你的任务就是计算任意一对给定集合的相似度。输入格式:输入第一行给出一个正整数N(≤50),是集合的个数。随后N行,每行对应一个集合。每个集合首先给出一个正整数M(≤104),是集合中元素的个数;然后跟M个[0,109...原创 2019-03-15 22:22:47 · 170 阅读 · 0 评论 -
F - Divisibility POJ - 1745
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 ...原创 2019-03-08 09:36:11 · 177 阅读 · 0 评论 -
K - 素数回文(25) (素数筛+做题技巧)
xiaoou33对既是素数又是回文的数特别感兴趣。比如说151既是素数又是个回文。现在xiaoou333想要你帮助他找出某个范围内的素数回文数,请你写个程序找出 a 跟b 之间满足条件的数。(5 <= a < b <= 100,000,000);Input这里有许多组数据,每组包括两组数据a跟b。Output对每一组数据,按从小到大输出a,b之间所有满足条件的素数...原创 2019-03-15 19:19:08 · 329 阅读 · 0 评论 -
E - 18岁生日(20) (闰年判断)
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。Input一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。OutputT行,每行一...原创 2019-03-15 18:49:15 · 322 阅读 · 0 评论 -
L2-010 排座位 (25 分)(简单并差集)
布置宴席最微妙的事情,就是给前来参宴的各位宾客安排座位。无论如何,总不能把两个死对头排到同一张宴会桌旁!这个艰巨任务现在就交给你,对任何一对客人,请编写程序告诉主人他们是否能被安排同席。输入格式:输入第一行给出3个正整数:N(≤100),即前来参宴的宾客总人数,则这些人从1到N编号;M为已知两两宾客之间的关系数;K为查询的条数。随后M行,每行给出一对宾客之间的关系,格式为:宾客1 宾客2 ...原创 2019-03-15 18:10:44 · 463 阅读 · 0 评论 -
L1-049 天梯赛座位分配 (20 分)(循环技巧)
天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情。为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位参赛选手。令每校选手排成一列纵队,第 i+1 队的选手排在第 i 队选手之后。从第 1 所学校开始,各校的第 1 位队员顺次入座,然后是各校的第 2 位队员…… 以此类推。如果最后只剩下 1 所学校的...原创 2019-03-15 17:50:10 · 4010 阅读 · 10 评论 -
L1-046 整除光棍 (20 分)
这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1、11、111、1111等。传说任何一个光棍都能被一个不以5结尾的奇数整除。比如,111111就可以被13整除。 现在,你的程序要读入一个整数x,这个整数一定是奇数并且不以5结尾。然后,经过计算,输出两个数字:第一个数字s,表示x乘以s是一个光棍,第二个数字n是这个光棍的位数。这样的解当然不是唯一的,题目要求你输出最小的解。...原创 2019-03-15 17:12:55 · 246 阅读 · 0 评论 -
7-1 垃圾箱分布 (30 分)
大家倒垃圾的时候,都希望垃圾箱距离自己比较近,但是谁都不愿意守着垃圾箱住。所以垃圾箱的位置必须选在到所有居民点的最短距离最长的地方,同时还要保证每个居民点都在距离它一个不太远的范围内。现给定一个居民区的地图,以及若干垃圾箱的候选地点,请你推荐最合适的地点。如果解不唯一,则输出到所有居民点的平均距离最短的那个解。如果这样的解还是不唯一,则输出编号最小的地点。输入格式:输入第一行给出4个正...原创 2019-03-24 23:15:35 · 1870 阅读 · 1 评论 -
7-5 拯救007(升级版) (30 分)(路径输出)
在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里一系列鳄鱼的大脑袋跳上岸去!(据说当年替身演员被最后一条鳄鱼咬住了脚,幸好穿的是特别加厚的靴子才逃过一劫。)设鳄鱼池是长宽为100米的方形,中心坐标为 (0, 0),且东北角坐标为 (50, 50)。池心岛是以 (0, 0) 为...原创 2019-03-25 09:35:31 · 2003 阅读 · 7 评论 -
C. Problem for Nazar(奇偶性质)
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him avery difficult task.Consider two infinite s...原创 2019-04-19 23:22:17 · 320 阅读 · 0 评论 -
G - Seven-Segment Display (思维)
A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven segmen...原创 2019-04-15 09:00:21 · 278 阅读 · 0 评论 -
C. Serval and Parenthesis Sequence(合法括号序列)
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.In his favorite math class, the teacher taught him the following interesting definitions.Aparenthesis ...原创 2019-04-22 09:04:02 · 687 阅读 · 0 评论 -
L - Tic-Tac-Toe
Kim likes to play Tic-Tac-Toe.Given a current state, and now Kim is going to take his next move. Please tell Kim if he can win the game in next 2 moves if both player are clever enough.Here “next ...原创 2019-04-13 12:22:14 · 265 阅读 · 0 评论 -
B - Team Formation (异或)
For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team fromNstudents of his university.Edward knows the skill level of each student. He has fou...原创 2019-04-03 16:20:14 · 226 阅读 · 0 评论 -
D - XOR Permutations
A bitwise XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is11if both bits are different (o...原创 2019-04-09 13:03:46 · 614 阅读 · 0 评论 -
D - Beauty of Array (好题)
Edward has an arrayAwithNintegers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous ...原创 2019-04-03 07:23:38 · 297 阅读 · 0 评论 -
L - Median (矩阵前缀和+二分)
You are given a grid g consisting of n rows each of which is divided into m columns. The grid contains unique values between 1 and n×m(inclusive).Also, you are given two values hand w, and your ...原创 2019-04-07 17:55:43 · 623 阅读 · 0 评论 -
L3-020 至多删三个字符 (30 分)(dp)
给定一个全部由小写英文字母组成的字符串,允许你至多删掉其中 3 个字符,结果可能有多少种不同的字符串?输入格式:输入在一行中给出全部由小写英文字母组成的、长度在区间 [4, 106] 内的字符串。输出格式:在一行中输出至多删掉其中 3 个字符后不同字符串的个数。输入样例:ababcc输出样例:25提示:删掉 0 个字符得到 "ababcc"。...原创 2019-03-23 19:47:46 · 1270 阅读 · 0 评论 -
L3-015 球队“食物链” (30 分)(DFS)
某国的足球联赛中有N支参赛球队,编号从1至N。联赛采用主客场双循环赛制,参赛球队两两之间在双方主场各赛一场。联赛战罢,结果已经尘埃落定。此时,联赛主席突发奇想,希望从中找出一条包含所有球队的“食物链”,来说明联赛的精彩程度。“食物链”为一个1至N的排列{ T1 T2 ⋯ TN },满足:球队T1战胜过球队T2,球队T2战胜过球队T3,⋯,球队T(N−...原创 2019-03-22 18:11:42 · 309 阅读 · 0 评论 -
K - Transformation (区间标记思想)
Yuanfang is puzzled with the question below:There are n integers, a 1, a 2, …, a n. The initial values of them are 0. There are four kinds of operations.Operation 1: Add c to each number between a x...原创 2019-03-18 20:10:06 · 252 阅读 · 0 评论 -
C. Polycarp Restores Permutation(标记+特殊值)
An array of integersp1,p2,…,pnp1,p2,…,pnis called apermutationif it contains each number from11tonnexactly once. For example, the following arrays are permutations:[3,1,2][3,1,2],[1][1],[1,...原创 2019-03-22 08:34:18 · 469 阅读 · 0 评论 -
C. Edgy Trees(并查集+数学)
You are given a tree (a connected undirected graph without cycles) ofnnvertices. Each of then−1n−1edges of the tree is colored in either black or red.You are also given an integerkk. Consider s...原创 2019-03-22 07:42:41 · 358 阅读 · 0 评论 -
L2-022 重排链表 (25 分)(简单模拟)
给定一个单链表L1→L2→⋯→Ln−1→Ln,请编写程序将链表重新排列为Ln→L1→Ln−1→L2→⋯。例如:给定L为1→2→3→4→5→6,则输出应该为6→1→5→2→4→3。输入格式:每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址和结点总个数,即正整数N(≤105)。结点的地址是5位非负整数,NULL地址用−...原创 2019-03-21 23:33:13 · 1059 阅读 · 1 评论 -
L2-020 功夫传人 (25 分)(DFS加vector)
一门武功能否传承久远并被发扬光大,是要看缘分的。一般来说,师傅传授给徒弟的武功总要打个折扣,于是越往后传,弟子们的功夫就越弱…… 直到某一支的某一代突然出现一个天分特别高的弟子(或者是吃到了灵丹、挖到了特别的秘笈),会将功夫的威力一下子放大N倍 —— 我们称这种弟子为“得道者”。这里我们来考察某一位祖师爷门下的徒子徒孙家谱:假设家谱中的每个人只有1位师傅(除了祖师爷没有师傅);每位师傅可以带很...原创 2019-03-21 23:04:55 · 118 阅读 · 0 评论 -
L1-043 阅览室 (20 分)
天梯图书阅览室请你编写一个简单的图书借阅统计程序。当读者借书时,管理员输入书号并按下S键,程序开始计时;当读者还书时,管理员输入书号并按下E键,程序结束计时。书号为不超过1000的正整数。当管理员将0作为书号输入时,表示一天工作结束,你的程序应输出当天的读者借书次数和平均阅读时间。注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有S没有E,或者只有E没有S的纪录,系统应能自动忽略这种无效...原创 2019-03-15 16:51:15 · 132 阅读 · 0 评论 -
C - 盐水的故事(10) (类型技巧)
挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?Input输入数据包含多个测试实例,每个实例占一行,由VUL和D组成,其中 0<D<VUL<5000。...原创 2019-03-14 23:27:32 · 482 阅读 · 0 评论 -
F - Candle Box (思维)
题意:姐姐从4岁开始放蜡烛,并且每年放的个数为岁数大小,而弟弟从3岁开始。给出姐姐和弟弟的年龄差距,姐姐的蜡烛个数,弟弟的蜡烛个数。由于弟弟把一些蜡烛放入了姐姐的盒子里,要求输出姐姐需要拿走多少蜡烛才能获得正确的蜡烛个数。感受:打比赛时思维不清晰,导致思维定势,只认为一年只放1个,怎么想也想不对。所以以后思维要更加活跃。#include<iostream>using nam...原创 2019-03-06 08:27:17 · 280 阅读 · 0 评论 -
D - Fourth Point !! (思维,求平行四边形第4点)
题意:给出两条边的起止点,注意顺序可不同,给出的4个点占据了3个点,即4个点有2个是一样的,根据信息求出第4个点的坐标。题解:由于起止点不知,所以可考虑所有情况,找出一种情况的解决办法,再将其他情况通过交换点的坐标来得到一般情况的解。#include<iostream>#include<iomanip>using namespace std;struct p...原创 2019-03-06 07:59:03 · 483 阅读 · 0 评论 -
B - Decode the Mad man (思维)
Once in BUET, an old professor had gone completely mad. He started talking with some peculiarwords. Nobody could realize his speech and lectures. Finally the BUET authority fall in great trouble.There...原创 2019-03-05 23:04:39 · 173 阅读 · 0 评论 -
1353. Milliard Vasya's Function
Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as ...原创 2019-03-02 00:30:57 · 115 阅读 · 0 评论 -
F. Asya And Kittens(并查集)
Asya loves animals very much. Recently, she purchasednnkittens, enumerated them from11andnnand then put them into the cage. The cage consists of one row ofnncells, enumerated with integers fro...原创 2019-03-01 23:34:38 · 396 阅读 · 0 评论