随笔分类 -  ACM-数学

摘要:Beef McNuggetsHubert ChenFarmer Brown's cows are up in arms, having heard that McDonalds is considering the introduction of a new product: Beef McNuggets. The cows are trying to find any possible way to put such a product in a negative light.One strategy the cows are pursuing is that of `inferio 阅读全文
posted @ 2012-09-26 14:17 mtry 阅读(922) 评论(0) 推荐(0) 编辑
摘要:Closed FencesA closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 < N < 200). The corners or vertices are each distinct and are listed in counter-clockwise order in an array {xi, yi}, i in (1..N).Every pair of adjacent vertices defines a side of the f 阅读全文
posted @ 2012-09-21 09:43 mtry 阅读(675) 评论(0) 推荐(0) 编辑
摘要:Electric FenceDon PieleIn this problem, `lattice points' in the plane are points with integer coordinates.In order to contain his cows, Farmer John constructs a triangular electric fence by stringing a "hot" wire from the origin (0,0) to a lattice point [n,m] (0<=;n<32000, 0<m 阅读全文
posted @ 2012-09-19 13:01 mtry 阅读(359) 评论(1) 推荐(0) 编辑
摘要:Feed Ratios1998 ACM Finals, Dan AdkinsFarmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of these easily mixable grains, he can not buy that mixture! He buys three other mixtures of the three grains 阅读全文
posted @ 2012-09-13 18:37 mtry 阅读(442) 评论(0) 推荐(0) 编辑
摘要:FactorialsThe factorial of an integer N, written N!, is the product of all the integers from 1 through N inclusive. The factorial quickly becomes very large: 13! is too large to store in a 32-bit integer on most computers, and 70! is too large for most floating-point variables. Your task is to find 阅读全文
posted @ 2012-09-13 14:22 mtry 阅读(335) 评论(0) 推荐(0) 编辑
摘要:Prime PalindromesThe number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b (5 <= a < b <= 100,000,000); both a a 阅读全文
posted @ 2012-08-29 21:20 mtry 阅读(1026) 评论(0) 推荐(0) 编辑
摘要:Big NumberTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14952Accepted Submission(s): 6631Problem DescriptionIn many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, 阅读全文
posted @ 2012-05-07 15:01 mtry 阅读(1953) 评论(0) 推荐(0) 编辑
摘要:Hat's FibonacciTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3442Accepted Submission(s): 1169Problem DescriptionA Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.F(1) = 阅读全文
posted @ 2012-05-07 11:37 mtry 阅读(810) 评论(0) 推荐(0) 编辑
摘要:A + B Problem IITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 111273Accepted Submission(s): 21079Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of 阅读全文
posted @ 2012-05-07 09:44 mtry 阅读(2351) 评论(0) 推荐(0) 编辑
摘要:前缀式计算时间限制:1000 ms | 内存限制:65535 KB难度:3描述先说明一下什么是中缀式:如2+(3+4)*5这种我们最常见的式子就是中缀式。而把中缀式按运算顺序加上括号就是:(2+((3+4)*5))然后把运算符写到括号前面就是+(2 *( +(3 4) 5) )把括号去掉就是:+ 2 * + 3 4 5最后这个式子就是该表达式的前缀表示。给你一个前缀表达式,请你计算出该前缀式的值。比如:+ 2 * + 3 4 5的值就是 37输入有多组测试数据,每组测试数据占一行,任意两个操作符之间,任意两个操作数之间,操作数与操作符之间都有一个空格。输入的两个操作数可能是小数,数据保证输入的 阅读全文
posted @ 2012-04-16 14:11 mtry 阅读(1884) 评论(0) 推荐(0) 编辑
摘要:Humble NumbersTime Limit: 2 Seconds Memory Limit: 65536 KBA number whose only prime factors are 2,3,5 or 7 is called a humblenumber. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.Write a program to find and print the nth el. 阅读全文
posted @ 2012-04-10 23:04 mtry 阅读(287) 评论(0) 推荐(0) 编辑
摘要:LottoTime Limit: 2 Seconds Memory Limit: 65536 KBIn a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to select a subset S containing k (k>6) of these 49 numbers, and t 阅读全文
posted @ 2012-04-10 21:10 mtry 阅读(641) 评论(0) 推荐(0) 编辑
摘要:NimTime Limit: 3 Seconds Memory Limit: 65536 KBNim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. The game ends when one of the players is unable to remove object in his/her turn. This player will then lose. On each turn, a player must remov. 阅读全文
posted @ 2012-04-09 00:28 mtry 阅读(391) 评论(0) 推荐(0) 编辑
摘要:完全覆盖时间限制:2000 ms | 内存限制:65535 KB难度:3描述有一天小董子在玩一种游戏----用2*1或1*2的骨牌把m*n的棋盘完全覆盖。但他感觉游戏过于简单,于是就随机生成了两个方块的位置(可能相同),标记一下,标记后的方块不用覆盖。还要注意小董子只有在m*n的棋盘能被完全覆盖后才会进行标记。现在他想知道:如果标记前m*n的棋盘能被完全覆盖,标记后的棋盘是否能被完全覆盖?输入第一行有一个整数t(1<=t<=100000),表示有t组测试数据。每组测试数据有三行或一行。第一行有两个整数 m,n(1<=m,n<=25535)表示行数和列数。第二、三行都有两 阅读全文
posted @ 2012-04-06 12:43 mtry 阅读(806) 评论(0) 推荐(0) 编辑
摘要:Kiki & Little Kiki 2时间限制:3000 ms | 内存限制:65535 KB难度:4描述There are n lights in a circle numbered from 1 to n. The left of light 1 is light n, and the left of light k (1< k<= n) is the light k-1.At time of 0, some of them turn on, and others turn off.Change the state of light i (if it's on 阅读全文
posted @ 2012-04-05 15:51 mtry 阅读(433) 评论(0) 推荐(1) 编辑
摘要:Game of Connections时间限制:1000 ms | 内存限制:65535 KB难度:3描述This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, . . . , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pai 阅读全文
posted @ 2012-03-30 16:40 mtry 阅读(1408) 评论(0) 推荐(0) 编辑
摘要:方法一:递归求解(1)、从 n 个元素中,选择 m 个元素的组合 #include<iostream> using namespace std; int ans[10],a[20],m,n; bool visited[20]; void output() { int i; for(i=1;i<m;i++) cout<<ans[i]<<" "; cout<<ans[i]<<endl; } void work(int i,int k) { if(i==m+1) { output(); return ; } fo. 阅读全文
posted @ 2012-03-26 18:38 mtry 阅读(1584) 评论(0) 推荐(0) 编辑
摘要:快速查找素数时间限制:1000 ms | 内存限制:65535 KB难度:3描述现在给你一个正整数N,要你快速的找出在2.....N这些数里面所有的素数。输入给出一个正整数数N(N<=2000000)但N为0时结束程序。测试数据不超过100组输出将2~N范围内所有的素数输出。两个数之间用空格隔开样例输入510110样例输出2 3 52 3 5 72 3 5 7 11算法分析:打素数表;错误原因:假如n=2000000时要考虑最后的数字View Code #include<iostream>#include<cstdio>#include<cstring> 阅读全文
posted @ 2012-03-22 22:03 mtry 阅读(1754) 评论(0) 推荐(0) 编辑
摘要:求余数时间限制:1000 ms | 内存限制:65535 KB难度:3描述现在给你一个自然数n,它的位数小于等于一百万,现在你要做的就是求出这个数除10003之后的余数输入第一行有一个整数m(1<=m<=8),表示有m组测试数据;随后m行每行有一个自然数n。输出输出n整除10003之后的余数,每次输出占一行。样例输入345465456541样例输出456948算法分析:就是模拟一般的除法运算。View Code 1 #include<iostream> 2 #include<cstring> 3 #define N 1000010 4 5 using nam 阅读全文
posted @ 2012-03-22 19:39 mtry 阅读(882) 评论(0) 推荐(0) 编辑
摘要:我排第几个时间限制:1000 ms | 内存限制:65535 KB难度:3描述现在有"abcdefghijkl”12个字符,将其所有的排列中按字典序排列,给出任意一种排列,说出这个排列在所有的排列中是第几小的?输入第一行有一个整数n(0<n<=10000);随后有n行,每行是一个排列;输出输出一个整数m,占一行,m表示排列是第几位;样例输入3abcdefghijklhgebkflacdjigfkedhjblcia样例输出1302715242260726926算法分析:这个题我是采用计算给定字符串后面还有多少个View Code 1 #include<iostream 阅读全文
posted @ 2012-03-22 14:51 mtry 阅读(741) 评论(0) 推荐(0) 编辑