- 博客(360)
- 资源 (1)
- 收藏
- 关注
原创 PAT-A 1024. Palindromic Number
1024. Palindromic NumberA number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers
2016-08-04 11:17:32 278
原创 PAT-A 1019. General Palindromic Number
1019. General Palindromic NumberA number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit
2016-08-03 23:10:00 262
原创 PAT-B 1055. 集体照
1055. 集体照拍集体照时队形很重要,这里对给定的N个人K排的队形设计排队规则如下: 每排人数为N/K(向下取整),多出来的人全部站在最后一排; 后排所有人的个子都不比前排任何人矮; 每排中最高者站中间(中间位置为m/2+1,其中m为该排人数,除法向下取整); 每排其他人以中间人为轴,按身高非增序,先右后左交替入队站在中间人的两侧(例如5人身高为190、188、186、175、170,则队形为17
2016-08-03 21:33:07 509
原创 PAT-B 1048. 数字加密
1048. 数字加密本题要求实现一种数字加密方法。首先固定一个加密用正整数A,对任一正整数B,将其每1位数字与A的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对13取余——这里用J代表10、Q代表11、K代表12;对偶数位,用B的数字减去A的数字,若结果为负数,则再加10。这里令个位为第1位。输入格式:输入在一行中依次给出A和B,均为不超过100位的正整数,其间以空格分隔。输出格式:在
2016-08-03 21:29:26 336
原创 PAT-B 1007.素数对猜想
1007. 素数对猜想让我们定义 dnd_n 为:dn=pn+1−pnd_n = p_{n+1} - p_n,其中 pi 是第i个素数。显然有 d1=1 且对于n>1有 dnd_n 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。现给定任意正整数N(<105)N (< 10^5),请计算不超过N的满足猜想的素数对的个数。输入格式:每个测试输入包含1个测试用例,给出正整数N。输出格式:每
2016-08-03 21:10:03 1249
原创 PAT-A 1048. Find Coins
1048. Find CoinsEva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as pay
2016-08-03 20:42:13 332
原创 PAT-A 1037. Magic Coupon
1037. Magic CouponThe magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value
2016-08-03 20:38:44 266
原创 PAT-A 1099. Build A Binary Search Tree
1099. Build A Binary Search TreeA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than
2016-08-03 20:25:18 369
原创 PAT-A 1085. Perfect Sequence
1085. Perfect SequenceGiven a sequence of positive integers and another positive integer p. The sequence is said to be a “perfect sequence” if M <= m * p where M and m are the maximum and minimum numbe
2016-08-03 20:19:45 330
原创 PAT-A 1081.Rational Sum
1081. Rational SumGiven N rational numbers in the form “numerator/denominator”, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with
2016-08-03 20:15:20 319
原创 PAT-A 1069. The Black Hole of Numbers
1069. The Black Hole of NumbersFor any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new n
2016-08-03 20:12:11 311
原创 PAT-A 1015. Reversible Primes
1015. Reversible PrimesA reversible prime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its r
2016-08-03 20:07:39 292
原创 PAT-B 1052.卖个萌
萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:[左手]([左眼][口][右眼])[右手]现给出可选用的符号集合,请你按用户的要求输出表情。输入格式:输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号[]内。题目保证每个集合都至少有一个.。之后一行给出一个正整数K,为用户请求的个数。随后K行,每行给出一个用户的符号
2016-08-03 12:27:07 354
原创 PAT-B 1034. 有理数四则运算
本题要求编写程序,计算2个有理数的和、差、积、商。输入格式:输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为0。输出格式:分别在4行中按照“有理数1 运算符 有理数2 = 结果”的格式顺序输出2个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式“k a/b”,其中k是整数部分,a/b是最
2016-08-03 12:25:47 385
原创 PAT-B 1050.螺旋矩阵
题目描述本题要求将给定的N个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第1个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为m行n列,满足条件:m*n等于N;m>=n;且m-n取所有可能值中的最小值。输入格式:输入在第1行中给出一个正整数N,第2行给出N个待填充的正整数。所有数字不超过104,相邻数字以空格分隔。输出格式:输出螺旋矩阵。每行n个数字,共m行。相邻数字以1个
2016-08-02 18:06:03 543
原创 【回溯法】游戏竞赛
题目描述某游戏规则中,甲乙双方战斗,每一回合总能分出胜负,游戏规定: 1.失败的一方要将自己体力值的1/4加给胜利的一方。 2.游戏开始时,甲的体力值是1000,乙的体力值是2000。 3.每一回合,甲乙胜利的概率均为50%。 求解4个回合后,双方体力值之差小于1000的概率。分析每一回合结束,要么甲赢,要么乙赢。n个回合,那么有2^n种结果,采用回溯法从解空间中,中找出abs(a-b)<1
2016-08-02 14:15:10 722
原创 【回溯法】求子集问题
????????{1,2,3},?????????? ???????????,????????????,??????,???????? ????????n????????,?????????i,?xi?????????????,xi=1??????,xi=0???????,??,??????: {x1,x2,x3,x4……xn};???2^n?????????????. ????:#in
2016-08-02 10:38:10 8579 13
原创 【回朔法】八皇后问题
八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例。该问题是国际西洋棋棋手马克斯·贝瑟尔于1848年提出:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问有多少种摆法。 假设八个皇后的位置分别用X1到X8表示,那么Xi可以取的值为1~8,因此,问题的解可以用向量 {x1,x2,x3,x4,x5,x6,x7,x8}表示,解空间包含8
2016-08-02 09:40:56 517
原创 PAt-A 1065. A+B and C(64bit)
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.Input Specification:The first line of the input gives the positive number of test cases, T (<=10). Then T test c
2016-08-01 15:00:09 289
原创 PAT-A 1035. Password
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L i
2016-08-01 14:57:39 323
原创 PAT-A 1049. Counting Ones
The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in
2016-08-01 13:07:11 619
原创 PAT-A 1100. Mars Numbers
People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 to 12 on Earch is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, re
2016-07-31 23:30:50 425
原创 PAT-A 1093. Count PAT's
The string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now giv
2016-07-31 23:29:07 377
原创 PAT-A 1092. To Buy or Not to Buy
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell
2016-07-31 23:27:54 336
原创 PAT-A 1084. Broken Keyboard
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to ty
2016-07-31 23:26:02 269
原创 PAT-A 1083. List Grades
Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades a
2016-07-31 23:24:51 259
原创 PAT-A 1058. A+B in Hogwarts
If you are a fan of Harry Potter, you would know the world of magic has its own currency system – as Hagrid explained it to Harry, “Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sick
2016-07-31 23:23:15 315
原创 PAT-A 1042. Shuffling Machine
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers
2016-07-31 23:22:04 297
原创 PAT-A 1041. Be Unique
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a
2016-07-31 23:19:51 260
原创 PAT-A 1036. Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each input file contains one test c
2016-07-31 23:18:25 293
原创 PAT-A 1031. Hello World for U
Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, “helloworld” can be printed as:h d e l l r lowoThat is, the characters must be printed
2016-07-31 23:17:00 237
原创 PAT-A 1029. Median
Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The
2016-07-31 23:15:42 302
原创 PAT-A 1027. Colors in Mars
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digi
2016-07-31 23:14:29 276
原创 PAT-A 1023. Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number cons
2016-07-31 23:13:20 262
原创 PAT-A 1020. Tree Traversals
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corr
2016-07-31 23:07:03 281
原创 PAT-A 1011. World Cup Betting
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Sim
2016-07-31 23:02:50 280
原创 PAT-A 1008. Elevator
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seco
2016-07-31 23:01:11 310
原创 PAT-A 1007. Maximum Subsequence Sum
Given a sequence of K integers { N1, N2, …, NK }. A continuous subsequence is defined to be { Ni, Ni+1, …, Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has t
2016-07-31 23:00:08 263
原创 PAT-A 1006. Sign In and Sign Out
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in’s and out’s, you
2016-07-31 22:58:27 293
原创 PAT-A 1005. Spell It Right
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each cas
2016-07-31 22:55:15 265
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人