- 博客(20)
- 收藏
- 关注
原创 HDU-3038 How Many Answers Are Wrong
Problem DescriptionTT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game.
2017-04-07 09:58:00
337
原创 HDU-1213 How Many Tables
Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the fri
2017-04-07 09:37:54
246
原创 POJ-1611 The Suspects
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s
2017-04-07 09:34:02
224
原创 POJ-2236 Wireless Network
DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all com
2017-03-31 15:02:33
524
原创 777E Hanoi Factory
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Eg
2017-02-28 14:55:32
582
原创 777C Alyona and Spreadsheet
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.Now she has a table filled with integers. The table consists of n rows and m co
2017-02-28 14:32:38
334
原创 算法概论8.14
8.14. 证明如下问题是NP完全的:给定一个无向图G = (V, E)和整数k,求G中一个规模为k的团以及一个规模为k的独立集【证明】(算法导论34.5.1)(1)团:顶点子集V'⊆V,其中每一对定点之间都由E中的一条边来连接,即团是G的完全子图。对于一个给定的图G = (V, E),团中顶点集V',对于任意一对顶点u, v∈V',检查边(u, v)是否属于E,就可以在多项式时间
2017-01-15 14:14:33
422
原创 【LeetCode】207. Course Schedule (Medium)
【题意】给出一个有向图的边集,判断这个图是不是DAG【解】用DFS,记录每个节点u的发现时间 u.d 和完成时间 u.f,一个有向图是DAG当且仅当DFS不产生后向边。如果u.d v.f 说明有一条v -> u的后向边。#include#includeusing namespace std;class Solution {public: bool canFinish(int
2016-09-22 22:02:48
259
原创 【LeetCode】215. Kth Largest Element in an Array (Medium)
【题意】找出第k大的元素【解】类似快排class Solution {public: int findKthLargest(vector& nums, int k) { return f(nums, 0, nums.size(), k); }private: int f(vector& nums, int l, int r, int k) {
2016-09-14 14:18:49
212
原创 【LeetCode】240. Search a 2D Matrix II (Medium)
【题意】给一个m*n的矩阵,矩阵的每一行从左到右,从小到大排列,每一列从上到下,从小到大排列。给定一个元素,返回是不是在矩阵中。【解】把矩阵分成四个部分 1 2 3 4每个部分的最小元素在左上角,最大元素在右下角,如果要找的元素在最大和最小之间,接着分。有限步后一定会终止,不可能有元素可能既出现在1
2016-09-14 00:22:52
254
原创 【LeetCode】136.Single Number (Easy)
题意:给定一个数组,里面有一个元素只出现一次,其他都出现两次,要求O(n)时间复杂度,O(1)空间复杂度用异或 a^a = 0,所有元素异或得到的结果就是只出现一次的。int singleNumber(vector& nums) { int s = 0; for (size_t i = 0; i < nums.size(); i++)
2016-09-06 14:01:31
238
原创 【LeetCode】169.Majority Element (Easy)
题目要求:n个元素的数组,找出现次数大于[n/2]的数(保证存在)用map可以过: int majorityElement(vector& nums) { map m; for (int i = 0; i != nums.size(); i++) m[nums[i]]++; for (map::iterat
2016-09-06 01:19:57
242
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人