OJ
文章平均质量分 66
jxfang7788
#非宁静无以致远-_-||
展开
-
POJ1012 Joseph
题目比较简单,因为k不大于14,所以直接使用暴力求解递推公式为:ans[i]; //第i轮杀掉 对应当前轮的编号为ans[i]的人ans[0]=0;ans[i]=(ans[i-1]+m-1)%(n-i+1); (i>1 , 总人数n=2k 则n-i为第i轮剩余的人数)若本题是从0开始报数,则递推式要改变为ans[i]=(ans[i-1]+m)%(n-i原创 2015-05-08 22:46:49 · 384 阅读 · 0 评论 -
LeetCodeOJ: 38. Count and Say
Total Accepted: 75530 Total Submissions: 265272 Difficulty: EasyThe count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "原创 2016-03-23 21:18:50 · 328 阅读 · 0 评论 -
LeetCodeOJ:338. Counting Bits
Total Accepted: 4466 Total Submissions: 8073 Difficulty: MediumGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their原创 2016-03-22 11:49:29 · 422 阅读 · 0 评论 -
LeetCodeOJ:2. Add Two Numbers
Total Accepted: 129010 Total Submissions: 572407 Difficulty: MediumYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of原创 2016-03-20 14:20:35 · 323 阅读 · 0 评论 -
LeetCodeOJ:1Two Sum
Total Accepted: 203765 Total Submissions: 923425 Difficulty: EasyGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume原创 2016-03-20 13:39:09 · 347 阅读 · 0 评论 -
LeetCode OJ: 12 Integer to Roman
Total Accepted: 59069 Total Submissions: 155093 Difficulty: MediumGiven an integer, convert it to a roman numeral.Input is guaranteed to be with原创 2016-03-20 11:07:12 · 265 阅读 · 0 评论 -
UVA10038 - Jolly Jumpers
代码如下#include#include#include#include#includeusing namespace std;int main(){ int n; string input; bool mark[3001]; int num[3001]; while(1){ getline(cin, input);原创 2015-09-15 20:36:20 · 436 阅读 · 0 评论 -
ccf 字符串匹配
问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行。你的程序还需支持大小写敏感选项:当选项打开时,表示同一个字母的大写和小写看作不同的字符;当选项关闭时,表示同一个字母的大写和小写看作相同的字符。输入格式 输入的第一行包含一个字符串S,由大小写英文字母组成。 第二行包含一个数字,表示大小写敏感的选项,当数字为0时表示大小写不敏感,当数字为1时表示大小写敏感原创 2015-09-11 15:47:11 · 575 阅读 · 0 评论 -
九度题目1190:大整数排序
题目描述:对N个长度最长可达到1000的数进行排序。输入:输入第一行为一个整数N,(1接下来的N行每行有一个数,数的长度范围为1每个数都是一个正数,并且保证不包含前缀零。输出:可能有多组测试数据,对于每组数据,将给出的N个数从小到大进行排序,输出排序后的结果,每个数占一行。样例输入:311111111111111111111原创 2015-09-10 16:22:51 · 754 阅读 · 0 评论 -
九度题目1207:质因数的个数
题目描述:求正整数N(N>1)的质因数的个数。相同的质因数需要重复计算。如120=2*2*2*3*5,共有5个质因数。输入:可能有多组测试数据,每组测试数据的输入是一个正整数N,(1输出:对于每组数据,输出N的质因数的个数。样例输入:120样例输出:5提示:注意:1不是N的质因数;若N为质数,N是N原创 2015-09-08 16:35:49 · 462 阅读 · 0 评论 -
九度题目1447:最短路
题目描述:在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?输入:输入包括多组数据。每组数据第一行是两个整数N、M(N当输入为两个0时,输入结束。输出:对于每组输入,输出一行,表示工作人员从原创 2015-09-08 15:08:00 · 920 阅读 · 0 评论 -
九度题目1008:最短路径问题
题目描述:给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。输入:输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p。最后一行是两个数 s,t;起点s,终点t。n和m为0时输入结束。(1输出:输出原创 2015-09-08 14:55:19 · 494 阅读 · 0 评论 -
九度OJ1444:More is better
题目描述:Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.Mr Wang selected原创 2015-09-06 10:10:49 · 493 阅读 · 0 评论 -
各大Oj平台介绍
转载自:http://www.cnblogs.com/lzmfywz/archive/2012/02/07/2342010.html1.题库与网站资源题库-在线提交系统(Online Judge)简介 下面是几个比较大的在线提交系统(OnlineJudge)里面有大量历年的竞赛题目,注册一个ID,然后用自己熟悉的语言(一般有Pascal/C/C++/Java)写好源代码转载 2015-09-04 15:49:29 · 1063 阅读 · 0 评论 -
九度OJ题目1012:畅通工程
题目描述: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?输入: 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( 注意:两个城市之原创 2015-08-14 11:11:29 · 430 阅读 · 0 评论 -
九度题目1432:叠筐
题目描述:把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。输入:输入是一个个的三元组,分别是,外筐尺寸n(n为满足0输出:输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。样例输入:11 B A 5 @原创 2015-08-13 11:47:28 · 675 阅读 · 0 评论 -
POJ1728 A flea on a chessboard
首先很容易判断出当前坐标(x, y)落在白格子上的条件是q(x / S) + q(y / S) 为奇数, q表示下取整那么可以从起点不断地循环跳,并用上述条件判断是否跳到了白格子, 如果不在白格子,则对当前当前坐标模S,当(x % S, y % S)已经被访问过时说明无解这里有一个要注意的地方,那就是:模运算时如果x % 2 == 0(或者y % 2 == 0)时即落在边界上,需要判断这个原创 2015-05-08 18:24:02 · 466 阅读 · 0 评论 -
POJ1231The Alphabet Game
题意:输入K和P,K表示有几种字母,也就是输入有几行,p表示每种字母有几个,是以坐标的形式出现的(x,y),现在让我们将相同的字母划分在一个矩形块中,使每个矩形都不重合,问能否实现。输入:输入测试的组数t,再给出每一组的字母种数K,每个字母的坐标数P,最后一次输入每种字母的P个坐标。输出:能满足要求的测试数据就输出YES,否则输出NO。具体做法如下1.首先申请4个数原创 2015-05-08 18:15:41 · 591 阅读 · 0 评论 -
POJ2243 Knight Moves
题意:给你一个8*8的棋盘,已知骑士的开始位置、结束位置,让你求得骑士从开始位置走到结束位置所需要的最小步数是多少(骑士走日字)?输入:输入包括多组数据,每一行都是一组开始位置和结束位置,位置由两个字符组成,一个是小写字母(a-h),一个是数字(1-8),起始位置结束位置由一个空格隔开。输出:输出从起始位置到结束位置,骑士所要走过的最小的步数.按照样例的格式来。纯数原创 2015-05-08 18:14:14 · 460 阅读 · 0 评论 -
九度OJ题目1108:堆栈的使用
题目描述: 堆栈是一种基本的数据结构。堆栈具有两种基本操作方式,push 和 pop。Push一个值会将其压入栈顶,而 pop 则会将栈顶的值弹出。现在我们就来验证一下堆栈的使用。输入: 对于每组测试数据,第一行是一个正整数 n,0输出: 对于每组测试数据,根据其中的命令字符来处理堆栈;并对所有的'A’操作,输出当时栈顶的值,每个原创 2015-09-03 15:15:32 · 1088 阅读 · 3 评论 -
LeetCodeOJ:206 Reverse Linked List
Total Accepted: 95123 Total Submissions: 244712 Difficulty: EasyReverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * struct原创 2016-03-23 20:40:18 · 320 阅读 · 0 评论 -
Topcoder好题推荐 ( 持续更新中 )
转载自:http://blog.csdn.net/ls_0222/article/details/8351206推荐的好题不一定是难题,但往往带有那么一点代表性。凡是由别人推荐的题目,偶会加上推荐人ID和blog地址。偶自己推荐的题目,偶会尽量推荐一份简洁的代码。当天推荐的题会以红色标记。Single Round MatchSRM 522 DIV1 1050pt ( 很不错的dp题转载 2015-10-26 16:00:45 · 1420 阅读 · 0 评论 -
POJ题目分类(各种分类合集)
转自:http://blog.csdn.net/kingwolfofsky/article/details/8840207POJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期:一.基本算法: (1)枚举. (poj1753,转载 2015-05-08 17:58:24 · 532 阅读 · 0 评论 -
leetcode 100 sametree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.递归:/** *原创 2016-10-12 19:05:06 · 275 阅读 · 0 评论 -
leetcode OJ:387. First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.以下是程序:c原创 2016-10-12 22:39:28 · 360 阅读 · 0 评论 -
leetcode OJ :413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:原创 2016-10-12 23:39:21 · 634 阅读 · 0 评论 -
leetcode OJ:223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total a原创 2016-10-15 23:27:47 · 374 阅读 · 0 评论 -
leetcode:75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0,原创 2016-12-11 16:39:27 · 293 阅读 · 0 评论 -
leetcode OJ:190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-12-15 17:49:42 · 274 阅读 · 0 评论 -
leetcodeOJ:137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2016-12-24 14:19:08 · 324 阅读 · 0 评论 -
leetcodeOJ:136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2016-12-24 14:21:15 · 199 阅读 · 0 评论 -
leetcodeOJ:134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2016-12-24 15:51:28 · 219 阅读 · 0 评论 -
leetcodeOj:66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.题意:一个整数按位存储于一个数组中,排列顺序原创 2016-12-25 11:09:23 · 284 阅读 · 0 评论 -
leetcodeOJ 113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2017-03-27 15:17:34 · 204 阅读 · 0 评论 -
leetcodeOJ 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.最大深度问题/** * Definition for a binary原创 2017-03-27 15:48:18 · 400 阅读 · 0 评论 -
leetcodeOJ 111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.最小深度问题,注意引用传递。代码如下:/** *原创 2017-03-27 15:54:22 · 207 阅读 · 0 评论 -
leetcodeOJ 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity. 在O(nlogn)时间内,给一单向链表排序 分析,时间复杂度有要求,考虑用mergesort 取单向链表的中间元素:ListNode* temp = head;//temp每次移动一步 ListNode* pre = he原创 2017-04-07 09:44:46 · 194 阅读 · 0 评论 -
leetcodeOJ 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:可以两两进行归并排序,代码如下:/** * Definition for singly-linked list. * struct ListNode { * int原创 2017-04-07 10:06:33 · 219 阅读 · 0 评论 -
leetcodeOJ 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive原创 2017-04-07 11:01:49 · 186 阅读 · 0 评论 -
leetcodeOJ 91. Decode Ways
参考了大牛的博客:http://blog.csdn.net/linhuanmars/article/details/24570759A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26原创 2017-04-07 12:12:05 · 261 阅读 · 0 评论