From c792923c7fce1f8ecd38a333c13d67f6b377f16d Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 3 May 2016 14:52:51 +0800 Subject: [PATCH 01/11] Create 1879.cpp --- HDOJ/1879.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 HDOJ/1879.cpp diff --git a/HDOJ/1879.cpp b/HDOJ/1879.cpp new file mode 100644 index 0000000..6d0c10b --- /dev/null +++ b/HDOJ/1879.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +#define MAXN 105 +int father[MAXN]; +int noderank[MAXN]; + +void init() +{ + for(int i=0;inoderank[fb]) + { + father[fb]=fa; + } + else + { + father[fa]=fb; + if(noderank[fa]==noderank[fb]) + { + noderank[fb]++; + } + } +} + +struct pack +{ + int a,b,v; +}; +#define MAXM 5000 +pack pk[MAXM]; + +bool cmp(const pack& a,const pack& b) +{ + return a.v Date: Tue, 3 May 2016 15:30:25 +0800 Subject: [PATCH 02/11] Create 4786_cnblogs.cpp From http://www.cnblogs.com/Canon-CSU/p/3426977.html --- HDOJ/4786_cnblogs.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 HDOJ/4786_cnblogs.cpp diff --git a/HDOJ/4786_cnblogs.cpp b/HDOJ/4786_cnblogs.cpp new file mode 100644 index 0000000..afe505a --- /dev/null +++ b/HDOJ/4786_cnblogs.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#define maxn 100100 +using namespace std; + +struct edge{ + int u,v; +}a[2][maxn]; + +int s[2]; +int n,m,c,t,uu,vv,cc,MM,mm,cas=0; +int f[maxn],g[maxn]; +bool flag; + +void init() { for (int i=1; i<=n; i++) f[i]=i; } + +void build(int xx,int yy) { f[f[xx]]=f[yy]; } + +int getf(int x) +{ + if (f[x]!=x) f[x]=getf(f[x]); + return f[x]; +} + +void addedge(int x) +{ + int tot=0; + init(); + for (int i=1; i<=s[x]; i++) + if (getf(a[x][i].u)!=getf(a[x][i].v)) tot++,build(a[x][i].u,a[x][i].v); + if (x==0) mm=n-1-tot; + else MM=tot; +} + +int main() +{ + g[1]=1,g[2]=2; + for (int i=2; g[i]<=maxn; i++) g[i+1]=g[i]+g[i-1]; + scanf("%d",&t); + while (t--) + { + scanf("%d%d",&n,&m); + s[0]=s[1]=0; + for (int i=1; i<=m; i++) + { + scanf("%d%d%d",&uu,&vv,&cc); + a[cc][++s[cc]].u=uu; + a[cc][s[cc]].v=vv; + } + init(); + for (int i=1; i<=s[0]; i++) + if (getf(a[0][i].u)!=getf(a[0][i].v)) build(a[0][i].u,a[0][i].v); + for (int i=1; i<=s[1]; i++) + if (getf(a[1][i].u)!=getf(a[1][i].v)) build(a[1][i].u,a[1][i].v); + flag=true; + for (int i=2; i<=n; i++) + if (getf(i)!=getf(i-1)) { flag=false; break; } + if (!flag) + { + printf("Case #%d: No\n",++cas); + continue; + } + addedge(0),addedge(1); + //cout<<" MM && mm : " <=mm) { flag=true; break; } + if (flag) printf("Case #%d: Yes\n",++cas); + else printf("Case #%d: No\n",++cas); + } + return 0; +} From d6d048a9974f8f7f78426ecbb32263e839b343bb Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 4 May 2016 08:12:46 +0800 Subject: [PATCH 03/11] Create 1010_csdn.cpp From http://blog.csdn.net/hurmishine/article/details/51255092 --- HDOJ/1010_csdn.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 HDOJ/1010_csdn.cpp diff --git a/HDOJ/1010_csdn.cpp b/HDOJ/1010_csdn.cpp new file mode 100644 index 0000000..56390a8 --- /dev/null +++ b/HDOJ/1010_csdn.cpp @@ -0,0 +1,73 @@ +#include +#include +using namespace std; +char a[10][10]; +int n,m,t; +int sx,sy,ex,ey; +bool flag; +int dir[4][2]={0,1,1,0,0,-1,-1,0}; +int abs(int x) +{ + return x<0?-x:x; +} +void DFS(int x,int y,int time)//当前位置坐标(x,y),到目前位置消耗时间 +{ + if(x<0||x>=n||y<0||y>=m) + return; + if(x==ex&&y==ey&&time==t) + { + flag =true; + return ; + } + if(flag) + return; + int temp=(t-time)-(abs(x-ex)+abs(y-ey)); + if(temp<0||temp&1) + return; + for(int i=0;i<4;i++) + { + int xx=x+dir[i][0]; + int yy=y+dir[i][1]; + if(a[xx][yy]!='X') + { + a[xx][yy]='X'; + DFS(xx,yy,time+1); + a[xx][yy]='.'; + if(flag) + return ; + } + } +} +int main() +{ + while(cin>>n>>m>>t) + { + if(n==0&&m==0) + break; + int wall=0; + for(int i=0; i>a[i][j]; + if(a[i][j]=='S') + sx=i,sy=j; + else if(a[i][j]=='D') + ex=i,ey=j; + else if(a[i][j]=='X') + wall++; + } + if(n*m-wall<=t) + { + cout<<"NO"< Date: Wed, 4 May 2016 08:51:16 +0800 Subject: [PATCH 04/11] Create 1010.cpp --- HDOJ/1010.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 HDOJ/1010.cpp diff --git a/HDOJ/1010.cpp b/HDOJ/1010.cpp new file mode 100644 index 0000000..6cafe59 --- /dev/null +++ b/HDOJ/1010.cpp @@ -0,0 +1,130 @@ +/// TLE -> WA +#include +#include +#include +#include +using namespace std; + +#define MAXN 10 +#define MAXM 10 + +char map[MAXN][MAXM]; + +int N,M,T; + +inline void init() +{ + memset(map,0,MAXN*MAXM); +} + +inline bool checkmap() +{ + int wall=0; + for(int i=0;iN||y<1||y>M) return; + if(x==endx&&y==endy&&step==T) + { + endflag=true; + return; + } + /// TLE? Try this + int temp=T-step-(abs(endx-x)+abs(endy-y)); + if(temp<0||temp%2) + { + return; + } + if(map[x-1][y]=='.'||map[x-1][y]=='D') + { + map[x-1][y]='X'; + DFS(x-1,y,step+1); + map[x-1][y]='.'; + } + if(map[x+1][y]=='.'||map[x+1][y]=='D') + { + map[x+1][y]='X'; + DFS(x+1,y,step+1); + map[x+1][y]='.'; + } + if(map[x][y-1]=='.'||map[x][y-1]=='D') + { + map[x][y-1]='X'; + DFS(x,y-1,step+1); + map[x][y-1]='.'; + } + if(map[x][y+1]=='.'||map[x][y+1]=='D') + { + map[x][y+1]='X'; + DFS(x,y+1,step+1); + map[x][y+1]='.'; + } +} + + +int main() +{ + while(scanf("%d %d %d",&N,&M,&T)==3&&N+M+T!=0) + { + init(); + for(int i=1;i<=N;i++) + { + scanf("%s",&map[i][1]); + } + if(!checkmap()) + { + printf("NO\n"); + continue; + } + findSD(&startx,&starty,&endx,&endy); + endflag=false; + DFS(startx,starty,0); + if(endflag) + { + printf("YES\n"); + } + else + { + printf("NO\n"); + } + } + return 0; +} From 266f3140e5bae2c008c8ca1c3181c086c0b9d69f Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sat, 7 May 2016 16:28:43 +0800 Subject: [PATCH 05/11] Create 7483.cpp From http://blog.csdn.net/clz19960630/article/details/50965800 --- UVALive/7483.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 UVALive/7483.cpp diff --git a/UVALive/7483.cpp b/UVALive/7483.cpp new file mode 100644 index 0000000..4687890 --- /dev/null +++ b/UVALive/7483.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +#define pb push_back + +int main() +{ + int N; + while(cin>>N){ + vector arr[201]; + for (int i=1;i<=N;i++){ + int a, b; + scanf("%d%d",&a,&b); + arr[a].pb(b); + } + int mn=2e9, ans=0; + for (int i=1;i<=N+N;i++){ + if (mn < i) ans++, mn = 2e9; + for(int j=0;j Date: Sat, 7 May 2016 16:31:14 +0800 Subject: [PATCH 06/11] Create Readme.md --- UVALive/Readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 UVALive/Readme.md diff --git a/UVALive/Readme.md b/UVALive/Readme.md new file mode 100644 index 0000000..9b1f25b --- /dev/null +++ b/UVALive/Readme.md @@ -0,0 +1,2 @@ +#UVALive +[Goto UVa Online Judge](https://uva.onlinejudge.org/ "UVa Online Judge") From cde9f20e7a2d05b16b3886780d212a0d7d08f6a9 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sat, 7 May 2016 16:47:20 +0800 Subject: [PATCH 07/11] Rename 7483.cpp to 7483_csdn.cpp --- UVALive/{7483.cpp => 7483_csdn.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename UVALive/{7483.cpp => 7483_csdn.cpp} (100%) diff --git a/UVALive/7483.cpp b/UVALive/7483_csdn.cpp similarity index 100% rename from UVALive/7483.cpp rename to UVALive/7483_csdn.cpp From 200530a6ca6b9e7132c6c1f43e785bcfffa30101 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sat, 7 May 2016 19:10:04 +0800 Subject: [PATCH 08/11] Create 7483.cpp Accepted on VirtualJudge Online : http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115784#problem/F --- UVALive/7483.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 UVALive/7483.cpp diff --git a/UVALive/7483.cpp b/UVALive/7483.cpp new file mode 100644 index 0000000..949a33c --- /dev/null +++ b/UVALive/7483.cpp @@ -0,0 +1,50 @@ +/** +LINK= +http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115784#problem/F +*/ +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define MAXN 105 + +int main() +{ + int n; + while(scanf("%d",&n)==1) + { + vector pool[MAXN*2+8]; + for(int i=0;i Date: Sat, 7 May 2016 19:20:06 +0800 Subject: [PATCH 09/11] Create 3946_cnblogs.cpp From http://www.cnblogs.com/20143605--pcx/p/5426398.html --- ZOJ/3946_cnblogs.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 ZOJ/3946_cnblogs.cpp diff --git a/ZOJ/3946_cnblogs.cpp b/ZOJ/3946_cnblogs.cpp new file mode 100644 index 0000000..795aaab --- /dev/null +++ b/ZOJ/3946_cnblogs.cpp @@ -0,0 +1,107 @@ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +using namespace std; +# define LL long long + +const int N=1005; +const int INF=1000000000; +const LL oo=1000000000000005; + +struct Edge +{ + int to,nxt; + LL c,d; +}; + +int n,m,cnt; +Edge e[N*200]; +LL d[N*100]; +int head[N*100]; +vectorpre[N*100]; + +void add(int u,int v,LL d,LL c) +{ + e[cnt].to=v; + e[cnt].d=d; + e[cnt].c=c; + e[cnt].nxt=head[u]; + head[u]=cnt++; +} + +void solve() +{ + for(int i=0;iq; + q.push(0); + while(!q.empty()) + { + int u=q.front(); + q.pop(); + for(int i=head[u];i!=-1;i=e[i].nxt){ + int v=e[i].to; + if(d[v]>d[u]+e[i].d){ + d[v]=d[u]+e[i].d; + q.push(v); + } + } + } + + q.push(0); + while(!q.empty()){ + int u=q.front(); + q.pop(); + for(int i=head[u];i!=-1;i=e[i].nxt){ + int v=e[i].to; + if(d[v]==d[u]+e[i].d){ + pre[v].push_back(i); + q.push(v); + } + } + } + + LL ans1=0,ans2=0; + for(int i=0;i Date: Sat, 7 May 2016 19:40:20 +0800 Subject: [PATCH 10/11] Create 2492_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/03/12/2391988.html --- HDOJ/2492_cnblogs.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 HDOJ/2492_cnblogs.cpp diff --git a/HDOJ/2492_cnblogs.cpp b/HDOJ/2492_cnblogs.cpp new file mode 100644 index 0000000..8cac02e --- /dev/null +++ b/HDOJ/2492_cnblogs.cpp @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +//Constant Declaration +/*--------------------------*/ +//#define LL long long +#define LL __int64 +const int M=100001; +const int INF=1<<30; +const double EPS = 1e-11; +const double PI = acos(-1.0); +/*--------------------------*/ +// some essential funtion +/*----------------------------------*/ +void Swap(int &a,int &b){ int t=a;a=b;b=t; } +int Max(int a,int b){ return a>b?a:b; } +int Min(int a,int b){ return a 0) + { + sum += c[k]; + k -= LowBit(k); + } + return sum; +} + +void Update(int k, int sc) +{ + while (k <= 100000) + { + c[k] += sc; + k += LowBit(k); + } +} + + + +int main() +{ + //freopen("in.txt","r",stdin); + //freopen("out.txt","w",stdout); + int t, case1 = 0; + scanf("%d", &t); + int m; + int i, j; + int num; + //scanf("%d%d", &n, &m); + while (t--) + { + scanf("%d", &num); + memset(c, 0, sizeof(c)); + memset(left_lower, 0, sizeof(left_lower)); + memset(right_lower, 0, sizeof(right_lower)); + for (i = 1; i <= num; i++) + { + scanf("%d", &a[i]); + left_lower[i] += Sum(a[i] - 1);///Sum(a[i] - 1):插入该数前,区间1到a[i]-1的总个数 + Update(a[i], 1); + } + + memset(c, 0, sizeof(c)); + for (i = num; i > 0; i--)//顺序插入 + { + right_lower[i] += Sum(a[i] - 1); + Update(a[i], 1); + } + + LL ans = 0; + + for (i = 1; i <= num; i++)//逆序插入 + { + ans += left_lower[i]*(num - i - right_lower[i]);//由于只能求比其小的个数,可以用i右边的总个数见减比他小的来求比他大的个数。 + ans += (i - 1 - left_lower[i])*right_lower[i];// + } + + printf("%I64d\n", ans); + } + + + return 0; +} From 2655538f9c043b85034106355041a4210b63292e Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sat, 7 May 2016 19:41:31 +0800 Subject: [PATCH 11/11] Create 3790_cnblogs.cpp From http://www.cnblogs.com/qiufeihai/archive/2012/03/15/2398455.html --- HDOJ/3790_cnblogs.cpp | 144 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 HDOJ/3790_cnblogs.cpp diff --git a/HDOJ/3790_cnblogs.cpp b/HDOJ/3790_cnblogs.cpp new file mode 100644 index 0000000..6a9bb4f --- /dev/null +++ b/HDOJ/3790_cnblogs.cpp @@ -0,0 +1,144 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +//Constant Declaration +/*--------------------------*/ +//#define LL long long +#define LL __int64 +const int M=1100;//最多点数 +const int INF=1<<30; +const double EPS = 1e-11; +const double PI = acos(-1.0); +/*--------------------------*/ +// some essential funtion +/*----------------------------------*/ +void Swap(int &a,int &b){ int t=a;a=b;b=t; } +int Max(int a,int b){ return a>b?a:b; } +int Min(int a,int b){ return a d[min_num].l + g[min_num][i].l) + { + d[i].l = d[min_num].l + g[min_num][i].l; + d[i].p = d[min_num].p + g[min_num][i].p; + } + if (!used[i] && d[i].l == d[min_num].l + g[min_num][i].l && d[i].p > d[min_num].p + g[min_num][i].p)//这里的判断是关键 + { + d[i].p = d[min_num].p + g[min_num][i].p; + } + } + + } + return d[end].l; +} + + + + + +int main() +{ + //freopen("in.txt","r",stdin); + //freopen("out.txt","w",stdout); + //int t, case1 = 0; + //scanf("%d", &t); + int n, m; + int i, j; + while (scanf("%d%d", &n, &m), n + m) + { + init(n); + for (i = 0; i < m; i++) + { + int a, b, c, c1; + scanf("%d%d%d%d", &a, &b, &c, &c1); + if (g[a][b].l > c) + { + g[b][a].l = g[a][b].l = c; + g[b][a].p= g[a][b].p = c1; + }//此题为无向图 + if (g[a][b].l == c && g[b][a].p > c1)//这里的判断是关键 + { + g[b][a].p= g[a][b].p = c1; + } + + } + int star, end,ans; + scanf("%d%d", &star, &end); + ans = dijkstra(star, end, n); + printf("%d %d\n", ans, d[end].p); + } + + return 0; +}