uva 10104 Euclid Problem (数论-扩展欧几里德)
题目大意:
已知 A 和 B , 问你 A*X+B*Y=GCD(A,B)的 X,Y解。
解题思路:
非常裸的拓展欧几里德算法。
拓展欧几里德算法证明过程:
因为 B*X1+A%B*Y1=GCD(B,A%B) =GCD(A,B)=A*X+B*Y
所以 B*X1+(A-A/B*B)*Y1=A*X+B*Y
A*Y1+B*(X1-A/B*Y1)=A*X+B*Y
于是: X=Y1,Y=(X1-A/B*Y1)
因此,得出( A*...
分类:
其他好文 时间:
2014-05-26 05:53:55
阅读次数:
297
月老的难题
时间限制:1000 ms | 内存限制:65535 KB
难度:4
描述
月老准备给n个女孩与n个男孩牵红线,成就一对对美好的姻缘。
现在,由于一些原因,部分男孩与女孩可能结成幸福的一家,部分可能不会结成幸福的家庭。
现在已知哪些男孩与哪些女孩如果结婚的话,可以结成幸福的家庭,月老准备促成尽可能多的幸福家庭,请你帮他找出最多可能促成的幸福...
分类:
其他好文 时间:
2014-05-26 04:43:20
阅读次数:
230
【题目】
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number of distinct solutions.
【题意】
解N皇后问题,N-Queens要求返回所有的解,而本题只需要返回可行解的数目
【思路】
DFS,参考N-Queens...
分类:
其他好文 时间:
2014-05-25 01:51:55
阅读次数:
236
http://poj.org/problem?id=2449
大致题意:给出一个有向图,求从起点到终点的第K短路。
K短路A*算法讲解:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long...
分类:
其他好文 时间:
2014-05-24 23:39:47
阅读次数:
352
题目如下:
Problem D: Hartals
A social research organization has determined a simple set of parameters to simulate the behavior of the political parties of our country. One of the ...
分类:
其他好文 时间:
2014-05-24 23:10:01
阅读次数:
317
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7748 Accepted Submission(s): 5238
Problem Description
People in Silverl...
分类:
其他好文 时间:
2014-05-24 21:06:18
阅读次数:
220
http://poj.org/problem?id=3013
题意:
Because of a technical difficulty, price of an edge will be (sum of weights of all descendant nodes) × (unit price of the edge).这句话一直没看懂。后面还以为是最小生成树。
正确...
分类:
其他好文 时间:
2014-05-24 20:27:13
阅读次数:
266
整数划分(三)
时间限制:1000 ms | 内存限制:65535 KB
难度:5
描述
整数划分是一个经典的问题。请写一个程序,完成以下要求。
输入每组输入是两个整数n和k。(1
输出对于输入的 n,k;
第一行: 将n划分成若干正整数之和的划分数。
第二行: 将n划分成k个正整数之和的划分数。
第三行: 将n划分成最大数...
分类:
其他好文 时间:
2014-05-24 18:20:36
阅读次数:
242
Xor Sum
Problem Description
Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大。Prometheus 为了让 Zeu...
分类:
其他好文 时间:
2014-05-24 17:53:54
阅读次数:
177
【题目】
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuratio...
分类:
其他好文 时间:
2014-05-24 17:12:32
阅读次数:
237