- 博客(42)
- 收藏
- 关注
原创 KM算法模板
KM算法是用来求完全二分图最大完美匹配的算法,其原理是不断寻找增广路(增广路定理)。相关性质:在最大二分图匹配图中,W[x][y] <= Lx[x] + Ly[y]。#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <...
2018-02-17 17:02:17
197
原创 2-SAT模板
2-SAT是指可以将问题看作多个布尔表达式同时成立的问题。 如 x | y 为真,则 !x & !y 为假,由此可以推导出 !x -> y,以及 !y -> x ,也就是当x为假时,必须让y为真,当y为假时,必须让x为真。这样可以将此问题形象化为一个图论问题。 &...
2018-02-14 14:45:18
285
原创 后缀数组模板
倍增算法(DA)倍增算法的时间复杂度为O(nlogn),利用倍增思想给字符串所有后缀进行排序,用于解决字符串处理问题。变量解释:sa[i] 排名为i的后缀是以下标为sa[i]开头的字符串(以下简称后缀) rnk[i] 后缀i的排名为rnk[i] hei[i] sa[i-1]和sa[i]的最长公共前缀(连续)的长度相关性质:1.rnk...
2018-02-09 22:01:55
168
原创 Codeforces-535B Tavas and SaDDas
The problem is: You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky
2017-05-06 20:01:57
482
原创 HDU-1242 Rescue
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel’s friends want to save
2017-05-06 14:44:26
224
原创 UVA-11078 Open Credit System
In an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of such a course has found quite
2017-05-05 18:45:54
324
原创 UVA-548 Trees
You are to determine the value of the leaf node in a given binary tree that is the terminal node of a path of least value from the root of the binary tree to any leaf. The value of a path is the sum of
2017-03-25 22:05:47
279
原创 UVA-839 Not so Mobile
Before being an ubiquous communications gadget, a mobile was just a structure made of strings and wires suspending colourfull things. This kind of mobile is usually found hanging over cradles of small
2017-03-25 15:33:02
300
原创 UVA-679 Dropping Balls
A number of K balls are dropped one by one from the root of a fully binary tree structure FBT. Each time the ball being dropped first visits a non-terminal node. It then keeps moving down, either follo
2017-03-23 21:41:27
241
原创 UVA-514 Rails
There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to es
2017-03-22 20:47:55
200
原创 UVA-11988 Broken Keyboard (a.k.a. Beiju Text)
You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed (interna
2017-03-22 20:41:06
200
原创 UVA-136 Ugly Numbers
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … shows the first 11 ugly numbers. By convention, 1 is included. Write a program to
2017-03-19 12:24:16
372
原创 蓝桥杯-猜算式
请你观察如下的乘法算式 星号代表某位数字,注意这些星号中, 0~9中的每个数字都恰好用了2次。 (如因字体而产生对齐问题,请参看图p1.jpg)请写出这个式子最终计算的结果,就是那个5位数是多少?注意:只需要填写一个整数,不要填写任何多余的内容。比如说明文字。分析:dfs简单题,注意剪枝。我的这个程序大概花了2分钟算出答案。Source:#include<cstdio>#include<st
2017-03-18 22:50:15
386
原创 UVA-540 Team Queue
Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the que
2017-03-18 22:42:46
228
原创 UVA-12096 The SetStack Computer
Background from Wikipedia: “Set theory is a branch of mathematics created principally by the German mathematician Georg Cantor at the end of the 19th century. Initially controversial, set theory has co
2017-03-18 18:34:16
208
原创 UVA-156 Ananagrams
Most crossword puzzle fans are used to anagrams — groups of words with the same letters in different orders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute,
2017-03-16 21:25:49
174
原创 UVA-101 The Blocks Problem
Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a rob
2017-03-14 21:18:32
198
原创 蓝桥杯-凑算式
凑算式 (如果显示有问题,可以参见【图1.jpg】) 这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。比如: 6+8/3+952/714 就是一种解法, 5+3/1+972/486 是另一种解法。这个算式一共有多少种解法?注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字。分析:dfs暴力法,简单题。Source:#include<cstdio>using names
2017-03-13 20:09:47
317
原创 蓝桥杯-寒假作业
现在小学的数学题目也不是那么好玩的。 看看这个寒假作业:□ + □ = □ □ - □ = □ □ × □ = □ □ ÷ □ = □(如果显示不出来,可以参见【图1.jpg】) 每个方块代表1~13中的某一个数字,但不能重复。 比如: 6 + 7 = 13 9 - 8 = 1 3 * 4 = 12 10 / 2 = 5以及: 7 +
2017-03-13 19:52:05
483
原创 UVA-10474 Where is the marble?
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers
2017-03-13 19:12:41
186
原创 UVA-129 Krypton Factor
You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physical abilities. In one section of the contest the contestants are tested on
2017-03-11 20:50:08
262
原创 UVA-524 Prime Ring Problem
A ring is composed of n (even number) circles as shown in diagram. Put natural numbers 1,2,…,n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the
2017-03-10 19:34:10
209
原创 UVA-10976 Fractions Again?!
It is easy to see that for every fraction in the form 1 k (k > 0), we can always find two positive integers x and y, x ≥ y, such that: 1 /k = 1/ x + 1/ y Now our question is: can you write a program
2017-03-07 21:52:17
226
原创 UVA-11059 Maximum Product
Given a sequence of integers S = {S1,S2,…,Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S. If you cannot find a positive sequence, you should
2017-03-07 21:45:01
304
原创 UVA-725 Division
Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, w
2017-03-07 21:37:34
288
原创 UVA-133 The Dole Queue
In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every day all dole applicants will be placed in a large c
2017-03-04 17:16:05
214
原创 UVA-489 Hangman Judge
In “Hangman Judge,” you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of
2017-03-04 15:35:26
203
原创 UVA-1588 Kickdown
原题网址分析:分别将两个字符串不断右移,找出移动次数最少的答案。Source:#include<stdio.h>#include<string.h>#define MAX 110int main(){ char s1[MAX],s2[MAX]; int i,j,k,l1,l2,ans1,ans2; while(scanf("%s%s",s1,s2)!=EOF)
2017-03-04 13:58:37
286
原创 UVA-1587 Box
Ivan works at a factory that produces heavy machinery. He has a simple job — he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular paral
2017-03-04 13:15:58
254
原创 UVA-11889 Benefit
Recently Yaghoub is playing a new trick to sell some more. When somebody gives him A Tomans, he who never has appropriate changes, asks for B Tomans such that lowest common multiple of A and B equals t
2017-02-26 21:49:00
247
原创 UVA-455 Periodic Strings
A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, the string ”abcabcabcabc” has period 3, since it is
2017-02-26 20:19:05
129
原创 UVA-1225 Digit Counting
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 < N < 10000). After that, he counts the number of
2017-02-26 19:36:57
225
原创 UVA-1586 Molar Mass
原题网址分析:简单题,对字符串判断与操作。Source:#include<stdio.h>#include<string.h>int main(){ double saw[4]={12.01,1.008,16.00,14.01},sum; int num[4]={0,0,0,0}; int i,k,l,t,c; char s[80]; scanf("%d
2017-02-26 17:35:19
275
原创 UVA-1585 Score
There is an objective test result such as “OOXXOXXOOO”. An ‘O’ means a correct answer of a problem and an ‘X’ means a wrong answer. The score of each problem of this test is calculated by itself and it
2017-02-26 15:33:56
200
原创 UVA-1584 Circular Sequence
Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequence “CGAGTCAGCT”, that is, the last symbol “T” in “CGAGTCAGCT” is connected to the first symbol “C”. We
2017-02-26 15:13:53
305
原创 UVA-1583 Digit Genarator
For a positive integer N, the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N, we call N a generator of M. For example, the digit-sum of 245 is 256 (= 245 +
2017-02-25 22:00:45
245
原创 UVA-401 Palindromes
原题网址分析:根据题意,本题需要两个函数is_palidrome()和is_mirrored()来判断字符串。判断是否镜像时,使用两个字符串,其中元素一一对应。Source:#include<stdio.h>#include<string.h>int is_palindrome(char *s){ int i,l=strlen(s); for(i=0;i<=l-i;i++)
2017-02-25 21:02:38
193
原创 UVA-272 TEX Quotes
原题网址 分析:简单的字符串操作。Source:#include<stdio.h>int main(){ char c,i,k=0; while((c=getchar())!=EOF) { if(c=='"') { k++; if(k%2) printf("`
2017-02-25 19:19:54
367
原创 UVA-11609 Teams
In a galaxy far far away there is an ancient game played among the planets. The specialty of the game is that there is no limitation on the number of players in each team, as long as there is a captain
2017-02-25 16:44:32
535
原创 UVA-10892 LCM Cardinality
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the numb
2017-02-25 11:30:00
457
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人