From ca790e2a6367e4fee2546618365fcbb28431f891 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 20 Apr 2016 18:04:36 +0800 Subject: [PATCH 01/30] Create 3190.cpp --- POJ/3190.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 POJ/3190.cpp diff --git a/POJ/3190.cpp b/POJ/3190.cpp new file mode 100644 index 0000000..2615acb --- /dev/null +++ b/POJ/3190.cpp @@ -0,0 +1,74 @@ + +#include +#include +#include +#include +using namespace std; + + +struct cow +{ + int start,over; + int pos; + bool operator <(const cow& b) const + { + if(over==b.over) + return start>b.start; + return over>b.over; + } +}; + +bool cmp(const cow& a,const cow& b) +{ + if(a.start==b.start) return a.over bus; +int use[50001]; +cow cowx[50001]; + +int cnt=1; + +int main() +{ + int n; + while(scanf("%d",&n)==1) + { + + for(int i=0; i Date: Wed, 20 Apr 2016 18:05:41 +0800 Subject: [PATCH 02/30] From CSDN From http://blog.csdn.net/z309241990/article/details/19566625 --- POJ/3190_csdn.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 POJ/3190_csdn.cpp diff --git a/POJ/3190_csdn.cpp b/POJ/3190_csdn.cpp new file mode 100644 index 0000000..af8f42a --- /dev/null +++ b/POJ/3190_csdn.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +using namespace std; +const int maxn=60000; +int n,use[maxn]; +struct Node +{ + int l; + int r; + int pos; + bool operator <(const Node &a)const + { + if(r==a.r) + return l>a.l; + return r>a.r; + } +}a[maxn]; +priority_queue q; +bool cmp(Node a,Node b) +{ + if(a.l==b.l) + return a.r Date: Wed, 20 Apr 2016 21:15:34 +0800 Subject: [PATCH 03/30] From www.aiuxian.com http://www.aiuxian.com/article/p-2049140.html --- POJ/3040_aiuxian.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 POJ/3040_aiuxian.cpp diff --git a/POJ/3040_aiuxian.cpp b/POJ/3040_aiuxian.cpp new file mode 100644 index 0000000..7277aea --- /dev/null +++ b/POJ/3040_aiuxian.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +using namespace std; +const int maxn=30; +struct node +{ + int x,y;//存储钱的大小和数量 + bool operator<(const node c)const + { + return x>c.x; + } +}num[maxn]; +int need[maxn],n,c,kj; +//need[]函数是是存储需要哪些钱币的组合 +int main() +{ + while(scanf("%d%d",&n,&c)!=EOF) + { + for(int i=0;i0) + { + int t=sum/num[i].x; + if(t==0) + continue; + t=min(t,num[i].y); + need[i]=t; + sum-=t*num[i].x; + } + } + + if(sum>0)//如果在上面的组合中没有使sum变为0,则从小到大选择最小的面值组合,这样使面值超过的最小化 + { + for(int i=n-1;i>=0;i--) + if(num[i].y&&num[i].x>=sum) + { + sum=0; + need[i]++; + break; + } + } + if(sum>0)//如果组合不能达到c,怎么说明搜索结束 + break; + int cc=2e9; + for(int i=n-1;i>=0;i--)//找出这个组合成的面值中最小的数量,同时减去它们。 + { + if(need[i]) + { + cc=min(cc,num[i].y/need[i]); + } + } + kj+=cc; + for(int i=0;i Date: Thu, 21 Apr 2016 09:32:57 +0800 Subject: [PATCH 04/30] From http://www.tuicool.com/articles/i2y2ma --- POJ/3040_tuicool.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 POJ/3040_tuicool.cpp diff --git a/POJ/3040_tuicool.cpp b/POJ/3040_tuicool.cpp new file mode 100644 index 0000000..2cc1eb2 --- /dev/null +++ b/POJ/3040_tuicool.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +const int INF=0x3f3f3f3f; +using namespace std; + +struct node +{ + int val,mou;//面值和数目 +} mon[25]; +int n,c; +int need[25];//一种方案所需各面值的数目 +bool cmp(node a,node b) +{ + return a.val=0;i--) + if(mon[i].val>=c)//如果面值大于c直接加数目就行了 + ans+=mon[i].mou; + else + { + lim=i; + break; + } + while(1) + { + memset(need,0,sizeof need); + rest=c; + for(i=lim;i>=0;i--)//尽可能用大面值凑够 + { + if(!mon[i].mou||!rest) + continue; + ti=rest/mon[i].val; + ti=min(ti,mon[i].mou); + need[i]=ti; + rest-=ti*mon[i].val; + } + if(rest)//没凑够的话。只能往回找最小的面值凑够。保证损失的钱最少 + { + for(i=0;i<=lim;i++) + { + if(mon[i].val>=rest&&(mon[i].mou-need[i])) + { + need[i]++; + rest=0; + break; + } + } + if(rest) + break; + } + mday=INF; + for(i=0;i<=lim;i++) + if(need[i]) + mday=min(mday,mon[i].mou/need[i]);//得出该种方案能支付的最大周数 + ans+=mday; + for(i=0;i<=lim;i++) + mon[i].mou-=mday*need[i]; + } + printf("%d\n",ans); + } + return 0; +} +/* +11 +6 1 +4 1 +*/ From f44a9ff3b7e3b8d014a0d9e98ba4aa540a36c720 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 09:36:07 +0800 Subject: [PATCH 05/30] From www.hankcs.com/program/cpp/poj-3040-allowance.html --- POJ/3040_hankcs.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 POJ/3040_hankcs.cpp diff --git a/POJ/3040_hankcs.cpp b/POJ/3040_hankcs.cpp new file mode 100644 index 0000000..caa36f3 --- /dev/null +++ b/POJ/3040_hankcs.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +using namespace std; + +typedef pair Coin; // 硬币 面值和数量 +Coin coin[20]; +int need[20]; + +///////////////////////////SubMain////////////////////////////////// +int main(int argc, char *argv[]) +{ +#ifndef ONLINE_JUDGE + freopen("in.txt", "r", stdin); + freopen("out.txt", "w", stdout); +#endif + int N, C; + cin >> N >> C; + for (int i = 0; i < N; ++i) + { + cin >> coin[i].first >> coin[i].second; + } + int week = 0; + // 面额不小于C的一定可以支付一周 + for (int i = 0; i < N; ++i) + { + if (coin[i].first >= C) + { + week += coin[i].second; + coin[i].second = 0; + } + } + sort(coin, coin + N, greater()); + while(true) + { + int sum = C; // 等待凑足的sum + memset(need, 0, sizeof(need)); + // 从大到小 + for (int i = 0; i < N; ++i) + { + if (sum > 0 && coin[i].second > 0) + { + int can_use = min(coin[i].second, + sum / coin[i].first); + if (can_use > 0) + { + sum -= can_use * coin[i].first; + need[i] = can_use; + } + } + } + // 从小到大 + for (int i = N - 1; i >= 0; --i) + { + if (sum > 0 && coin[i].second > 0) + { + int can_use = min(coin[i].second - need[i], // 上个loop用掉了一些 + (sum + coin[i].first - 1) / coin[i].first); // 允许多出不超过一个面值的金额 + if (can_use > 0) + { + sum -= can_use * coin[i].first; + need[i] += can_use; + } + } + } + + if(sum > 0) + { + break; + } + + int add_up = numeric_limits::max(); // 凑起来的week数 + // add_up多少个最优的week 受限于 每种面值能满足最优解下的需求个数多少次 + for (int i = 0; i < N; ++i) + { + if (need[i] == 0) + { + continue; + } + add_up = min(add_up, coin[i].second / need[i]); + } + week += add_up; + // 最优解生效,更新剩余硬币数量 + for (int i = 0; i < N; ++i) + { + if (need[i] == 0) + { + continue; + } + coin[i].second -= add_up * need[i]; + } + } + cout << week << endl; +#ifndef ONLINE_JUDGE + fclose(stdin); + fclose(stdout); + system("out.txt"); +#endif + return 0; +} +///////////////////////////End Sub////////////////////////////////// From a83f2973119d6388cd524ff7170730326e334b0f Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 10:26:40 +0800 Subject: [PATCH 06/30] Create 3040.cpp --- POJ/3040.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 POJ/3040.cpp diff --git a/POJ/3040.cpp b/POJ/3040.cpp new file mode 100644 index 0000000..e8bb9a8 --- /dev/null +++ b/POJ/3040.cpp @@ -0,0 +1,105 @@ +#include +#include +#include + +#include +#include +using namespace std; + +struct cash +{ + int value; + int amount; +}; + +bool cmp(const cash& a,const cash& b) +{ + return a.value& vec,int C) +{ + memset(need,0,sizeof(int)*64); + int N=vec.size(); + int left=C; + for(int i=N-1;i>=0;i--) + {// + if(vec.at(i).amount>0&&left>0) + { + int x=left/vec.at(i).value; + x=min(x,vec.at(i).amount); + need[i]=x; + left-=x*vec.at(i).value; + } + } + if(left>0) + { + for(int i=0;ineed[i]&&left>0) + { + int x=left/vec.at(i).value; + if(x==0) + { + /// try to make x = 1 + need[i]++; + left=0; + break; + } + } + } + } + if(left>0) + { + return -1; + } + int canpayday=2<<29; + for(int i=0;i<64;i++) + { + if(need[i]>0) + { + canpayday=min(canpayday,vec.at(i).amount/need[i]); + } + } + if(canpayday<=0) return -1; + for(int i=0;i0) + { + vec.at(i).amount-=canpayday*need[i]; + } + } + return canpayday; + +} +int main() +{ + int N,C; + scanf("%d %d",&N,&C); + vector vec; + int ans=0; + for(int i=0;i=0;i--) + { + if(vec.at(i).value>=C) + { + ans+=vec.at(i).amount; + vec.pop_back(); + } + else break; + } + int tmp; + while((tmp=makedayfrom(vec,C))>0) + { + ans+=tmp; + } + printf("%d\n",ans); + return 0; +} From a6318e28643b744c1ad8657d406f4ade51017a4f Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 11:05:00 +0800 Subject: [PATCH 07/30] Create 1166.cpp --- HDOJ/1166.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 HDOJ/1166.cpp diff --git a/HDOJ/1166.cpp b/HDOJ/1166.cpp new file mode 100644 index 0000000..33f2e73 --- /dev/null +++ b/HDOJ/1166.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +using namespace std; + + +int C[131072]; + +char cmd[32]; + +int getsum(int left,int right,int pos,int leftbound,int rightbound) +{ + if(left<=leftbound&&right>=rightbound) + { + return C[pos]; + } + if(rightrightbound) + { + return 0; + } + int a=getsum(left,right,2*pos+1,leftbound,(leftbound+rightbound)/2); + int b=getsum(left,right,2*pos+2,(leftbound+rightbound)/2+1,rightbound); + return a+b; +} +int main() +{ + int t; + scanf("%d",&t); + for(int itt=1;itt<=t;itt++) + { + printf("Case %d:\n",itt); + int N; + scanf("%d",&N); + int realn=1; + while(realn0) + { + int L=start+1; + for(int i=0;i0) + { + C[pos]+=b; + pos=(pos-1)/2; + } + C[0]+=b; + } + else if(strcmp(cmd,"Sub")==0) + { + int pos=realn-1+a-1; + while(pos>0) + { + C[pos]-=b; + pos=(pos-1)/2; + } + C[0]-=b; + } + } + }/// end of for(...) + + return 0; +} From 307c7181362bef62ebb922c732eeab8afca9eb8d Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 18:38:06 +0800 Subject: [PATCH 08/30] Create 1501_dp.cpp --- HDOJ/1501_dp.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 HDOJ/1501_dp.cpp diff --git a/HDOJ/1501_dp.cpp b/HDOJ/1501_dp.cpp new file mode 100644 index 0000000..e08bab4 --- /dev/null +++ b/HDOJ/1501_dp.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; + +char a[300]; +char b[300]; +char c[700]; + +int lena,lenb,lenc; +bool dfs(int pos_in_a,int pos_in_b,int pos_in_c) +{ + if(pos_in_a==lena&&pos_in_b==lenb) + { + return true; + } + if(pos_in_a Date: Thu, 21 Apr 2016 18:38:36 +0800 Subject: [PATCH 09/30] Create 1501_CSDN_dp.cpp --- HDOJ/1501_CSDN_dp.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 HDOJ/1501_CSDN_dp.cpp diff --git a/HDOJ/1501_CSDN_dp.cpp b/HDOJ/1501_CSDN_dp.cpp new file mode 100644 index 0000000..c41f7c0 --- /dev/null +++ b/HDOJ/1501_CSDN_dp.cpp @@ -0,0 +1,42 @@ +#include +#include +//#define LOCAL +using namespace std; + +const int MAXN=205; + +char a[MAXN],b[MAXN],all[2*MAXN-5]; +int lenA,lenB,lenAll; + +bool DFS(int posA,int posB,int posAll) { + if(posA==lenA&&posB==lenB) + return true; + if(posA Date: Thu, 21 Apr 2016 18:38:53 +0800 Subject: [PATCH 10/30] Rename 1501_dp.cpp to 1501_dfs.cpp --- HDOJ/{1501_dp.cpp => 1501_dfs.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename HDOJ/{1501_dp.cpp => 1501_dfs.cpp} (100%) diff --git a/HDOJ/1501_dp.cpp b/HDOJ/1501_dfs.cpp similarity index 100% rename from HDOJ/1501_dp.cpp rename to HDOJ/1501_dfs.cpp From b9ab362dcf631b9cf31b70d42f57060f67e852e1 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 18:39:11 +0800 Subject: [PATCH 11/30] Rename 1501_CSDN_dp.cpp to 1501_CSDN_dfs.cpp --- HDOJ/{1501_CSDN_dp.cpp => 1501_CSDN_dfs.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename HDOJ/{1501_CSDN_dp.cpp => 1501_CSDN_dfs.cpp} (100%) diff --git a/HDOJ/1501_CSDN_dp.cpp b/HDOJ/1501_CSDN_dfs.cpp similarity index 100% rename from HDOJ/1501_CSDN_dp.cpp rename to HDOJ/1501_CSDN_dfs.cpp From 6a7fed60f867b862d67b57c41ceecb01c886816b Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 18:39:51 +0800 Subject: [PATCH 12/30] From http://blog.csdn.net/idealism_xxm/article/details/51204130 --- HDOJ/1501_CSDN_dp.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 HDOJ/1501_CSDN_dp.cpp diff --git a/HDOJ/1501_CSDN_dp.cpp b/HDOJ/1501_CSDN_dp.cpp new file mode 100644 index 0000000..b43ab5e --- /dev/null +++ b/HDOJ/1501_CSDN_dp.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +using namespace std; + +int n,m,al,bl,cl,lim; +char a[205],b[205],c[405]; +bool dp[205][205];//dp[i][j]表示串a的前i个字符与串b的前j个字符是否能形成串c的前i+j个字符 + +int main() { + int T,kase=0; + scanf("%d",&T); + while(kase Date: Thu, 21 Apr 2016 18:54:53 +0800 Subject: [PATCH 13/30] change the language link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df833c6..ca10f9c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[English](https://github.com/Kiritow/OJ-Problems-Source#oj-problems-source) | [中文(简体)](https://github.com/Kiritow/OJ-Problems-Source#oj问题源代码) +[English](oj-problems-source) | [中文(简体)](#oj问题源代码) # OJ-Problems-Source Source of **AC** Problems on different OJ. If you want to publish your source file, just contact me via GitHub~ From 383b9c2109c2ef281aa819b99d7f7e5b6257dd16 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 21 Apr 2016 18:55:29 +0800 Subject: [PATCH 14/30] Link error fixed. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca10f9c..fb9b763 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[English](oj-problems-source) | [中文(简体)](#oj问题源代码) +[English](#oj-problems-source) | [中文(简体)](#oj问题源代码) # OJ-Problems-Source Source of **AC** Problems on different OJ. If you want to publish your source file, just contact me via GitHub~ From 276cd4f62c6504917bcdd36ec21021b435de5d7a Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 26 Apr 2016 21:12:25 +0800 Subject: [PATCH 15/30] Create 1078.cpp --- HDOJ/1078.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 HDOJ/1078.cpp diff --git a/HDOJ/1078.cpp b/HDOJ/1078.cpp new file mode 100644 index 0000000..113de59 --- /dev/null +++ b/HDOJ/1078.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +using namespace std; +#define MAXN 101 +int map[MAXN][MAXN]; +int dp[MAXN][MAXN]; +int N; +int K; +int dfs(int y,int x) +{ + if(dp[y][x]!=0) return dp[y][x]; + dp[y][x]=map[y][x]; + for(int i=1;i<=K;i++) + { + if(x+i=0&&map[y][x]=0&&map[y][x] Date: Wed, 27 Apr 2016 10:03:22 +0800 Subject: [PATCH 16/30] Create Readme.md --- SDUSTOJ/Readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 SDUSTOJ/Readme.md diff --git a/SDUSTOJ/Readme.md b/SDUSTOJ/Readme.md new file mode 100644 index 0000000..c11496d --- /dev/null +++ b/SDUSTOJ/Readme.md @@ -0,0 +1,2 @@ +#山东科技大学 SDUSTOJ +[Goto SDUSTOJ Home Page (May be changed since last update)](http://acm.zning.net/JudgeOnline/ "Welcome to SDUSTOJ") From e1c9886f17e038fb6ebad620040d5b48241e2955 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 10:16:55 +0800 Subject: [PATCH 17/30] Create 1802.cpp --- SDUSTOJ/1802.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 SDUSTOJ/1802.cpp diff --git a/SDUSTOJ/1802.cpp b/SDUSTOJ/1802.cpp new file mode 100644 index 0000000..5e6c2ec --- /dev/null +++ b/SDUSTOJ/1802.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +using namespace std; +/* +bool check(int inc) +{ + if(inc%36!=0) return false; + char buff[32]; + memset(buff,0,32); + sprintf(buff,"%d",inc); + if(strstr(buff,"36")==NULL) return false; + int len=strlen(buff); + for(int i=0;i Date: Wed, 27 Apr 2016 10:33:29 +0800 Subject: [PATCH 18/30] From http://www.cnblogs.com/d-e-v-i-l/p/5436755.html --- SDUSTOJ/1800_cnblogs.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 SDUSTOJ/1800_cnblogs.cpp diff --git a/SDUSTOJ/1800_cnblogs.cpp b/SDUSTOJ/1800_cnblogs.cpp new file mode 100644 index 0000000..ee07cf3 --- /dev/null +++ b/SDUSTOJ/1800_cnblogs.cpp @@ -0,0 +1,50 @@ +/* *********************************************** +Author :devil +Created Time :2016/4/26 21:58:52 +************************************************ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int N=1010; +int dp[N],a[N],b[N],c[N]; +int main() +{ + //freopen("in.txt","r",stdin); + int t,n; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + for(int i=1; i<=n; i++) + scanf("%d",&a[i]); + int ma=0; + memset(c,0,sizeof(c)); + c[1]=n; + for(int i=1; i<=n; i++) + { + b[i]=dp[i]=1; + for(int j=1; ja[j]&&dp[i]a[j]&&dp[i]==dp[j]+1) b[i]+=b[j]; + } + if(dp[i]>1) c[dp[i]]+=b[i]; + ma=max(ma,dp[i]); + } + printf("%d\n",c[ma]); + } + return 0; +} From f7fe7391033fd0cb90acdcc2501257eff68c0dd8 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 10:34:30 +0800 Subject: [PATCH 19/30] From http://www.cnblogs.com/d-e-v-i-l/p/5437027.html --- SDUSTOJ/1799_cnblogs.cpp | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 SDUSTOJ/1799_cnblogs.cpp diff --git a/SDUSTOJ/1799_cnblogs.cpp b/SDUSTOJ/1799_cnblogs.cpp new file mode 100644 index 0000000..5a1a99b --- /dev/null +++ b/SDUSTOJ/1799_cnblogs.cpp @@ -0,0 +1,93 @@ +/* *********************************************** +Author :devil +Created Time :2016/4/26 22:47:45 +************************************************ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define inf 0x3f3f3f3f +#define maxn 1010 +struct node +{ + int v,d; + node(int a=0,int b=0):v(a),d(b){} + bool operator < (const node &a) const + { + return d>a.d; + } +}; +struct edge +{ + int v,cost; + edge(int a=0,int b=0):v(a),cost(b){} +}; +vector eg[maxn]; +bool vis[maxn]; +int n,m,s,a,b,t,c,dis[maxn],ss[maxn],tt[maxn]; +void dijkstra(int x) +{ + memset(vis,false,sizeof(vis)); + for(int i=0; i<=n; i++) + dis[i]=inf; + priority_queueq; + while(!q.empty()) q.pop(); + dis[x]=0; + q.push(node(x,0)); + node tmp; + while(!q.empty()) + { + tmp=q.top(); + q.pop(); + int u=tmp.v; + if(vis[u]) continue; + vis[u]=true; + for(int i=0; idis[u]+cost) + { + dis[v]=dis[u]+cost; + q.push(node(v,dis[v])); + } + } + } +} +int main() +{ + //freopen("in.txt","r",stdin); + while(~scanf("%d%d%d%d",&n,&m,&s,&t)&&n) + { + for(int i=1;i<=n;i++) + eg[i].clear(); + while(m--) + { + scanf("%d%d%d",&a,&b,&c); + eg[a].push_back(edge(b,c)); + eg[b].push_back(edge(a,c)); + } + for(int i=1;i<=s;i++) + scanf("%d",&ss[i]); + for(int i=1;i<=t;i++) + scanf("%d",&tt[i]); + int ans=inf; + for(int i=1;i<=s;i++) + { + dijkstra(ss[i]); + for(int j=1;j<=t;j++) + ans=min(ans,dis[tt[j]]); + } + if(ans!=inf) printf("%d\n",ans); + else printf("What a pity!\n"); + } + return 0; +} From ef090cad703ee582a24c0f06e435e5c4d3896b73 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 10:35:10 +0800 Subject: [PATCH 20/30] From http://www.cnblogs.com/d-e-v-i-l/p/5436931.html --- SDUSTOJ/1801.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 SDUSTOJ/1801.cpp diff --git a/SDUSTOJ/1801.cpp b/SDUSTOJ/1801.cpp new file mode 100644 index 0000000..ecfca56 --- /dev/null +++ b/SDUSTOJ/1801.cpp @@ -0,0 +1,62 @@ +/* *********************************************** +Author :devil +Created Time :2016/4/26 22:18:57 +************************************************ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const int N=110; +const int mod=1e9+9; +LL dp[N][N],dp2[N][N]; +int a[N],b[N]; +int main() +{ + //freopen("in.txt","r",stdin); + int t,n,m; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&n,&m); + for(int i=1; i<=n; i++) + scanf("%d",&a[i]); + memset(dp,0,sizeof(dp)); + memset(dp2,0,sizeof(dp2)); + memset(b,-1,sizeof(b)); + b[a[1]]=dp[a[1]][1]=1; + for(int i=2;i<=n;i++) + { + dp[a[i]][1]=1; + int mi=min(i,m); + for(int k=2;k<=mi;k++) + { + for(int j=1;j=mod) dp[a[i]][k]-=mod; + } + if(b[a[i]]!=-1) + { + dp[a[i]][k]-=dp2[a[i]][k]; + if(dp[a[i]][k]<0) dp[a[i]][k]+=mod; + } + dp2[a[i]][k]=dp[a[i]][k]; + } + b[a[i]]=i; + } + LL ans=0; + for(int i=1;i<=n;i++) + ans=(ans+dp[i][m])%mod; + printf("%lld\n",ans); + } + return 0; +} From 2a7e7a9508e5d2a222a23a5d02328a5609893c69 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 10:35:50 +0800 Subject: [PATCH 21/30] From http://www.cnblogs.com/d-e-v-i-l/p/5436931.html --- SDUSTOJ/{1801.cpp => 1801_cnblogs.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename SDUSTOJ/{1801.cpp => 1801_cnblogs.cpp} (100%) diff --git a/SDUSTOJ/1801.cpp b/SDUSTOJ/1801_cnblogs.cpp similarity index 100% rename from SDUSTOJ/1801.cpp rename to SDUSTOJ/1801_cnblogs.cpp From 21a0f270efb456348863a6c4087f025d10210359 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 10:37:04 +0800 Subject: [PATCH 22/30] From http://www.cnblogs.com/d-e-v-i-l/p/5435509.html --- SDUSTOJ/1795_cnblogs.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 SDUSTOJ/1795_cnblogs.cpp diff --git a/SDUSTOJ/1795_cnblogs.cpp b/SDUSTOJ/1795_cnblogs.cpp new file mode 100644 index 0000000..dd17618 --- /dev/null +++ b/SDUSTOJ/1795_cnblogs.cpp @@ -0,0 +1,53 @@ +/* *********************************************** +Author :devil +Created Time :2016/4/26 16:10:39 +************************************************ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +const int N=2e6+7; +int a[N],b[N]; +long long sum[N]; +int main() +{ + //freopen("in.txt","r",stdin); + int n,x; + while(~scanf("%d",&n)) + { + int ma=0; + memset(a,0,sizeof(a)); + memset(b,0,sizeof(b)); + memset(sum,0,sizeof(sum)); + for(int i=0;i Date: Wed, 27 Apr 2016 10:39:46 +0800 Subject: [PATCH 23/30] From http://www.cnblogs.com/d-e-v-i-l/p/5434713.html --- SDUSTOJ/1796_cnblogs.cpp | 128 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 SDUSTOJ/1796_cnblogs.cpp diff --git a/SDUSTOJ/1796_cnblogs.cpp b/SDUSTOJ/1796_cnblogs.cpp new file mode 100644 index 0000000..9a2acdb --- /dev/null +++ b/SDUSTOJ/1796_cnblogs.cpp @@ -0,0 +1,128 @@ +/* *********************************************** +Author :devil +Created Time :2016/4/26 13:11:52 +************************************************ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int N=100005; +int n,a[N],b[N],tree[N<<2]; +void build1(int node,int l,int r) +{ + if(l==r) + { + tree[node]=N; + return ; + } + int m=(l+r)>>1; + build1(node<<1,l,m); + build1(node<<1|1,m+1,r); + tree[node]=min(tree[node<<1],tree[node<<1|1]); +} +void update1(int node,int l,int r,int p) +{ + if(l==r) + { + tree[node]=b[p]; + return ; + } + int m=(l+r)>>1; + if(a[p]<=m) update1(node<<1,l,m,p); + else update1(node<<1|1,m+1,r,p); + tree[node]=min(tree[node<<1],tree[node<<1|1]); +} +int query1(int node,int l,int r,int p) +{ + if(l>=p) return tree[node]; + int m=(l+r)>>1,ans; + ans=query1(node<<1|1,m+1,r,p); + if(p<=m) ans=min(ans,query1(node<<1,l,m,p)); + return ans; +} +void build2(int node,int l,int r) +{ + if(l==r) + { + tree[node]=0; + return ; + } + int m=(l+r)>>1; + build2(node<<1,l,m); + build2(node<<1|1,m+1,r); + tree[node]=max(tree[node<<1],tree[node<<1|1]); +} +void update2(int node,int l,int r,int p) +{ + if(l==r) + { + tree[node]=b[p]; + return ; + } + int m=(l+r)>>1; + if(a[p]<=m) update2(node<<1,l,m,p); + else update2(node<<1|1,m+1,r,p); + tree[node]=max(tree[node<<1],tree[node<<1|1]); +} +int query2(int node,int l,int r,int p) +{ + if(r<=p) return tree[node]; + int m=(l+r)>>1,ans; + ans=query2(node<<1,l,m,p); + if(p>m) ans=max(ans,query2(node<<1|1,m+1,r,p)); + return ans; +} +int main() +{ + //freopen("in.txt","r",stdin); + while(~scanf("%d",&n)) + { + int x,flag=1; + for(int i=1; i<=n; i++) + { + scanf("%d",&x); + a[x]=i; + } + for(int i=1; i<=n; i++) + { + scanf("%d",&x); + b[x]=i; + } + build1(1,1,n); + for(int i=n; i>0; i--) + { + if(a[i]<=b[i]&&b[i]>query1(1,1,n,a[i])) + { + flag=0; + break; + } + update1(1,1,n,i); + } + if(!flag) + { + printf("NO\n"); + continue; + } + build2(1,1,n); + for(int i=1; i<=n; i++) + { + if(a[i]>=b[i]&&b[i] Date: Wed, 27 Apr 2016 11:34:03 +0800 Subject: [PATCH 24/30] Create Readme.md --- TYVJ/Readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 TYVJ/Readme.md diff --git a/TYVJ/Readme.md b/TYVJ/Readme.md new file mode 100644 index 0000000..9bbda89 --- /dev/null +++ b/TYVJ/Readme.md @@ -0,0 +1,2 @@ +#太原成成中学 TYVJ +[Goto Home Page](http://www.tyvj.cn/ "Welcome to TYVJ 4.0") From 3d1c87a825582f827e83b76903e7982ba4b48285 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 11:35:56 +0800 Subject: [PATCH 25/30] Create 1403.cpp --- TYVJ/1403.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 TYVJ/1403.cpp diff --git a/TYVJ/1403.cpp b/TYVJ/1403.cpp new file mode 100644 index 0000000..840b165 --- /dev/null +++ b/TYVJ/1403.cpp @@ -0,0 +1,40 @@ +#include +#include +using namespace std; +int n,m,f[40001],x,y; +struct data +{ +int a,b,c; +}e[100001]; +int gz(const data &a,const data &b) +{ + if(a.c>b.c)return 1; + else return 0; +} +int find(int x) +{ + return f[x]==x?x:f[x]=find(f[x]); +} +int main() +{ + cin>>n>>m; + for(int i=1;i<=m;i++) + cin>>e[i].a>>e[i].b>>e[i].c; + for(int i=1;i<=n*2;i++) + f[i]=i; + sort(e+1,e+m+1,gz); + for(int i=1;i<=m;i++) + { + x=find(e[i].a); + y=find(e[i].b); + if(x==y) + { + cout< Date: Wed, 27 Apr 2016 11:36:25 +0800 Subject: [PATCH 26/30] From http://hzwer.com/599.html --- TYVJ/{1403.cpp => 1403_hzwer.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TYVJ/{1403.cpp => 1403_hzwer.cpp} (100%) diff --git a/TYVJ/1403.cpp b/TYVJ/1403_hzwer.cpp similarity index 100% rename from TYVJ/1403.cpp rename to TYVJ/1403_hzwer.cpp From cf3a9090478c71ffd1714e3deff46f8b4a715da3 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 12:16:39 +0800 Subject: [PATCH 27/30] From http://blog.chinaunix.net/uid-25304689-id-349853.html --- TYVJ/1403_chinaunix.cpp | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 TYVJ/1403_chinaunix.cpp diff --git a/TYVJ/1403_chinaunix.cpp b/TYVJ/1403_chinaunix.cpp new file mode 100644 index 0000000..8f18da1 --- /dev/null +++ b/TYVJ/1403_chinaunix.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include + +using namespace std; + +const int M = 100000; +const int N = 20000; + +struct EDGE { + int a; + int b; + int v; +} edge[M]; + +int f[N * 2]; + +bool Compare(const EDGE &a, const EDGE &b) +{ + return a.v < b.v; +} + +int Find(int x) +{ + if (f[x] == x) { + return f[x]; + } else { + return f[x] = Find(f[x]); + } +} + +int main() +{ + int n, m; + + ios::sync_with_stdio(false); + + cin >> n; + cin >> m; + for (int i = 0; i < m; i++) { + cin >> edge[i].a; + cin >> edge[i].b; + cin >> edge[i].v; + } + + for (int i = 0; i < n * 2; i++) { + f[i] = i; + } + + sort(edge, edge + m, Compare); + + for (int i = m - 1; i >= 0; i--) { + int x = Find(edge[i].a); + int y = Find(edge[i].b); + + if (x == y) { + cout << edge[i].v << endl; + + return 0; + } + + int xx = Find(edge[i].a + n); + int yy = Find(edge[i].b + n); + + f[x] = yy; + f[y] = xx; + } + + cout << "0" << endl; + + return 0; +} From 3d9595270bb603f9e1ef33bc42116d491a32d7c1 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 16:17:02 +0800 Subject: [PATCH 28/30] Create 600.cpp --- RQNOJ/600.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 RQNOJ/600.cpp diff --git a/RQNOJ/600.cpp b/RQNOJ/600.cpp new file mode 100644 index 0000000..06c4289 --- /dev/null +++ b/RQNOJ/600.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +using namespace std; + +#define MAXM 100000 +#define MAXN 20000 +struct ppk +{ +    int a,b,c; +}; +bool cmp(const ppk& a,const ppk& b) +{ +    return a.c>b.c; +} +int f[MAXN*2]; +ppk X[MAXM]; + +int get(int x) +{ +    if(x==f[x]) return x; +    else +    { +        f[x]=get(f[x]); +        return f[x]; +    } +} + +int main() +{ +    int n,m; +    scanf("%d %d",&n,&m); +    for(int i=1;i<=n*2;i++) +    { +        f[i]=i; +    } +    for(int i=0;i Date: Wed, 27 Apr 2016 17:55:20 +0800 Subject: [PATCH 29/30] Create 1403.cpp --- TYVJ/1403.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 TYVJ/1403.cpp diff --git a/TYVJ/1403.cpp b/TYVJ/1403.cpp new file mode 100644 index 0000000..8c48852 --- /dev/null +++ b/TYVJ/1403.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +using namespace std; + +#define MAXM 100000 +#define MAXN 20000 +struct ppk +{ + int a,b,c; +}; +bool cmp(const ppk& a,const ppk& b) +{ + return a.c>b.c; +} +int f[MAXN*2]; +ppk X[MAXM]; + +int get(int x) +{ + if(x==f[x]) return x; + else + { + f[x]=get(f[x]); + return f[x]; + } +} + +int main() +{ + int n,m; + scanf("%d %d",&n,&m); + for(int i=1;i<=n*2;i++) + { + f[i]=i; + } + for(int i=0;i Date: Wed, 27 Apr 2016 17:57:31 +0800 Subject: [PATCH 30/30] Create Readme.md --- RQNOJ/Readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 RQNOJ/Readme.md diff --git a/RQNOJ/Readme.md b/RQNOJ/Readme.md new file mode 100644 index 0000000..6724f30 --- /dev/null +++ b/RQNOJ/Readme.md @@ -0,0 +1,2 @@ +#RenQing Net Online Judge (RQNOJ) +[RQNOJ Home Page](http://www.rqnoj.cn/ "Welcome to RQNOJ")