
ACM-模拟题
文章平均质量分 57
LarryNLPIR
专注NLP/IR/Machine Learning/Data Mining
展开
-
POJ 1029 硬币称量类型二 与POJ 1013类比 模拟题
<br />参考了slayer 的解答http://www.slyar.com/blog/poj-1029-cpp.html 与POJ 1013类比<br />模拟题,抓两点,其一在等式中出现的硬币一定不是假币,其二在不等式中每次都出现即在不等式中出现的次数等于它出现的次数,一定是假币<br />其他情况无法判断输出0<br />#include <iostream>#include <string>using namespace std;const int MAX = 1001;int原创 2010-12-14 21:14:00 · 2452 阅读 · 0 评论 -
LeetCode Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whether原创 2015-07-27 16:38:42 · 3067 阅读 · 0 评论 -
LeetCode 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 its ne原创 2014-11-10 14:01:07 · 1888 阅读 · 0 评论 -
LeetCode Merge Intervals
题目:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].思路分析:这题关键要想到先对区间排序,然后从前向后扫描,如果下一个没法合并,就添加一个区间;如果可以,还要继续向后看,原创 2014-11-23 11:02:09 · 2137 阅读 · 0 评论 -
POJ 1247 数组首尾求和判定相等 枚举法
此题把题意弄懂后就很容易,S顺时针走,E逆时针走,确定一个分割点该处两人相遇时途经的客人数之和相等,直接枚举。#include using namespace std;//s顺时针走,e逆时针走,问他们在哪里相遇时路径上面经过的数字之和相等//直接用枚举法int main(){ int table[32]; int n,sum1,sum2,i,j; while(cin>>n,n!=0){ for (i = 1;i >table[i]; for (i = 1;i原创 2010-11-25 23:22:00 · 1775 阅读 · 0 评论 -
LeetCode Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where i原创 2014-11-09 11:36:47 · 2390 阅读 · 0 评论 -
POJ 2017 计算公路里程 模拟题
水题一道,以后还是不做水题,没什么收获Source CodeProblem: 2017 User: yangliuACMerMemory: 244K Time: 0MSLanguage: C++ Result: Accepted#include using namespace std;int原创 2012-02-10 16:54:49 · 3201 阅读 · 2 评论 -
POJ 1028 用栈模拟浏览器的前进与后退
poj 1028 Web NavigationTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 17718 Accepted: 7751DescriptionStandard web browsers contain features to move bac原创 2010-11-12 16:44:00 · 2935 阅读 · 0 评论 -
POJ 1033 磁盘文件碎片整理 模拟题 栈应用
以后一定要细心,不能再犯这个低级的错误,把WA控制在最低范围内参考了 http://www.cnblogs.com/damacheng/archive/2010/09/24/1833983.html的题目分析题目大意:你要写一个OS,要实现磁盘碎片整理的功能。磁盘分为N个簇,一个文件可以占用K个簇,(1 文件1:2 3 11 12,占用了4个簇,编号为1-4。 文件2:7,占原创 2011-12-24 20:33:23 · 2307 阅读 · 0 评论 -
面试题研究 用两个栈模拟实现队列
这是我面试一个公司的时候碰到的面试题Q 请用两个栈模拟实现队列,至少完成入队、出队及计算长度的方法A 基本思路是两次后进先出 = 先进先出,元素入队列总是入左栈,元素出队列如果右栈不为空直接弹出右栈头元素;如果右栈为空就把左栈元素出栈全部压入右栈,再弹出右栈头,这样就模拟出了一个队列。Class Q{ stack S1,S2; void push(int a){原创 2011-12-21 00:29:31 · 2270 阅读 · 0 评论 -
POJ 1862 变形虫合成 模拟题 优先权队列
本题很简单,变形虫的长度合成满足一定公式,只要每次从所有变形虫当中取出最长的两只合成新虫放进长度集合即可由于要不断取最大值,可以考虑用优先权队列或者堆Source CodeProblem: 1862 User: yangliuACMerMemory: 272K Time: 47MSLanguage: C++ Resul原创 2011-12-24 21:41:57 · 2665 阅读 · 0 评论 -
POJ 1007 DNA排序求逆序数
基本思路就是求逆序数然后根据逆序数排序,出现的问题有:1、这题出现的问题主要是对m和n总是搞混,而且提交出现了Runtime Error,这个错误一般都是由于一般都是非法访问内存(数组越界、访问空指针、堆栈溢出)、做除法时除以了0 等造成的,后来仔细看了一下“a positive integer n (0 < n <= 50) giving the length of the string原创 2011-12-21 00:27:28 · 3181 阅读 · 0 评论 -
POJ 1002 电话号码字符串处理
这题比较简单,就是对电话号码的字符串处理并排序输出,但是实现时有几个注意的地方1、用map存储比较方便,可以自动根据string的排序规则排序,而且题目数据恰好是的K-V存储特点。2、用另一个字符串重新拼接待输出地字符串比直接对输入字符串进行替换移位等操作要方便。3、注意字符和数字的ASCII的转化。4、‘-’的加入可以在输出的时候,输到第4个字符的时候先输出‘-’原创 2011-12-21 00:31:17 · 2892 阅读 · 0 评论 -
POJ 2244 约瑟夫问题的变形 已知最后胜利者逆推模拟
#include using namespace std;//要求第一个人就必须报数,因此第一个人总是最先被删除的。//因此可以把该问题看成是n-1个人的问题。题目就转变为,//在n-1个人的规模下,满足0号是最后胜利者的最小的M。int main(){ int i,n,m,k; while(cin>>n,n){ for(m = 1;;m++) { k = 0; for (i = 2; i原创 2010-11-20 00:04:00 · 2354 阅读 · 0 评论 -
POJ 1013 模拟题硬币称量
POJ 1013 AC代码//经典模拟题//关键思路还是假想如果硬币重或者轻时放在左右两边24种情况应该的results,一一对比//这里先假设硬币偏重,0表示不在,1表示在左边,-1表示在右边//硬币偏轻的情况就恰好与预想情况相反#include #include #include #include using namespace std;int main(){ int exp[12][3]; int result[3]; int n,i,j; stri原创 2010-11-08 20:44:00 · 2680 阅读 · 0 评论 -
POJ 1068 Parencodings 模拟题
这题勾起我伤心的回忆啊就是这题,在北信夏令营测试上面作为D题原题,卡了我两三个小时,眼睁睁看着做过此题的ACMER们抢走机会,痛哉~Orz知耻而后勇,AC300发誓坚持到底,为尊严而战原创 2010-12-17 23:29:00 · 2132 阅读 · 0 评论 -
POJ 2260 Error Correction 模拟题
<br />#include <iostream>using namespace std;int main(){ int n,rc[101][101]; int i,j,tempsr[101],tempsc[101],x[101],y[101]; while(cin>>n,n!=0){ for (i = 0;i < n;i++) for (j = 0;j < n;j++) cin>>rc[i][j]; //若行的奇数和的个数不等于列的奇数和的个数则Corru原创 2010-12-17 21:21:00 · 1687 阅读 · 0 评论 -
LeetCode Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty() --原创 2015-07-21 14:48:29 · 3307 阅读 · 0 评论