算法
%。濤&%
这个作者很懒,什么都没留下…
展开
-
Best cow line(贪心)
Best cow lineFJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds them past the judges.T...原创 2019-08-03 11:21:29 · 175 阅读 · 0 评论 -
Ultra-QuickSort (树状数组)
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted i...原创 2019-08-16 16:17:22 · 236 阅读 · 0 评论 -
Wormholes (最短路)
While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that i...原创 2019-08-21 21:33:07 · 265 阅读 · 0 评论 -
Stars (树状数组)
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and ...原创 2019-08-17 11:51:43 · 269 阅读 · 0 评论 -
Silver Cow Party (最短路)
One cow from each ofNfarms (1 ≤N≤ 1000) conveniently numbered 1..Nis going to attend the big cow party to be held at farm #X(1 ≤X≤N). A total ofM(1 ≤M≤ 100,000) unidirectional (one-way roa...原创 2019-08-22 10:38:10 · 261 阅读 · 0 评论 -
Save your cats (最小生成树)
Problem C:Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them.One day, an evil witch...原创 2019-08-22 11:08:51 · 281 阅读 · 0 评论 -
Agri-Net (最小生成树)
Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high spee...原创 2019-08-22 16:57:40 · 232 阅读 · 0 评论 -
Bad Cowtractors (最小生成树)
Bessie has been hired to build a cheap internet network among Farmer John's N (2 <= N <= 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found M (1 <...原创 2019-08-22 17:18:50 · 194 阅读 · 0 评论 -
Carmichael Numbers (素数)
An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without...原创 2019-08-22 18:02:39 · 295 阅读 · 0 评论 -
Prime Path (素数)
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices.— It is a matter of se...原创 2019-08-22 18:08:40 · 174 阅读 · 0 评论 -
Pseudoprime numbers (快速幂)
Fermat's theorem states that for any prime numberpand for any integera> 1,ap=a(modp). That is, if we raiseato thepthpower and divide byp, the remainder isa. Some (but not very many) ...原创 2019-08-22 21:09:50 · 218 阅读 · 0 评论 -
算法总结(三)
然后下面是最短路的算法目录最短路最小生成树素数快速幂最短路最短路是从最小的一个点出发,不断地与其相连的最小的点合并直到所有点合并完成为止的一个算法。其代码是:int floyd(int x){ int i,j,k; for(k=0;k<=x;k++) { for(i=0;i<=x;i++) ...原创 2019-08-28 16:54:52 · 63 阅读 · 0 评论 -
算法总结(一)
在学校暑训了一个月,期间学到了几种算法。每种算法都有固定的模板,只要学会了模板,就可以参照模板来解决相应的问题。目录贪心深搜贪心首先是贪心算法,需要用到sort这个函数,如果要用sort函数,必须调用algorithm这个包才能使用sort函数。#include <iostream>#include <stdio.h>#include <...原创 2019-08-28 16:54:27 · 71 阅读 · 0 评论 -
How Many Tables (并查集)
Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, a...原创 2019-08-12 18:05:07 · 183 阅读 · 0 评论 -
小希的迷宫 (并查集)
上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头路)。小希现在把她的设计图给你,让你帮忙判断她的...原创 2019-08-16 11:33:26 · 126 阅读 · 0 评论 -
Six Degrees of Cowvin Bacon (最短路)
The cows have been making movies lately, so they are ready to play a variant of the famous game "Six Degrees of Kevin Bacon".The game works like this: each cow is considered to be zero degrees of se...原创 2019-08-20 21:13:51 · 389 阅读 · 0 评论 -
Cleaning Shifts(贪心)
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 i...原创 2019-08-04 11:59:10 · 205 阅读 · 0 评论 -
Stripies (贪心)
Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian - polosatiki, but the scientists had to invent an English name to apply...转载 2019-08-04 18:14:38 · 213 阅读 · 0 评论 -
Red and Black (深搜)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can'...原创 2019-08-05 10:57:45 · 146 阅读 · 0 评论 -
Property Distribution (深搜)
タナカ氏がHWアールの果樹園を残して亡くなりました。果樹園は東西南北方向にH × Wの区画に分けられ、区画ごとにリンゴ、カキ、ミカンが植えられています。タナカ氏はこんな遺言を残していました。果樹園は区画単位でできるだけ多くの血縁者に分けること。ただし、ある区画の東西南北どれかの方向にとなりあう区画に同じ種類の果物が植えられていた場合は、区画の境界が分からないのでそれらは 1 つの大きな...原创 2019-08-05 11:59:40 · 232 阅读 · 0 评论 -
Lake Counting (深搜)
Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains ei...原创 2019-08-06 11:53:12 · 138 阅读 · 0 评论 -
Cow Bowling (动态规划)
The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this: 7 ...原创 2019-08-07 10:28:03 · 198 阅读 · 0 评论 -
Sumsets (动态规划)
Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that ...原创 2019-08-07 11:56:23 · 187 阅读 · 0 评论 -
Wireless Network (并查集)
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n...原创 2019-08-14 11:29:24 · 239 阅读 · 0 评论 -
敌兵布阵 (树状树状)
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所...原创 2019-08-09 21:22:48 · 251 阅读 · 0 评论 -
How Many Answers Are Wrong (并查集)
TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should ...原创 2019-08-14 12:12:16 · 179 阅读 · 0 评论 -
Convenient Location (最短路)
便利な町来春卒業するAさんは、就職を機に引越しをすることにしました。就職する会社は、オフィスがいくつかの町にあって、日によって出勤するオフィスが違います。そこでAさんは,どこのオフィスに 行くにも時間の短い町に住もうと考えました。そこであなたは、Aさんを助けるため、住むのに一番便利な町を探すことになりました。町には 0 から始まる番号が振られており、町と町の間には道があります...原创 2019-08-20 11:51:45 · 834 阅读 · 0 评论 -
Connections in Galaxy War (并查集)
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...原创 2019-08-15 17:57:37 · 128 阅读 · 0 评论 -
算法总结(二)
继上面的深搜之后,然后就到了动态规划了。目录动态规划树状数组并查集动态规划动态规划是从小的问题出发,然后再选择较优的选项,如此类推。直到数据结束为止。下面的代码就是运用了动态规划的思想来写的for(int i=n-2;i>=0;i--) { for(int j=0;j<=i;j++) { ...原创 2019-08-28 16:55:23 · 74 阅读 · 0 评论