自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(181)
  • 问答 (1)
  • 收藏
  • 关注

原创 poj 3461 Oulipo kmp字符串匹配

//#include <iostream>#include <stdio.h>#include <string.h>using namespace std;//string a,b;char a[10000],b[1000000];int asize,bsize;int kmp(){ int *pi = new int [asize]; pi[0] = -1; fo

2015-08-01 18:17:09 514

原创 PAT(Advance) 1091. Acute Stroke (30)

题意是在实难懂,其实就是就是包含上下左右前后的一块连通区域内的1的数量大于threshold DFS和BFS都可以,网上说DFS递归的话可能会爆栈,要写一个非递归的形式 我是用的BFS#include <iostream>#include<queue>#define ROWS 1286#define COLS 128#define SLI 60int map[SLI][ROWS][COL

2015-05-30 12:47:03 686

原创 PAT(Advance) 1089. Insert or Merge (25)

#include <iostream>#include <vector>#include <algorithm>using namespace std;vector<int> orignal,target,result;bool InsertSort(){ int flag = 0; result = orignal; for(int i = 1;i<result.s

2015-05-29 19:48:28 461

原创 PAT(Advance) 1098. Insertion or Heap Sort (25)

#include <iostream>#include <vector>#include <algorithm>using namespace std;vector<int> orignal,target,result;bool InsertSort(){ int flag = 0; //result.clear(); result = orignal; fo

2015-05-29 19:24:13 923

原创 PAT(Advance) 1082. Read Number in Chinese (25)

这道题放了好久,一直不想做,感觉要考虑的情况好多。 实际做的时候感觉只要理清思路还是不难的。#include <iostream>#include <map>#include <vector>using namespace std;string num[10] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};map<i

2015-05-24 16:37:31 451

原创 PAT(Advanec Level) 1093. Count PAT's (25)

注意g++不支持int64_t最后改成了unsigned long long 基本思路:如果是P,不变 如果是A,它前面的所有的P都+1 如果是T,它前面的P都+A#include <stdio.h>#include <vector>#define DIV 1000000007using namespace

2015-05-17 21:15:25 424

原创 1099. Build A Binary Search Tree (30)

1、先递归计算每一个节点两边孩子的数量 2、然后对给的序列排序 3、然后根据两边孩子的数量就可以确定这个节点在序列中的位置,然后递归的确定就好了 4、最后层序遍历一遍#include <iostream>#include <algorithm>#include <queue>#define SIZE 100using namespace std;int treetable[SIZE],t

2015-05-10 14:05:53 302

原创 1097. Deduplication on a Linked List (25)

考察各种STL,没什么难度#include <iostream>#include <stdio.h>#include <list>#include <map>#include <vector>using namespace std;struct linkedlist{ int address,next,key;};map<int,int> table;list<struct

2015-05-09 20:54:51 280

原创 PAT 1095. Cars on Campus (30)

思路不难,就是处理起来略繁 查询的时候题目说明按照时间顺序查询,就暗示要进行前面的record删掉,一开始用STL中的list的erase超时了,后来用vector记录上次不满足条件的起始地址,类似于伪删除#include<iostream>#include<vector>#include<map>#include<string.h>#include<string>#include<li

2015-04-07 17:38:10 1794 1

原创 PAT 1096. Consecutive Factors (20)

#include<stdio.h>int begin, end, length, maxbegin, maxend, maxlength;int main(){ long long num; long long i; bool flag = false; scanf("%lld", &num); maxbegin = maxend = maxlength =

2015-04-06 17:47:13 617

原创 PAT 1094. The Largest Generation (25)

简单BFS,要注意判断每一层开始的标志#include<stdio.h>#include<vector>#include<queue>#define SIZE 105using namespace std;vector<int> family[SIZE];queue<int>q;int maxgen, gen;void bfs(int n){ maxgen = 0; ge

2015-04-06 16:18:57 402

原创 PAT 1092. To Buy or Not to Buy (20)

#include<stdio.h>#include<string.h>#include<map>#define SIZE 1005using namespace std;char sell[SIZE], want[SIZE];map<char, int>m;int main(){ freopen("1.in", "r", stdin); scanf("%s", sell

2015-04-06 15:31:12 321

原创 1060. Are They Equal (25)

#include<iostream>#include<string>#include<string.h>using namespace std;class digit{private: char a[101]; int pow;public: digit(char *str = "NULL", int n = 0) :pow(n){ strcpy(a

2015-03-14 16:13:43 262

原创 pat 1057. Stack (30)

