T1
貌似很水,求一个最长的序列使得阶乘和等于当前序列,我们发现对于每个数都有独立性,那么把1~9特判掉就好啦 100
T2
看到数据范围大致明白是搜索了,我觉得宽搜状态不好设置所以写的深搜
剪枝:
1.层数限制,大于100层(大致)剪掉
2.不能让人在原地绕圈
3.把箱子不可能达到的地点预处理出来,这样可以O(1)判断
4.只有3个箱子、、等等只有3个箱子?我们完全可以把箱子分开设置状态啊
一共7*7,除去边界只有5个格子,4个物体所以5^7状态,大概也就80000种状态,我们记忆化一下然后再搞?
然后过了样例,但是大数据有时候会卡比如
1111111
1000001
1004001
1320001
1320001
1320001
1111111
然后还要加启发式优化,如果当前状态严格不优大胆剪掉就好啦
最后100
T3
其实这道题比T2简单的= =
二分边权,把所有白边加上当前边权,每次kruskal和k比较就好啦
因为脑残想到了LCT所以写了暴力,然后暴力严重挂掉导致只有10分
贴上代码
//Copyright(c)2015 liuchenrui #include<cstdio> #include<ctime> #include<iostream> #include<algorithm> #include<cstring> #include<map> using namespace std; int ans[1001],t; int n; char s[1001]; int main() { freopen("function.in","r",stdin); freopen("function.out","w",stdout); cin>>n;scanf("%s",s+1); for(int i=1;i<=n;i++) { if(s[i]=='0')continue; if(s[i]=='1')continue; if(s[i]=='2')ans[++t]=2; if(s[i]=='3')ans[++t]=3; if(s[i]=='4')ans[++t]=2,ans[++t]=2,ans[++t]=3; if(s[i]=='5')ans[++t]=5; if(s[i]=='6')ans[++t]=3,ans[++t]=5; if(s[i]=='7')ans[++t]=7; if(s[i]=='8')ans[++t]=2,ans[++t]=2,ans[++t]=2,ans[++t]=7; if(s[i]=='9')ans[++t]=2,ans[++t]=3,ans[++t]=3,ans[++t]=7; } sort(ans+1,ans+t+1); for(int i=t;i>=1;i--)printf("%d",ans[i]); }
//Copyright(c)2015 liuchenrui #include<cstdio> #include<ctime> #include<iostream> #include<algorithm> #include<cstring> #include<conio.h> #include<map> #define inf 1000000000 #define rep() for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) inline void R(int &v) { v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } char map[11][11]; bool can[11][11]; char g[11][11]; int n,m; int stax,stay; int num; const int fx[]={0,1,0,-1,0}; const int fy[]={0,0,1,0,-1}; int ans=inf; int zt[500000]; const int zy[]={1,5,25,125,625,3125,15625,78125}; void huifu(int x,int y) { if(g[x][y]=='3')map[x][y]='3'; else map[x][y]='0'; } void print(int step) { for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { putchar(map[i][j]); } putchar(10); } printf("step=%d\n",step); putchar(10); } int calc() { int t=1,ret=0;bool flag=true; rep() { if(map[i][j]=='4')ret+=zy[0]*(i-2)+zy[1]*(j-2); if(map[i][j]=='2')ret+=zy[t<<1]*(i-2)+zy[t<<1|1]*(j-2),t++; if(map[i][j]=='2' && g[i][j]!='3')flag=false; } if(flag)return -1; return ret; } void dfs(int nowx,int nowy,int step) { int hahaha=calc(); if(hahaha>0)if(step>=zt[hahaha])return; if(hahaha>0)zt[hahaha]=step; //print(step); //getch(); if(step>100)return; if(hahaha==-1) { ans=std::min(ans,step); return; } for(int i=1;i<=4;i++) { int px=nowx+fx[i]; int py=nowy+fy[i]; if(map[px][py]=='1')continue; if(map[px][py]=='0' || map[px][py]=='3') { map[px][py]='4'; huifu(nowx,nowy); dfs(px,py,step+1); huifu(px,py); map[nowx][nowy]='4'; } else if(map[px][py]=='2') { int rx=px+fx[i]; int ry=py+fy[i]; if(!can[rx][ry])continue; if(map[rx][ry]=='2')continue; map[rx][ry]='2'; map[px][py]='4'; huifu(nowx,nowy); dfs(px,py,step+1); map[nowx][nowy]='4'; map[px][py]='2'; huifu(rx,ry); } } } int main() { freopen("box.in","r",stdin); freopen("box.out","w",stdout); memset(can,true,sizeof(can)); memset(zt,63,sizeof(zt)); R(n),R(m); for(int i=1;i<=n;i++) { scanf("%s",map[i]+1); } rep()g[i][j]=map[i][j]; rep() { if(map[i][j]=='1')can[i][j]=false; if(map[i+1][j]=='1' && map[i][j+1]=='1')can[i][j]=false; if(map[i-1][j]=='1' && map[i][j+1]=='1')can[i][j]=false; if(map[i+1][j]=='1' && map[i][j-1]=='1')can[i][j]=false; if(map[i-1][j]=='1' && map[i][j-1]=='1')can[i][j]=false; if(map[i][j]=='3')can[i][j]=true,num++; if(map[i][j]=='4')stax=i,stay=j; } dfs(stax,stay,0); std::cout<<ans<<std::endl; }
//Copyright(c)2015 liuchenrui #include<cstdio> #include<ctime> #include<iostream> #include<algorithm> #include<cstring> #define inf 1000000000 using namespace std; inline void R(int &v) { v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } int father[100010]; int sum; int from[100010],to[100010],len[100010],color[100010]; struct Edge { int from,to,len,color; }edge[200010]; int getfather(int v) { if(father[v]==v)return v; father[v]=getfather(father[v]); return father[v]; } int n,m,k; int size; void addedge(int x,int y,int z,int color) { size++; edge[size].from=x; edge[size].to=y; edge[size].len=z; edge[size].color=color; } bool comp1(const Edge &a,const Edge &b) { if(a.len!=b.len)return a.len<b.len; return a.color<b.color; } bool comp2(const Edge &a,const Edge &b) { if(a.len!=b.len)return a.len<b.len; return a.color>b.color; } bool kruskal(int num) { size=0; for(int i=0;i<=n;i++)father[i]=i; for(int i=1;i<=m;i++) { if(color[i]==0)addedge(from[i],to[i],len[i]+num,0); else addedge(from[i],to[i],len[i],1); //cerr<<from[i]<<" "<<to[i]<<endl; } sort(edge+1,edge+size+1,comp1); int ret1=0;sum=0; for(int i=1;i<=size;i++) { int l=getfather(edge[i].from); int r=getfather(edge[i].to); if(l!=r) { if(!edge[i].color)ret1++; father[l]=r; if(edge[i].color==1 || ret1>k)sum+=edge[i].len; else sum+=edge[i].len-num; } } return ret1>=k; } int main() { freopen("tree.in","r",stdin); freopen("tree.out","w",stdout); R(n),R(m),R(k); for(int i=1;i<=m;i++) { R(from[i]),R(to[i]),R(len[i]),R(color[i]); from[i]++,to[i]++; } n++;n++; int l=-101,r=101; //cerr<<kruskal(-4)<<endl; //cerr<<sum<<endl; //return 0; while(l<r) { int mid=l+r>>1; if(kruskal(mid))l=mid+1; else r=mid; } /*for(int i=-100;i<=100;i++) { int u=kruskal(i); fprintf(stderr,"%d %d %d\n",i,u,sum); }*/ kruskal(l-1); std::cout<<sum<<std::endl; }