- 博客(141)
- 收藏
- 关注
原创 高精度模板
#include <bits/stdc++.h> using namespace std; string add(string s1,string s2) { int l1 = s1.size(); int l2 = s2.size(); if(l2>l1) { int n = l2-l1; while(n) ...
2018-09-14 13:35:32
295
原创 前序中序求后序,中序后续求前序
求后续 #include <bits/stdc++.h> using namespace std; int const maxn=1100; int a[8][8]; int vis[8]; vector<string> ans; void f(string ins,string post) { if(ins.size()==0) return ; ...
2018-09-14 11:05:27
523
原创 P1273 有线电视网
就是一个普通的树形dp,看错了题目的输入一直wa。 // luogu-judger-enable-o2 #include <bits/stdc++.h> using namespace std; const int maxn = 3010; vector<int> G[maxn]; int dp[maxn][maxn]; int vis[maxn][maxn]; int...
2018-09-01 12:07:20
310
原创 P1198 [JSOI2008]最大数
#include <bits/stdc++.h> using namespace std; int n,d; int const maxn =200001; int const INF = -2147483647; int thenum = 200000; int addv[maxn],maxv[maxn<<2]; void build(int s ,int l...
2018-08-31 10:13:23
390
1
原创 P1197 [JSOI2008]星球大战
不同的结构形成的结果也不同。。 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<vector> #include<stack> #define MAXN 200010 using namespace std...
2018-08-30 15:49:00
189
原创 最小生成数模板和并查集模板
#include<bits/stdc++.h> using namespace std; struct Edge{int u,v,w;}edge[200005]; int fa[5005],n,m,ans,eu,ev,cnt; inline bool cmp(Edge a,Edge b) { return a.w<b.w; } //快排的依据 inline int fi...
2018-08-29 22:24:35
174
原创 头条笔试题目
2018/8/25 发下头条的笔试题目,给大家笔试后练习。 第一题: 求连通分量。bfs dfs 并查集都可以。n=1e5,图的储存估计要用邻接表,而并查集开个数组就可以了。 第二题: 感觉应该是递推 唯一分解,考虑最后一个加减号的位置。 第三题: 听说kmp可以或者trie树 第四题: 不递减的序列的改变,记录一个周期每个点对应的大小关系,有上一个周期的节点就...
2018-08-29 10:47:41
366
原创 Poj 1258
#include<iostream> #include <string.h> using namespace std; const int maxn = 1000; int graph[maxn][maxn]; int dis[maxn]; int vis[maxn]; int n; const int INF = 0x3f3f3f3f; int tree(int r) { int ans
2017-06-23 00:11:03
388
原创 Poj 1161
#include <stdio.h> #include <string.h> int const maxn = 1000; const int INF = 0x3f3f3f3f; int n,m,a; int member[maxn]; int G[maxn][maxn]; struct area { int townnum; int town[maxn]; int vis
2017-06-20 14:20:54
360
原创 英语6级题目
Questions 52 to 56 are based on the following passage.Is 20th-century capitalism failing 21st-century society? Members of the global elite debated that unusual question at the annual World Economic For
2017-06-20 14:20:13
1634
原创 魔板[S]
好的分层思想会使代码简单许多。 用了康拓展开,再次感觉到了数学的力量。 bfs的判定边界条件的时候,一般可以分为在得到新的状态的时候判定是否重复,也可以在拿出来的时候判定。总体而言在得到的时候判定会减少一层判定树的高度,但是要额外注意最开始的初始情况。 在TSOj中由于不能用stl中的数据,即必须自己手写队列,保存状态等,但是可以用stl的时候用简单了不少。#include <stdio.h>
2017-03-01 16:50:54
463
原创 3n+1数链问题
用时间换空间,然而需要的空间太大,卡在第6个样例,我觉得应该可以压缩的。#include <stdio.h> #include <string.h>int const maxn = 7000000; //不知道上限在哪里 int g_a[maxn]; int g_i,g_j; int g_ans=0;int dfs(int i) { if (g_a[i]!=-1) return g_a[
2017-02-27 13:33:37
394
原创 能量项链
动态规划的想法很容易想到,但是在细节上特别是整除那里容易出错,如果下标从0开始也许更为方便一些。#include <stdio.h> #include <string.h> int const maxn = 210; int a[maxn],s[maxn][maxn]; int n; int f(int k) { if(k>n) { if(k%n==0) return n;
2017-02-24 23:16:41
457
原创 this指针的作用
//this指针问题 2012年7月18日0:37:13 #include <iostream> using namespace std; class point { public: int x,y; point(int a,int b) { x= a; y = b; } void input(int x,in
2017-02-04 23:14:48
455
原创 [编程题]餐馆
某餐馆有n张桌子,每张桌子有一个参数:a 可容纳的最大人数; 有m批客人,每批客人有两个参数:b人数,c预计消费金额。 在不允许拼桌的情况下,请实现一个算法选择其中一部分客人,使得总预计消费金额最大 输入描述: 输入包括m+2行。 第一行两个整数n(1 <= n <= 50000),m(1 <= m <= 50000) 第二行为n个参数a,即每个桌子可容纳的最大人数,以空格分隔,范围均在3
2017-01-19 23:07:09
1017
原创 数字和为sum的方法数
给定一个有n个正整数的数组A和一个整数sum,求选择数组A中部分数字和为sum的方案数。 当两种选取方案有一个数字的下标不一样,我们就认为是不同的组成方案。 输入描述: 输入为两行:第一行为两个正整数n(1 ≤ n ≤ 1000),sum(1 ≤ sum ≤ 1000)第二行为n个正整数Ai,以空格隔开。输出描述: 输出所求的方案数输入例子: 5 15 5 5 10 2 3输出例子:
2017-01-19 22:23:18
1539
原创 连续最大和
一个数组有 N 个元素,求连续子数组的最大和。 例如:[-1,2,1],和最大的连续子数组为[2,1],其和为 3 输入描述: 输入为两行。 第一行一个整数n(1 <= n <= 100000),表示一共有n个元素 第二行为n个数,即每个元素,每个整数都在32位int范围内。以空格分隔。输出描述: 所有连续子数组中和最大的值。输入例子: 3 -1 2 1输出例子: 3 当前面的贡
2017-01-19 13:44:35
383
原创 数列还原
牛牛的作业薄上有一个长度为 n 的排列 A,这个排列包含了从1到n的n个数,但是因为一些原因,其中有一些位置(不超过 10 个)看不清了,但是牛牛记得这个数列顺序对的数量是 k,顺序对是指满足 i < j 且 A[i] < A[j] 的对数,请帮助牛牛计算出,符合这个要求的合法排列的数目。 输入描述: 每个输入包含一个测试用例。每个测试用例的第一行包含两个整数 n 和 k(1 <= n <=
2017-01-19 13:41:11
456
原创 星际穿越
航天飞行器是一项复杂而又精密的仪器,飞行器的损耗主要集中在发射和降落的过程,科学家根据实验数据估计,如果在发射过程中,产生了 x 程度的损耗,那么在降落的过程中就会产生 x2 程度的损耗,如果飞船的总损耗超过了它的耐久度,飞行器就会爆炸坠毁。问一艘耐久度为 h 的飞行器,假设在飞行过程中不产生损耗,那么为了保证其可以安全的到达目的地,只考虑整数解,至多发射过程中可以承受多少程度的损耗? 输入描述
2017-01-19 13:35:05
362
原创 分苹果
n 只奶牛坐在一排,每个奶牛拥有 ai 个苹果,现在你要在它们之间转移苹果,使得最后所有奶牛拥有的苹果数都相同,每一次,你只能从一只奶牛身上拿走恰好两个苹果到另一个奶牛上,问最少需要移动多少次可以平分苹果,如果方案不存在输出 -1。 输入描述: 每个输入包含一个测试用例。每个测试用例的第一行包含一个整数 n(1 <= n <= 100),接下来的一行包含 n 个整数 ai(1 <= ai <=
2017-01-19 13:32:15
438
原创 分田地
牛牛和 15 个朋友来玩打土豪分田地的游戏,牛牛决定让你来分田地,地主的田地可以看成是一个矩形,每个位置有一个价值。分割田地的方法是横竖各切三刀,分成 16 份,作为领导干部,牛牛总是会选择其中总价值最小的一份田地, 作为牛牛最好的朋友,你希望牛牛取得的田地的价值和尽可能大,你知道这个值最大可以是多少吗? 输入描述: 每个输入包含 1 个测试用例。每个测试用例的第一行包含两个整数 n 和 m(
2017-01-19 13:31:02
629
原创 下厨房
牛牛想尝试一些新的料理,每个料理需要一些不同的材料,问完成所有的料理需要准备多少种不同的材料。 输入描述: 每个输入包含 1 个测试用例。每个测试用例的第 i 行,表示完成第 i 件料理需要哪些材料,各个材料用空格隔开,输入只包含大写英文字母和空格,输入文件不超过 50 行,每一行不超过 50 个字符。输出描述: 输出一行一个数字表示完成所有料理需要多少种不同的材料。输入例子: BUTTE
2017-01-19 13:29:39
315
原创 地牢逃脱
是对最短路径的变形,即是就最短路径当中的最长路径,注意修改即可。bfs,dfs都可以实现,现在附上dfs的实现方式。#include <iostream> #include <cstring> using namespace std; int const maxn = 100; char data[maxn][maxn]; int r,c; int vis[maxn][maxn]; int dr[m
2017-01-19 13:24:41
308
原创 合唱团
dp 保留两个数组,因为最大值得来源有两个 另外记得用long long,int会溢出#include <iostream> #include <cstring> using namespace std; int const maxn = 100; int data[maxn]; long long ap[maxn][maxn]; long long an[maxn][maxn]; int c
2017-01-19 13:20:16
371
原创 Super Snooker
#include <iostream> using namespace std;int main() { int t; cin>>t; int a,b,c,d; for (int i=1;i<=t;i++) { cin>>a>>b>>c>>d; int s=(c+d)*(d-c+1)/2; int len = d-c+1
2017-01-13 20:53:02
311
原创 Team Rankings
搜索#include <iostream> #include <cstring> using namespace std; char tmp[10]; char data[110][10]; int vis[10]; int ans = 2<<10; int n; char hh[10]; int findchar(char* s,char k) { for (int i=0;i<strle
2017-01-13 20:52:28
426
原创 sort-list
说说自己做的过程中的几个错误吧。 1忽略了空链表的情况。 2两个链表进行并归排序的时候,应该拿函数返回的头结点,而不是划分的头结点,因为在递归的过程中,最初的头结点可能因为排序而后移了。 3快慢指针的问题条件的判断。#include <iostream> #include <map> #include <vector> #include<cstdlib> #include <ctime> #i
2017-01-12 17:53:39
242
原创 Sorting Algorithm
堆排序#include <iostream> using namespace std; const int maxn = 100010; int a1[maxn]; int n,m; void g(int lo,int len) { int tmp = a1[lo]; int h = lo; int k=lo*2; while(k<=len) { i
2017-01-03 10:57:56
336
原创 字符串匹配
题目中的数组大小有问题#include <iostream> #include <string> using namespace std; const int maxn = 60010; int a1[maxn],a2[maxn]; int len1,len2;int* build(int l2) { int i1=-1,i2=0; int* next = new int[l2];
2017-01-02 19:12:34
291
原创 图的广度优先搜索
pay attention to the cout#include <iostream> #include <vector> #include <cstring> #include <queue> using namespace std; const int maxn = 1010; int nV,nE; int vis[maxn]; int map[maxn][maxn]; int main()
2017-01-01 13:33:08
299
原创 connect components in undirected graph
深度和宽度搜索都写了,记住分析的过程。#include <iostream> #include <vector> #include <cstring> #include <queue> using namespace std; const int maxn = 1010; int nV,nE; int vis[maxn];int f (int lo,vector<vector<int>> V) {
2017-01-01 13:11:46
350
原创 走迷宫
记忆化搜索的效果呢?我估计效率不会高。#include <iostream> #include <cstring> #include <queue> using namespace std; int const maxn = 20; int vis[maxn][maxn]; char data[maxn][maxn]; int dr[]={1,-1,0,0}; int dc[]={0,0,1,-1}
2016-12-31 21:36:13
406
原创 猴子选大王
#include <iostream> #include <list> #include <vector> using namespace std; const int maxn = 100; int data[maxn]; int main() { int t; cin>>t; while(t--) { int n,m; cin>>n>>m;
2016-12-31 20:50:52
366
原创 卡片游戏
#include <iostream> #include <list> #include <vector> using namespace std; const int maxn = 100; int data[maxn];int main() { int t; cin>>t; while(t--) { int n; cin>>n; for(int i=0;i<n
2016-12-31 20:32:55
398
转载 list
http://www.cnblogs.com/fangyukuan/archive/2010/09/21/1832364.html http://www.cnblogs.com/scandy-yuan/archive/2013/01/08/2851324.html
2016-12-30 17:11:14
283
原创 1002. 计算二叉查找树的高度
devcpp代码名字如果太相近就会出现bug#include <iostream> using namespace std; const int maxn = 100; int a[maxn],b[maxn]; struct TreeNode { int val; TreeNode* left,*right; TreeNode(int a):val(a),left(NULL)
2016-12-30 15:14:21
642
原创 Intersect
#include <iostream> #include <set> using namespace std; int main() { int n; cin>>n; while(n--) { int n1,n2; cin>>n1>>n2; set<int> S1; for (int i=0;i<n1;i++)
2016-12-29 18:58:42
344
原创 红与黑
#include <iostream> #include <cstring> using namespace std; const int maxn = 25; int dr[]={0,0,1,-1}; int dc[]={1,-1,0,0}; char data[maxn][maxn]; int vis[maxn][maxn]; int dfs(int lr,int lc,int r,int
2016-12-29 14:00:27
412
原创 最长句子
从子树到父节点却是一个选择。#include <set> #include <map> #include <string> #include <iostream> using namespace std; int getLen(string s,map<string,set<string>>& mp,map<string,int>& hasFind){ if(hasFind.count(s)==1)
2016-12-29 13:32:51
440
原创 validate-binary-search-tree
while写成if debug了半天。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }
2016-12-28 10:32:41
306
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