利用树状数组来做,树状节点储存该区间内的数字个数 树状数组每个节点x负责的区间为[x - 2^k + 1,x] 其中k为x用二进制表示中末尾0的个数#include<stdio.h>#include<stack>#include<algorithm>#include<string.h>using namespace std;#define SIZE 100001struct key{

2015-03-14 10:43:02 369

原创 pat 1034. Head of a Gang (30)

DFS寻找强连通分量#include<stdio.h>#include<iostream>#include<string>#include<vector>#include<map>#include<algorithm>#define SIZE 2000#define INF 0x7fffffffusing namespace std;int graph[SIZE][SIZE], ca

2015-03-08 21:43:04 358

原创 pat 1033. To Fill or Not to Fill (25)

贪婪算法#include<stdio.h>#include<algorithm>#define SIZE 501#define INF 0x7fffffffusing std::sort;struct gas{ double price; int dist;} station[SIZE];bool cmp(const struct gas &a, const gas &b

2015-03-08 15:29:20 305

原创 pat 1032. Sharing (25)

建两条双向链表,然后从后向前比较#include<stdio.h>#define SIZE 100000struct list{ int add; struct list *next, *forward; char key;};struct Node{ int add,next; char key;}node[SIZE];int main(){

2015-03-08 10:10:06 283

原创 pat 1022. Digital Library (30)

用STL里的map很简单 要注意的几点: 1.key的分离,网上查到一种比较好的方法char *point=book[i].keyWord;//关键词分离 while(*point){ sscanf(point,"%s",str); point+=strlen(str)+1; string stemp(str); mm_keyWord[st

2015-03-07 21:38:16 573

原创 pat 1068. Find More Coins (30)

01背包 裸背包问题,相关资料参见 dd 大神的总结:《背包问题九讲》按照常规的背包思路,构建 10001 * 101 的二维数组 f[i][j],状态 f[i][j] 表示前 i 枚硬币能拼凑出的小于等于 j 的最大值(j 这里代表一个价格)。状态转移方程为:f[i][j] = max(f[i - 1][j], f[i - 1][j - c[i]] + c[i]), 其中 c[i]为第 i 枚硬

2015-03-07 19:29:24 264

原创 pat 1065

1.考虑相加溢出的情况 (1) a > 0 && b>0 && a+b <0 , 因 a+b > c,故true (2) a < 0 && b<0 && a+b >0 , 因 a+b < c,故false 2. PAT上不支持 __int64数据,采用long long型数据#include<stdio.h>int main(){ long long a, b, c; i

2015-03-02 18:04:33 315

原创 pat 1063

看到有人用STL 中的set来求交集和并集,学习一下#include<stdio.h>#include<map>#define SIZE 50using namespace std;map<int, int> set[SIZE];void SetSim(int a, int b){ map<int, int>s; map<int, int>::iterator k;

2015-03-02 17:40:50 415

原创 pat 1056

一开始理解错了题意,以为第二行的第i个数是第一行数的order,实际上是根据第二行排序,例如第二行第一个数是6,就是第一行6个数作为第一组第一号 所以这样看用queue是更好的选择#include<stdio.h>#include<algorithm>#include<vector>#define SIZE 1000using namespace std;struct mice{

2015-03-02 12:37:21 397

原创 pat 1053

简单回溯,其实还可以再剪枝的,数据太小,没有超时,也就懒得改了o(╯□╰)o#include<stdio.h>#include<vector>#include<algorithm>#define SIZE 100using namespace std;struct tree{ int index; int weight; bool flag;} t[SIZE];ve

2015-03-02 11:08:49 346

原创 pat 1050

先将两个字符串排序,然后对应相同字符标记删除#include<iostream>#include<string.h>#include<algorithm>using namespace std;bool flag[10001];struct str{ char ch; int index;} str1[10001],str2[10001];bool cmp_str(con

2015-02-27 16:22:42 375

原创 pat 1045

lcs变种 一开始我的想法是将题目给出的Favorite Color Stripe扩充后与实际的stripe做lcs,后来看到网上有更好的方法 m = max(mat[i - 1][j - 1], mat[i - 1][j], mat[i][j - 1]) 当a[i] == b[i]时,mat[i][j] = m + 1; 反之,mat[i][j] = m; from http://b

2015-02-27 15:31:46 365

原创 pat 1044

#include<iostream>#include<vector>#define INIFINTE 0x7fffffffusing namespace std;vector<pair<int, int>> pay;int main(){ freopen("1.in", "r", stdin); int n, m; scanf("%d%d", &n, &m);

2015-02-27 15:21:56 324

原创 pat 1038

