From 632bcfa92c619128a4f814e81361af3e169cc538 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 08:54:53 +0800 Subject: [PATCH 1/9] Create RMQ-ST.cpp --- .ACM-Templates/RMQ-ST.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .ACM-Templates/RMQ-ST.cpp diff --git a/.ACM-Templates/RMQ-ST.cpp b/.ACM-Templates/RMQ-ST.cpp new file mode 100644 index 0000000..274ec68 --- /dev/null +++ b/.ACM-Templates/RMQ-ST.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; + +namespace RMQ_ST +{ +const int MAXN=10000; +int f[MAXN][MAXN]; +int a[MAXN]; +int n; +void init() +{ + for(int i = 1;i<=n;i++) + { + f[i][0]=a[i]; + } + for(int j=1;(1< Date: Thu, 11 Aug 2016 08:55:33 +0800 Subject: [PATCH 2/9] Create Readme.md --- .Tools/Readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .Tools/Readme.md diff --git a/.Tools/Readme.md b/.Tools/Readme.md new file mode 100644 index 0000000..4bce553 --- /dev/null +++ b/.Tools/Readme.md @@ -0,0 +1 @@ +#Tools From 2f5b2cb6e3ce321ec5ae2320893e5977ce71b8bd Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:04:27 +0800 Subject: [PATCH 3/9] Create LCIS.cpp --- .ACM-Templates/LCIS.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .ACM-Templates/LCIS.cpp diff --git a/.ACM-Templates/LCIS.cpp b/.ACM-Templates/LCIS.cpp new file mode 100644 index 0000000..23ca374 --- /dev/null +++ b/.ACM-Templates/LCIS.cpp @@ -0,0 +1,29 @@ +/// LCIS 最长公共上升子序列 +namespace LCIS +{ + +const int MAXLEN_A = 500; +const int MAXLEN_B = 500; +int dp[MAXLEN_A+5][MAXLEN_B+5]; +int deal(const char* a,const char* b) +{ + int lena=strlen(a); + int lenb=strlen(b); + for(int i=1;i<=lenb;i++) + { + int k=0; + for(int j=1;j<=lena;j++) + { + dp[i][j]=dp[i-1][j];/// when b[i-1] != a[j-1] + if(b[i-1]>a[j-1]) k=max(k,dp[i-1][j]); + else if(b[i-1]==a[j-1]) dp[i][j]=k+1; + } + } + int ans=0; + for(int i=1;i<=lena;i++) ans=max(ans,dp[lenb][i]); + return ans; +} + +} +//End of namespace LCIS + From 1d524449693fdea1508d9376d1204d6f60b86384 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:05:04 +0800 Subject: [PATCH 4/9] Create LCS.cpp --- .ACM-Templates/LCS.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .ACM-Templates/LCS.cpp diff --git a/.ACM-Templates/LCS.cpp b/.ACM-Templates/LCS.cpp new file mode 100644 index 0000000..5660cc4 --- /dev/null +++ b/.ACM-Templates/LCS.cpp @@ -0,0 +1,30 @@ +/// LCS 最长子序列 +namespace LCS +{ +const int MAXLEN_A = 500; +const int MAXLEN_B = 500; +int dp[MAXLEN_A+5][MAXLEN_B+5]; +int deal(const char* a,const char* b) +{ + int lena=strlen(a); + int lenb=strlen(b); + for(int i=0;i Date: Thu, 11 Aug 2016 09:05:46 +0800 Subject: [PATCH 5/9] Create LIS.cpp --- .ACM-Templates/LIS.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .ACM-Templates/LIS.cpp diff --git a/.ACM-Templates/LIS.cpp b/.ACM-Templates/LIS.cpp new file mode 100644 index 0000000..9ac1f9b --- /dev/null +++ b/.ACM-Templates/LIS.cpp @@ -0,0 +1,30 @@ +#include +#define MAXN 1010 +int seq[MAXN]; +int seqlen[MAXN]; +int main() +{ + int N; + while(scanf("%d",&N)==1) + { + int i,j,k,max,maxlen=1; + for(i=1; i<=N; i++) + seqlen[i]=1; //seqlen数组存以第i个数为终点的最长上升序列 + for(i=1; i<=N; i++) + scanf("%d",&seq[i]); //seq数组保存序列数组 + for (i=2; i<=N; i++) + { + max=0; + for (j=1; j<=i-1; j++) + { + if(seq[j]max) //在前i-1个序列中,寻找以终点小于seq[i]的最长的子序列,即最优子状态 + max=seqlen[j]; + } + seqlen[i]=max+1; + if(seqlen[i]>maxlen) //seqlen中保存的是第i个数为终点的最长上升序列,找出这个数组中最大的值即为最优序列长度 + maxlen=seqlen[i]; + } + printf("%d\n",maxlen); + } + return 0; +} From 0d0d02cf941be7449b40b9ef6f3b122fc58813cb Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:06:44 +0800 Subject: [PATCH 6/9] Create floyd.cpp --- .ACM-Templates/floyd.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .ACM-Templates/floyd.cpp diff --git a/.ACM-Templates/floyd.cpp b/.ACM-Templates/floyd.cpp new file mode 100644 index 0000000..c37f08a --- /dev/null +++ b/.ACM-Templates/floyd.cpp @@ -0,0 +1,18 @@ +for(int k=1;k<=n;k++) +{ + for(int f=1;f<=n;f++) + { + for(int t=1;t<=n;t++) + { + if(f==t||f==k||t==k) continue; + if(m[f][k]!=INF&&m[k][t]!=INF) + { + int total=m[f][k]+m[k][t]; + if(total Date: Thu, 11 Aug 2016 09:07:22 +0800 Subject: [PATCH 7/9] Create isPrime.cpp --- .ACM-Templates/isPrime.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .ACM-Templates/isPrime.cpp diff --git a/.ACM-Templates/isPrime.cpp b/.ACM-Templates/isPrime.cpp new file mode 100644 index 0000000..04ac238 --- /dev/null +++ b/.ACM-Templates/isPrime.cpp @@ -0,0 +1,20 @@ +//Written by Coffee. 判断素数 +bool isPrime(int num) +{ + if (num == 2 || num == 3) + { + return true; + } + if (num % 6 != 1 && num % 6 != 5) + { + return false; + } + for (int i = 5; i*i <= num; i += 6) + { + if (num % i == 0 || num % (i+2) == 0) + { + return false; + } + } + return true; +} From b5c465a0f72c2e87b695b0a74dbda9b4f04b2933 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:11:03 +0800 Subject: [PATCH 8/9] Create 1698_libin56842.cpp From http://blog.csdn.net/libin56842/article/details/13511181 --- HDOJ/1698_libin56842.cpp | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 HDOJ/1698_libin56842.cpp diff --git a/HDOJ/1698_libin56842.cpp b/HDOJ/1698_libin56842.cpp new file mode 100644 index 0000000..a43871f --- /dev/null +++ b/HDOJ/1698_libin56842.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +using namespace std; +const int maxn = 100000+10; + +int n,sum; + +struct node +{ + int l,r,n; +} a[maxn<<2]; + +void init(int l,int r,int i) +{ + a[i].l = l; + a[i].r = r; + a[i].n = 1; + if(l!=r) + { + int mid = (l+r)>>1; + init(l,mid,2*i); + init(mid+1,r,2*i+1); + } +} + +void insert(int i,int x,int y,int m) +{ + if(a[i].n == m)//相同则不用修改了 + return ; + if(a[i].l == x && a[i].r == y)//找到了区间,直接更新 + { + a[i].n = m; + return ; + } + if(a[i].n != -1)//如果该区间只有一种颜色 + { + a[2*i].n = a[2*i+1].n = a[i].n;//由于后面必定对子树操作,所以更新子树的值等于父亲的值 + a[i].n = -1;//由于该区域颜色与修改不同,而且不是给定区域,所以该区域必定为杂色 + } + //父区间为杂色时对所有子节点进行操作 + int mid = (a[i].l+a[i].r)>>1; + if(x>mid) + insert(2*i+1,x,y,m); + else if(y<=mid) + insert(2*i,x,y,m); + else + { + insert(2*i,x,mid,m); + insert(2*i+1,mid+1,y,m); + } +} + +int find(int i)//区间求和 +{ + if(a[i].n != -1)//纯色直接算这个区间 + return (a[i].r - a[i].l+1)*a[i].n; + else//不存则左右子树去找 + return find(i*2)+find(i*2+1); +} + +int main() +{ + int t,i,k,x,y,m; + int cas = 1; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&k); + init(1,n,1); + while(k--) + { + scanf("%d%d%d",&x,&y,&m); + insert(1,x,y,m); + } + printf("Case %d: The total value of the hook is %d.\n",cas++,find(1)); + } + + return 0; +} From 85716f1888b4c047c38aa159388090e4854b19fc Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:23:15 +0800 Subject: [PATCH 9/9] Create 1698_chendl111.cpp From http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=28786&messageid=1&deep=0 --- HDOJ/1698_chendl111.cpp | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 HDOJ/1698_chendl111.cpp diff --git a/HDOJ/1698_chendl111.cpp b/HDOJ/1698_chendl111.cpp new file mode 100644 index 0000000..5e2475e --- /dev/null +++ b/HDOJ/1698_chendl111.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; +#define lchild rt << 1, l, m +#define rchild rt << 1 | 1, m + 1, r +const int N=400010; +int tree[N],lazy[N],t,ans=1,L,R,delta,n,m; + +//区间求和 +void push_up(int rt){ + tree[rt]=tree[rt << 1]+tree[rt << 1 | 1]; +} + +void push_down(int rt, int len) { + if(lazy[rt]) + { + lazy[rt << 1]=lazy[rt << 1 | 1] = lazy[rt]; + tree[rt << 1] = lazy[rt << 1] * (len - (len >> 1)); + tree[rt << 1 | 1] = lazy[rt << 1 | 1] * (len >> 1); + lazy[rt] = 0; + } +} + +void build(int rt = 1, int l = 1, int r = n) { + lazy[rt]=0; + if (l == r) { tree[rt]=1; return; }//注意对树的初始赋值 + int m = (l + r) >> 1; + build(lchild); build(rchild); + push_up(rt); +} + +void update(int L, int R, int delta, int rt = 1, int l = 1, int r = n) { + if (L <= l && r <= R) { + tree[rt] = delta * (r - l + 1);//数据更新 + lazy[rt] = delta; + return; + } + push_down(rt, r - l + 1); + int m = (l + r) >> 1; + if (L <= m) update(L, R, delta, lchild); + if (R > m) update(L, R, delta, rchild); + push_up(rt); +} + +int main() +{ + for(scanf("%d",&t);t--;) + { + scanf("%d%d",&n,&m); + build(); + for(int i=0;i