ACM大一
文章平均质量分 77
白黑菜
小白
展开
-
树的重心 poj-1655
紫书上的方法树的很明确,这里列举了一道例题,还有对这种类型的题目更高深的一些问题。首先,是poj-1655的一道裸题,也是入门类型的。#include#include#include#include#includeusing namespace std;int n;vector son[20010];int val[20010];int sum[20010];void原创 2017-09-06 18:10:06 · 342 阅读 · 0 评论 -
POJ-3186 Treats for the Cows
FJ has purchased N (1 The treats are interesting for many reasons:The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ ca原创 2017-06-13 17:19:05 · 191 阅读 · 0 评论 -
Hard problem CodeForces - 706C (DP)
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.Vasiliy is given n strings consisting of lowercase English letters. He wants th原创 2017-07-04 22:46:00 · 295 阅读 · 0 评论 -
拓扑排序的原理及其实现
收藏了一下大神的教导:大神博客转载 2017-07-05 07:36:35 · 217 阅读 · 0 评论 -
Gym Class HDU - 5695
众所周知,度度熊喜欢各类体育活动。 今天,它终于当上了梦寐以求的体育课老师。第一次课上,它发现一个有趣的事情。在上课之前,所有同学要排成一列, 假设最开始每个人有一个唯一的ID,从1到NN,在排好队之后,每个同学会找出包括自己在内的前方所有同学的最小ID,作为自己评价这堂课的分数。麻烦的是,有一些同学不希望某个(些)同学排在他(她)前面,在满足这个前提的情况下,新晋体育课老师——度度熊,希原创 2017-07-05 09:00:18 · 247 阅读 · 0 评论 -
The Meeting Place Cannot Be Changed CodeForces - 782B (二分时间)
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road原创 2017-07-05 10:21:58 · 270 阅读 · 0 评论 -
C. Okabe and Boxes
C. Okabe and Boxestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOkabe and Super Hacker Daru are stacking and remov原创 2017-06-26 18:21:50 · 688 阅读 · 1 评论 -
HDU-1078 FatMouse and Cheese
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmo原创 2017-06-27 09:28:11 · 217 阅读 · 0 评论 -
Alice and Bob HDU - 4268
Alice and Bob's game never ends. Today, they introduce a new game. In this game, both of them have N different rectangular cards respectively. Alice wants to use his cards to cover Bob's. The card A c原创 2017-07-06 08:42:41 · 618 阅读 · 0 评论 -
HDU-1789 Doing Homework again
一道贪心题目,没感觉出来哪里是DP。Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands原创 2017-06-13 15:50:54 · 192 阅读 · 0 评论 -
STL----lower_bound和upper_bound算法
首先要了解一下两种的区别:如上很清晰了:两种算法的实现只差了一个符号。嘿嘿。 所以很好记。上代码:首先时lower_bound的原理:int erfen(int x) // x 为查找的元素, 在d数组中查找x{ int left = 0; // 初始位置 int right = len; // 数组长度 while(left < righ原创 2017-06-11 22:40:35 · 358 阅读 · 0 评论 -
最长上升子序列问题(LIS)
最长上升子序列的问题解法有两种,方法一是很好理解的dp,方法二则类似于二分,下面两种都来解释一下。方法一:(动态规划)dp(i)表示以i结尾的最长上升子序列的长度。那么很好写出递推方程。详见代码。#include#include#include#includeusing namespace std;int dp[1010];int a[1010];int len;原创 2017-06-11 22:27:35 · 232 阅读 · 0 评论 -
钱币兑换问题 HDU - 1284
Problem Description在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。Input每行只有一个正整数N,N小于32768。Output对应每个输入,输出兑换方法数。Sample Input293412553Sampl转载 2017-07-03 16:08:40 · 516 阅读 · 0 评论 -
A == B ? HDU - 2054
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".Inputeach test case contains two numbers A and B. Outputfor each case, if A is equal to B, you should pr原创 2017-07-03 18:14:02 · 247 阅读 · 0 评论 -
Cleaning Shifts POJ - 2376
Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into T原创 2017-07-03 23:09:47 · 302 阅读 · 0 评论 -
Tempter of the Bone HDU - 1010 (奇偶性剪枝)
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone原创 2017-07-04 12:12:31 · 346 阅读 · 0 评论 -
Triangle HDU - 5914 (斐波那契数列的应用1123)
Mr. Frog has n sticks, whose lengths are 1,2, 3⋯⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks!原创 2017-07-04 12:20:05 · 338 阅读 · 0 评论 -
poj 1661 Help Jimmy-dp 动态规划
"Help Jimmy" 是在下图所示的场景上完成的游戏。 场景中包括多个长度和高度各不相同的平台。地面是最低的平台,高度为零,长度无限。 Jimmy老鼠在时刻0从高于所有平台的某处开始下落,它的下落速度始终为1米/秒。当Jimmy落到某个平台上时,游戏者选择让它向左还是向右跑,它跑动的速度也是1米/秒。当Jimmy跑到平台的边缘时,开始继续下落。Jimmy每次下落的高度不能超原创 2017-06-25 19:15:38 · 159 阅读 · 0 评论 -
The Frog's Games HDU - 4004 (二分)
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over th原创 2017-07-06 10:48:48 · 285 阅读 · 0 评论 -
关于memset初始化填充数组。
#include #include using namespace std;int a[10];int main(){ memset(a, 0x01, sizeof(a)); for(int i = 0; i < 10; i++) printf("%d ", a[i]); puts(""); printf("res = %d\n", (1<<24) + (1<<原创 2017-06-15 17:57:44 · 556 阅读 · 0 评论 -
Brackets sequence UVA - 1626(区间dp)
紫书278页的题目,纪念一下坑比的输入格式,实在是无语了;#include#include#include#includeusing namespace std;const int maxn = 100 + 5;char S[maxn];int n, d[maxn][maxn];bool match(char a, char b) { return (a == '('原创 2017-08-09 00:19:04 · 278 阅读 · 0 评论 -
Little Tiger vs. Deep Monkey HDU - 4815 (dp)
A crowd of little animals is visiting a mysterious laboratory – The Deep Lab of SYSU. “Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recognition原创 2017-08-09 22:18:40 · 472 阅读 · 0 评论 -
Faucet Flow UVA - 10366
主要就是模拟这题,实在是比较坑,个人代码写的很长,很无奈。大体要分情况讨论:1: 确定最终从哪一边流出,也就是先确定左边最高的板子和右边最高的板子哪一个更高。 如果相同高度的话就是左右两边都可能流出,那就取时间最短的那个。2:还有很多小细节,这个要自己做的时候慢慢想,做这种题还是很考验耐心的,因为没有什么算法,这也就不赘述了,具体过程还是自己慢慢体会吧。留个纪念,纪念这个坑原创 2017-08-17 14:51:24 · 297 阅读 · 0 评论 -
Connect them ZOJ - 3204 (最小生成树)
You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers i and j is the same as connec原创 2017-08-05 19:07:34 · 231 阅读 · 0 评论 -
Dream City ZOJ - 3211 (动态规划)
JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are ntrees in the yard. Let's call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins on it (i=1,原创 2017-08-05 19:19:03 · 479 阅读 · 0 评论 -
C. Journey(dfs求期望+Codeforces Round #428 (Div. 2))
C. Journeytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities and n - 1 roads in the Seven Kingdoms,原创 2017-08-14 12:51:58 · 445 阅读 · 0 评论 -
C - Keine's Problem OpenJ_POJ - 1039
In Gensokyo, Keine is a teacher in Human Village. Since there are many naughty students in her class, Keine keeps a log of all in/out behaviors of all students, in chronological order.Following is a原创 2017-08-14 21:53:55 · 237 阅读 · 0 评论 -
Game of the Rows CodeForces - 839B
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recen原创 2017-08-16 00:31:45 · 359 阅读 · 1 评论 -
Disk Schedule HDU - 4824 (双调欧几里得旅行商问题)
有很多从磁盘读取数据的需求,包括顺序读取、随机读取。为了提高效率,需要人为安排磁盘读取。然而,在现实中,这种做法很复杂。我们考虑一个相对简单的场景。 磁盘有许多轨道,每个轨道有许多扇区,用于存储数据。当我们想在特定扇区来读取数据时,磁头需要跳转到特定的轨道、具体扇区进行读取操作。为了简单,我们假设磁头可以在某个轨道顺时针或逆时针匀速旋转,旋转一周的时间是360个单位时间。磁头也可以随意移动到某原创 2017-08-08 21:40:04 · 251 阅读 · 0 评论 -
Labyrinth HDU - 4826 (dp)
度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,且只能向上向下向右走以前没有走过的格子,每一个格子中都有一些金币(或正或负,有可能遇到强盗拦路抢劫, 度度熊身上金币可以为负,需要给强盗写欠条),度度熊刚开始时身上金币数为0,问度度熊走出迷宫时候身上最多有多少金币? Input原创 2017-08-08 13:31:24 · 227 阅读 · 0 评论 -
B. Mister B and Angle in Polygon 421.div2
B. Mister B and Angle in Polygontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOn one quiet day all of sudden Miste原创 2017-06-28 07:23:01 · 947 阅读 · 2 评论 -
Queue CodeForces - 141C
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many原创 2017-07-07 08:42:07 · 667 阅读 · 0 评论 -
Connections in Galaxy War ZOJ - 3261
In order to strengthen the defense ability, many stars in galaxy allied together and built many bidirectional tunnels to exchange messages. However, when the Galaxy War began, some tunnels were destro原创 2017-07-16 19:42:17 · 338 阅读 · 0 评论 -
Magic Powder - 2 CodeForces - 670D2(二分)
The term of this problem is the same as the previous one, the only exception — increased restrictions.InputThe first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109原创 2017-07-18 10:13:50 · 368 阅读 · 0 评论 -
Color Length UVA - 1625
紫书上的题目,讲解的很清楚,附代,以后要仔细思考.#include#include#include#includeusing namespace std;int c[5010][5010];int dp[5010][5010];char s1[5010];char s2[5010];int p[5010];int q[5010];int py[5010];int qy[原创 2017-07-09 10:05:51 · 303 阅读 · 0 评论 -
Coprime Sequence HDU - 6025
Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, and the GCD (Greatest Common Divisor) of them is equal to 1. ``Coprime Sequence'' is easy to fi原创 2017-07-09 12:16:12 · 351 阅读 · 0 评论 -
New Year and Old Property CodeForces - 611B
The year 2015 is almost over.Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary s原创 2017-07-09 16:23:40 · 218 阅读 · 0 评论 -
Codeforces Round #245 (Div. 1) -- B. Working out (DP)
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and mcolumns. Let number a[i][j] represen原创 2017-07-21 22:41:01 · 393 阅读 · 0 评论 -
Coach CodeForces - 300B
A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive.Before the university programming championship the原创 2017-07-02 19:54:02 · 500 阅读 · 0 评论 -
Lucky Permutation Triple CodeForces - 303A
Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of l原创 2017-07-02 17:29:04 · 551 阅读 · 0 评论