对于字符串排序,依据: 若a在b前面组成的字符串小于b在a前的字符串,则a在b前面,反之b在a前面要注意 Do not output leading zeros. 例如 3 0 0 0 应只输出一个0#include<iostream>#include<string>#include<algorithm>using namespace std;bool cmp(const

2015-02-26 22:13:49 319

原创 Pat 1018

看起来是一道dijkstra题,实际上远没那么简单。dijkstra算法应该属于一种贪心算法,而要想应用贪心算法,就要确保之前的最优解是得到下一个最优解的基础,而这道题里面的条件约束中,路径长度是符合贪心算法的,但是自行车数量就不符合了! 例如 10 5 5 7 0 10 6 5 0 0 1 1 0 2 1 0 3 1 1 4 1 2 4 1 3 4 1 4 5 1 正确答案

2015-02-26 21:43:17 416

原创 pat 1016

第一次用map STL,其中map<string,int>,最好不要用char*做map的key,详见stackoverflows上的讨论 http://stackoverflow.com/questions/4157687/using-char-as-a-key-in-stdmap/4157811#4157811要注意如果一个账户没有满足条件的账单,则它什么都不输出(名字也不输出)#includ

2015-02-25 22:33:24 295

原创 pat 1067

v[0] != 0: 说明0不在正确位置上,那要通过变换使得v[0] == 0才行。此时该将0与该处在0所处的位置上的元素进行 交换,例如上面的举例{4, 0, 2, 1, 3},此时该将0与1(0所处的位置序号为1,即这本该是1所在的位置)交换, 通过类似的多次交换直到v[0] == 0;v[0] == 0: 此时0已在正确位置上了,但其他元素还没有全处于正确位置。所以必须得有一次废交换

2015-02-23 10:10:17 341

原创 pat 1089(两个点没有过)

#include<stdio.h>int org[100], sorted[100],it,ms[100];bool IsInsert(int n){ if (n == 1) return true; int i; for (i = 1; i < n; i++) if (sorted[i] < sorted[i - 1])

2015-02-23 08:55:45 305

原创 pat 1090

简单BFS#include<stdio.h>#include<vector>#include<math.h>#include<string.h>#include<queue>#define SIZE 100005using namespace std;vector<int> graph[SIZE];int level[SIZE], retail,lvl;void BFS(int s,

2015-02-22 20:27:58 417

原创 pat 1088

#include<stdio.h>long long gcd(long long a, long long b){ if (!a) return b; if (!b) return a; if (a < 0) a = -a; if (b < 0) b = -b; int tmp; whil

2015-02-22 18:32:00 340

原创 pat 1087

注意INIFINTE 定义成32767已经不够了,有可能出现大于INIFINTE的distance,以后定义成0x7fffffff (7个f) 相同最短路径的个数等于父路径个数或父路径个数加一,而不是++#include<stdio.h>#include<vector>#include<string.h>#define SIZE 205#define INIFINTE 0x7fffffff

2015-02-22 13:21:44 347

原创 pat 1085

固定下界用二分法求上界O(nlogn)#include<stdio.h>#include<algorithm>#include<vector>using namespace std;int main(){ int n,p; freopen("1.in", "r", stdin); scanf("%d%d", &n,&p); vector<int>v; i

2015-02-20 20:49:14 524

原创 pat 1080

#include<stdio.h>#include<vector>#include<algorithm>using namespace std;struct person{ int ge, gi; int total; int index; int rank;} app[40000],s[100];int school[100];vector<int>stu

2015-02-20 12:22:11 365

原创 pat 1079

printf中%0.1f采用的是四舍五入#include<stdio.h>#include<vector>#include<math.h>using namespace std;int level[100000],LEVEL;int sup[100000];vector<int> node[100000];void DFS(int src,int lvl){ level[src]

2015-02-20 10:55:14 488

原创 pat 1077

#include<stdio.h>#include<string.h>char * FindCommon(char a[], char b[]){ int len1 = strlen(a), len2 = strlen(b); int i = len1 - 1, j = len2 - 1; int flag = 0; for (; i >= 0 && j >= 0;

2015-02-20 09:58:56 294

原创 pat 1076

BFS#include<stdio.h>#include<queue>#include<string.h>using namespace std;bool graph[1005][1005];int flag[1005];int level;int NUM[1005];queue<int> q;void BFS(int s,int n){ int i,num = 0,coun

2015-02-19 22:37:04 314

原创 pat 1075

之前没有考虑到AC过后还会再次提交AC的代码,这时perfect就不应该在次改变,查了好久%>_<%#include<stdio.h>#include<algorithm>using namespace std;struct person{ int id; int problem[5]; int grade; int rank; int flag;

2015-02-17 21:42:13 325

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除