主题如以下: Don't Get Rooked In chess, the rook is a piece that can move any number of squaresvertically or horizontally. In this problem we will consider smallchess boards (at most 44) that can also contain walls through whichrooks cannot move. The goa…
Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all…
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: #include <stdio.h> #include <string.h> long long a, p; long long pow_mod(long long x, long long k, long long mod) { long long ans = 1; while (k…
UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,例如以下: We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cel…
题目例如以下: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that thecountry will be split into up to k separate parts on her death andeach part will be inherited by whoever performs best at some test. Itis possible for an…
UVA 1397 - The Teacher's Side of Math 题目链接 题意:给定一个x=a1/m+b1/n.求原方程组 思路:因为m*n最多20,全部最高项仅仅有20.然后能够把每一个此项拆分.之后得到n种不同无理数,每一项为0.就能够设系数为变元.构造方程进行高斯消元 一開始用longlong爆了.换成分数写法也爆了,又不想改高精度.最后是机智的用了double型过的,只是用double精度问题,所以高斯消元的姿势要正确,而且最后输出要注意-0的情况 代码: #include…
题目链接:1484 - Alice and Bob's Trip 题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,可是有个条件,就是路径权值总和必须在[L,R]之间,求终于这条路径的权值. 思路:树形dp,dp[u]表示在u结点的权值,往下dfs的时候顺带记录下到根节点的权值总和,然后假设dp[v] + w + sum 在[l,r]内,就是能够的,状态转移方程为 dp[u] = max{dp[v] + w }(bob) dp[u] = m…
Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time Limit: 5 seconds Memory Limit: 32 MB You are given a collection of books, which must be shelved in a library bookcase ordered (from top to bottom in t…
这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include <stdlib.h> int vis[100][100];//刚開始wrong的原因就是这里数组开小了,开了[8][8],以为可以.后来看到[cur-i+8]意识到可能数组开小了.改大之后AC. int a[8][8]; int C[10]; int max_,tot; void search_(int…
Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the lines trisecting the angles of an arbitrary plane triangle meet at the vertices of an equilateral triangle. For example in the figure below…
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his book…
称号:给你一个行长度的建设和高度,我们祈求最长的和下降的高度. 分析:dp,最大上升子. 说明:具有长度,不能直接优化队列单调. #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int h[2000],w[2000],u[2000],l[2000]; int main() { int T,n; while (~scanf("%d",&T…
Rip Van Winkle was fed up with everything except programming. One day he found a problem whichrequired to perform three types of update operations (A, B, C), and one query operation S over an arraydata[]. Initially all elements of data are equal to 0…
Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each ith job, it is known the integer Ti (1<=Ti<=1000), the time in days it takes the shoemaker to finish the jo…