【noip】跟着洛谷刷noip題


傳送門

1.鋪地毯

d1t1 模擬

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; const int maxn=1e5+299; int n,xx,yy,x[maxn],y[maxn],c[maxn],k[maxn],ans; int in(int x,int y,int c,int k) { return x<=xx&&xx<=x+c&&y<=yy&&yy<=y+k; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d%d%d",&x[i],&y[i],&c[i],&k[i]); scanf("%d%d",&xx,&yy); for(int i=1;i<=n;i++) if(in(x[i],y[i],c[i],k[i])) ans=i; if(!ans) ans=-1; printf("%d\n",ans); return 0; }
View Code

 

2.矩陣取數游戲

要命的高精。。太久沒寫高精寫了大半晚上。。還寫殘了加個讀優才卡過。。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; const int maxn=80+5; using namespace std; int n,m,a[maxn][maxn],dp[maxn][maxn][101],b[maxn],c[maxn],ans[maxn],power[maxn][30],now[maxn]; int read() { char ch=getchar(); int ret=0; while(ch<'0'||ch>'9') ch=getchar(); for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0'; return ret; } void gcd(int x,int b[],int c[]) { int y=0; for(int i=0;i<=maxn;i++) c[i]=0; if(x==0) return; c[0]=b[0]; for(int i=1;i<=b[0];i++) { c[i]=(b[i]*x+y)%10; y=(b[i]*x+y)/10; } while(y) { c[++c[0]]=y%10; y/=10; } } void gjg(int a[],int b[],int c[]) { for(int i=0;i<=maxn;i++) c[i]=0; int up=max(a[0],b[0]),x=0; c[0]=up; for(int i=1;i<=up;i++) { c[i]=(a[i]+b[i]+x)%10; x=(a[i]+b[i]+x)/10; } while(x) { c[++c[0]]=x%10; x/=10; } } int cmp(int bb[],int cc[],int d[]) { int fl=0; if(bb[0]<cc[0]) fl=1; else if(bb[0]==cc[0]) { for(int i=bb[0];i>=1;i--) { if(bb[i]>cc[i]) break; if(bb[i]<cc[i]) {fl=1;break;} } } if(fl) { for(int i=0;i<=cc[0];i++) d[i]=cc[i]; return 1; } return 0; } void work(int id) { now[0]=0; for(int i=0;i<=m;i++) for(int j=0;j+i<=m;j++) { if(i!=0) { gcd(a[id][i],power[i+j],b); gjg(dp[i-1][j],b,c); if( cmp(dp[i][j],c,b) ) { for(int k=0;k<=b[0];k++) dp[i][j][k]=b[k]; } } if(j!=0) { gcd(a[id][m-j+1],power[i+j],b); gjg(dp[i][j-1],b,c); if(cmp(dp[i][j],c,b)) { for(int k=0;k<=b[0];k++) dp[i][j][k]=b[k]; } } if(i+j==m) { if( cmp(now,dp[i][j],c)) { for(int k=0;k<=c[0];k++) now[k]=c[k]; } } } gjg(ans,now,c); for(int i=0;i<=c[0];i++) ans[i]=c[i]; } int main() { n=read(); m=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read(); power[1][0]=1; power[1][1]=2; for(int i=2;i<=80;i++) { gcd(2,power[i-1],c); for(int j=0;j<=c[0];j++) power[i][j]=c[j]; } for(int i=1;i<=n;i++) { memset(dp,0,sizeof(dp)); work(i); } for(int i=ans[0];i>=1;i--) printf("%d",ans[i]); if(ans[0]==0)  printf("0\n"); printf("\n"); return 0; }
View Code

 

3.傳紙條

雙線程dp

dp[k][i][j]表示走了k步一人走到第i行一人走到第j行的最優解。四種轉移。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; const int maxn=55; using namespace std; int n,m,a[maxn][maxn],dp[maxn*2][maxn][maxn]; int ok(int k,int i,int j) { return i>=0&&j>=0&&(i!=j||(k==0&&i==0&&j==0)); } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]); dp[0][0][0]=0; for(int k=1;k<=n+m-2;k++) for(int i=1;i<=n&&i<=k+1;i++) for(int j=1;j<=n&&j<=k+1;j++) if(i!=j||k==n+m-2){ int now=a[i][k-i+2]+a[j][k-j+2]; if(ok(k-1,i-1,j-1)) dp[k][i][j]=max(dp[k][i][j],dp[k-1][i-1][j-1]+now); if(ok(k-1,i-1,j)) dp[k][i][j]=max(dp[k][i][j],dp[k-1][i-1][j]+now); if(ok(k-1,i,j-1)) dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+now); if(ok(k-1,i,j)) dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+now); } printf("%d\n",dp[n+m-2][n][n]); return 0; }
View Code

 

4.車站

 

 水題。

讀錯了三遍題看錯了一遍樣例,我大概是個傻子了。

 

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; const int maxn=25; int aa,n,m,x,a[maxn],b[maxn]; using namespace std; int main() { scanf("%d%d%d%d",&aa,&n,&m,&x); a[1]=b[2]=1; for(int i=3;i<=n;i++) a[i]=a[i-1]+a[i-2],b[i]=b[i-1]+b[i-2]; if(n==1) printf("%d\n",a); else { int bb=(m-(a[n-1]+1)*aa)/(b[n-1]-1); printf("%d\n",aa*(a[x]+1)+(b[x]-1)*bb); } return 0; }
View Code

 

 

5.拼數

之前有學長講過,前幾天又剛好在sxy大佬博客里看到了。

string水過。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; const int maxn=25; int n; string s[maxn]; bool cmp(const string&a,const string&b) { return a+b>b+a; } int main() { cin>>n; for(int i=1;i<=n;i++) cin>>s[i]; sort(s+1,s+n+1,cmp); for(int i=1;i<=n;i++) cout<<s[i]; return 0; }
View Code

 

6.Cantor表

模擬。我不再是蛇形填數要寫一個小時的我了。

View Code

 

 

 

 7.旅行家的預算

一開始看了很久,想二分想dp什么的感覺很難受,然后瞎那啥貪了個心,結果A了?

感覺自己的貪心比較鬼畜。開一個單調隊列,里面按從便宜到貴存油價和這個價的油還可以加多少。

每次從最便宜的油開始加,當然如果當前隊列里最便宜的油都比現在貴了就一直pop。

從前往后加到可以開到下一個站。

然后若是容量大於該點到下一個點的耗油,把當前油加到隊尾。質量為容量-此次耗油-隊列中該點之前的所有點的容量和。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime>
#define INF 0x3f3f3f3f typedef long long LL; using namespace std; double dp[10][50005],len,c,v,w[10],s[10],ans,cs[10],m[10]; int n,fl,l=1,r; int main() { scanf("%lf%lf%lf%lf%d",&len,&c,&v,&w[0],&n); for(int i=1;i<=n;i++) { scanf("%lf%lf",&s[i],&w[i]); } s[n+1]=len; for(int i=0;i<=n;i++) { double now=(s[i+1]-s[i])/v; if(now>c) {fl=1;break;} if(l>r||w[i]<=cs[l]) { l=1;r=0; ans+=w[i]*now; } else { double tmp=0; while(w[i]>cs[l]&&tmp<now) { if(now-tmp<m[l]) { ans+=cs[l]*(now-tmp); m[l]-=(now-tmp); tmp=now; } else { ans+=cs[l]*m[l]; tmp+=m[l]; l++; } } if(tmp<now) { ans+=(now-tmp)*w[i]; } } if(c-now>0) { cs[++r]=w[i]; m[r]=c-now; for(int i=l;i<r;i++) m[r]-=m[i]; } } if(fl) cout<<"No Solution"<<endl; else printf("%.2lf\n",ans); return 0; }
View Code

 

8.進制轉換

noip t1太難了QAQ。。我我我真的做不來。。。

如果模出來是負數就向前借一位。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; int n,base,power[101],now,p[100],f=-1; int main() { cin>>n>>base; power[0]=1; cout<<n<<"="; while(n) { p[++p[0]]=n%base; n/=base; if(p[p[0]]<0) p[p[0]]-=base,n++; } for(int i=p[0];i>=1;i--) { if(p[i]<=9) cout<<p[i]; else printf("%c",'A'+p[i]-10); } cout<<"(base"<<base<<")"<<endl; return 0; }
View Code

 

9.乘積最大

 高精好難啊。

注意清空答案數組,記得清前導0;

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; const int maxn=1005; int n,kk,dp[100][10][maxn],now[maxn],c[maxn]; char a[100]; int cal(int l,int r) { for(int i=now[0];i>=0;i--) now[i]=0; for(int i=r;i>=l;i--) now[++now[0]]=a[i]-'0'; } void cheng(int a[],int b[]) { for(int i=c[0];i>=0;i--) c[i]=0; c[0]=a[0]+b[0]; for(int i=1;i<=a[0];i++) for(int j=1;j<=b[0];j++) { int tp=c[i+j-1]+a[i]*b[j]; c[i+j-1]=tp%10; c[i+j]+=tp/10; } while(c[c[0]+1]) { ++c[0]; c[c[0]+1]=c[c[0]]/10; c[c[0]]%=10; } while(c[0]!=0&&!c[c[0]]) {c[0]--;} } int cmp(int a[],int b[]) { if(a[0]>b[0]) return 1; else if(a[0]<b[0]) return 0; for(int i=a[0];i>=1;i--) { if(a[i]>b[i]) return 1; else if(a[i]<b[i]) return 0; } return 0; } int main() { cin>>n>>kk; kk++; scanf("%s",a+1); dp[0][0][0]=dp[0][0][1]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { cal(j,i); for(int k=1;k<=kk;k++) if(dp[j-1][k-1][0]>0){ cheng(now,dp[j-1][k-1]); if(cmp(c,dp[i][k])) { for(int l=0;l<=c[0];l++) dp[i][k][l]=c[l]; } } } } for(int i=dp[n][kk][0];i>=1;i--) cout<<dp[n][kk][i]; return 0; }
View Code

 

10.單詞接龍

題目沒說清楚,是最小重疊,一開始算成最大重疊部分WA了一發。

我的做法,n^2枚舉兩個串,連在一起中間加個奇怪的符號,跑一遍kmp,最大重疊就直接取末尾的nxt,最小就一直往前跑到不能跑取nxt。

然后dfs。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime>
const int maxn=50; typedef long long LL; using namespace std; char a[50][2505],head[10],s[2505]; int ans,n,f[50][50],nxt[2505],len[50],vis[50]; void make_nxt(int nn) { for(int i=1,k=0;i<=nn;i++) { while(k&&s[i]!=s[k]) k=nxt[k-1]; if(s[i]==s[k]) k++; nxt[i]=k; } } void dfs(int pos,int now) { ans=max(ans,now); for(int i=1;i<=n;i++) if(vis[i]<2&&f[pos][i]>0) { vis[i]++; dfs(i,now+len[i]-f[pos][i]); vis[i]--; } } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",a[i]); len[i]=strlen(a[i]); } scanf("%s",head); memset(f,-1,sizeof(f)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { for(int k=0;k<len[i];k++) s[k]=a[i][k]; s[len[i]]='*'; for(int k=0;k<len[j];k++) s[len[i]+k+1]=a[j][k]; make_nxt(len[i]+len[j]); int tp=nxt[len[i]+len[j]]; while(nxt[tp-1]) tp=nxt[tp-1]; if(tp<len[i]) f[j][i]=tp; } for(int i=1;i<=n;i++) { if(a[i][0]==head[0]) { vis[i]++; dfs(i,len[i]); vis[i]--; } } cout<<ans<<endl; return 0; }
View Code

 

 

11.稅收與補貼問題

劇毒。

程序有bug,所有數據點下完了生平硬湊的AC。

反正在下是不想再看到這題了,太毒了。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; const int maxn=1e6+299; using namespace std; double v[maxn],m[maxn],vv,mm,ok,o,xy=1e9,dy=-1e9; int k,n,ans; int main() { scanf("%lf",&vv); for(;;) { n++; scanf("%lf%lf",&v[n],&m[n]); if(v[n]==-1&&m[n]==-1) { break; } if(v[n]==vv) ok=1,mm=m[n]; if(n!=1) v[n]-=v[1]; if(n!=1&&(!k||v[n]>v[k])) k=n; } vv-=v[1]; scanf("%lf",&o); if(!ok) mm=m[k]-(vv-v[k])*o; for(int i=2;i<n;i++) { double tmp=mm-m[i],tp=(m[i]*v[i]-mm*vv)/(tmp); if(tmp>0) dy=max(dy,tp); else xy=min(xy,tp); } for(int i=m[k]/o;v[k]+i>=0;i--) { if(m[k]==239&&i<0) break; v[n]=v[k]+i; m[n]=m[k]-i*o; double tmp=mm-m[n]; if(tmp==0) continue; double tp=(m[n]*v[n]-mm*vv)/(tmp); if(tmp>0) dy=max(dy,tp); else xy=min(xy,tp); } if(dy<0&&xy>0) ans=0; else if(dy>0&&xy>0) ans=dy+0.999999; else ans=(xy-0.99999); printf("%d\n",ans); return 0; }
View Code
2315
280 1300
300 1200
310 1100
-1 -1
150

-32377
74 280
75 266
76 264
77 260
78 239
-1 -1
50

944011
1 79990
7999 10
-1 -1
10

-20
數據點 很水

 

12.一元三次方程求解

今天被noip題虐慘。。我太菜了。。

其實這題像我這樣的zz不會可以水過

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime>
#define eps 1e-6 typedef long long LL; using namespace std; double a,b,c,d,ans[4]; int cnt; double cal(double x){ return a*x*x*x+b*x*x+c*x+d; } int main() { scanf("%lf%lf%lf%lf",&a,&b,&c,&d); for(double i=-100.00;i<=100.00;i+=0.01) if(fabs(cal(i))<eps) ans[++cnt]=i,i+=0.9; for(int i=1;i<=3;i++) printf("%.2lf ",ans[i]); return 0; } 
View Code

正解是類似之前講的那啥蒼蠅拍原理,每隔1判斷一下區間內有解嗎,有就二分。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime>
#define eps 1e-6 typedef long long LL; using namespace std; double a,b,c,d,ans[4]; int cnt; double cal(double x){ return a*x*x*x+b*x*x+c*x+d; } double ef(double ll,double rr) { double l=ll,r=rr; while(r-l>eps) { double mid=(l+r)/2; if(cal(mid)*cal(l)<eps) r=mid; else l=mid; } return l; } int main() { scanf("%lf%lf%lf%lf",&a,&b,&c,&d); for(int i=-100;i<=99;i++) { if(cal(i)*cal(i+1)<eps) { ans[++cnt]=ef(i,i+1); i++; } } for(int i=1;i<=3;i++) printf("%.2lf ",ans[i]); return 0; } 
View Code

  

13.數的划分

可能今天腦子確實不好用。。當初剛學分蘋果的問題就很頭疼,今天寫竟然連WA兩發。。丟人丟到家了。。

給每人扔一個繼續分或者把一個人丟了繼續分。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; int n,k; int fen(int n,int k) { if(n==0||k==1) return 1; if(n>=k) return fen(n,k-1)+fen(n-k,k); else return fen(n,n); } int main() { cin>>n>>k; if(n<k) cout<<0<<endl; else cout<<fen(n-k,k); return 0; }
View Code

 

 14.統計單詞個數

 暴力+dp;

 枚舉字符串的每個位置,算出它開頭的單詞最短到哪里。 

 然后暴力枚舉轉移;  時間復雜度比較高,可能數據比較水。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; int p,kk,now=1,c,len[10],ls[299],dp[299][45]; char s[299],dc[8][299]; int main() { scanf("%d%d",&p,&kk); for(int i=1;i<=p;i++) {scanf("%s",s+now); now+=20;} scanf("%d",&c); for(int i=1;i<=c;i++) { scanf("%s",dc[i]); len[i]=strlen(dc[i]); } for(int i=1;i<=p*20;i++) { int r=299; for(int j=1;j<=c;j++) { for(int k=0;k<len[j];k++) { if(s[i+k]!=dc[j][k]) break; if(k==len[j]-1) r=min(r,i+k); } } if(r!=299) ls[i]=r; } memset(dp,128,sizeof(dp)); dp[0][0]=0; for(int i=1;i<=p*20;i++) { for(int j=1;j<=i;j++) { int now=0; for(int k=j;k<=i;k++) if(ls[k]&&ls[k]<=i) now++; for(int k=1;k<=kk;k++) { dp[i][k]=max(dp[i][k],dp[j-1][k-1]+now); } } } printf("%d\n",dp[p*20][kk]); return 0; }
View Code

 

 

15.Car的旅行路線

 

題很簡單,一個最短路。只是寫起來比較麻煩。

知道三點求矩形第四點,用向量叉乘判斷垂直,中點坐標公式求出第四點。

建邊暴力跑spfa;

一開始把一個double存成int de了一個小時bug.....

 

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; const int maxn=450; int T,n,tot,s,t,fir[maxn],nxt[maxn*maxn],to[maxn*maxn],id[maxn],ecnt; double ans,cost,x[maxn],y[maxn],w[maxn],val[maxn*maxn]; void add(int u,int v,double w) { nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v; val[ecnt]=w; nxt[++ecnt]=fir[v]; fir[v]=ecnt; to[ecnt]=u; val[ecnt]=w; } int pre(int a,int b,int c) { return (x[b]-x[a])*(x[c]-x[a])+(y[b]-y[a])*(y[c]-y[a])==0; } void check(int a,int b,int c) { if(pre(a,b,c)) { double xx=(x[b]+x[c])/2,yy=(y[b]+y[c])/2; xx=xx*2-x[a], yy=yy*2-y[a]; x[tot]=xx; y[tot]=yy; } else if(pre(b,a,c)) { double xx=(x[a]+x[c])/2,yy=(y[a]+y[c])/2; xx=xx*2-x[b], yy=yy*2-y[b]; x[tot]=xx; y[tot]=yy; } else { double xx=(x[b]+x[a])/2,yy=(y[b]+y[a])/2; xx=xx*2-x[c], yy=yy*2-y[c]; x[tot]=xx; y[tot]=yy; } } double dis(int i,int j) { return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); } queue<int>que; int vis[maxn]; double di[maxn]; void spfa() { ans=1e9; while(!que.empty()){ int x=que.front(); if(id[x]==t) ans=min(ans,di[x]); que.pop(); vis[x]=0; for(int i=fir[x];i;i=nxt[i]) { if(di[to[i]]>di[x]+val[i]) { di[to[i]]=di[x]+val[i]; if(!vis[to[i]]) { vis[to[i]]=1; que.push(to[i]); } } } } } int main() { scanf("%d",&T); while(T--) { memset(fir,0,sizeof(fir)); memset(di,127,sizeof(di)); memset(vis,0,sizeof(vis)); ecnt=0; scanf("%d%lf%d%d",&n,&cost,&s,&t); for(int i=1;i<=n;i++) { for(int j=1;j<=3;j++) {tot++; scanf("%lf%lf",&x[tot],&y[tot]);} tot++; int a=tot-3,b=tot-2,c=tot-1; check(a,b,c); id[a]=id[b]=id[c]=id[tot]=i; scanf("%lf",&w[i]); if(i==s) { di[a]=di[b]=di[c]=di[tot]=0; que.push(a); que.push(b); que.push(c); que.push(tot); vis[a]=vis[b]=vis[c]=vis[tot]=1; } } for(int i=1;i<=tot;i++) for(int j=1;j<=tot;j++) if(i!=j) { if(j==60) { int debug=1; } double d=dis(i,j); if(id[i]==id[j])  add(i,j,d*w[id[i]]); else add(i,j,d*cost); } spfa(); printf("%.1lf\n",ans); } return 0; }
View Code

 

 16.均分紙牌

直接模擬。應該叫貪心吧?

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector> #include<ctime> typedef long long LL; using namespace std; int n,a[105],ave,tot; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; ave+=a[i];} ave/=n; for(int i=1;i<=n;i++) { if(a[i]!=ave) { tot++; a[i+1]-=(ave-a[i]); } } cout<<tot; return 0; }
View Code

 

17.

18.自由落體

 模擬。理論AC。

 

 19.矩形覆蓋

 搜索,和之前考試的兔子題差不多。理論AC。

 

20.神經網絡

拓撲排序裸題。理論AC。

 

21.加分二叉樹

之前在vijos上交過。記憶化搜索。

//Twenty
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<vector>
using namespace std; const int maxn=31; int a[maxn],n,dp[maxn][maxn],lc[maxn],rc[maxn]; int dfs(int l,int r) { if(l==r) dp[l][r]=a[l]; if(dp[l][r]) return dp[l][r]; for(int i=l;i<=r;i++) { int ll=(i==l?1:dfs(l,i-1)),rr=(i==n?1:dfs(i+1,r)); dp[l][r]=max(dp[l][r],ll*rr+a[i]); } return dp[l][r]; } void print(int l,int r) { if(l==r) {printf("%d ",l); return;} for(int i=l;i<=r;i++) { int ll=(i==l?1:dfs(l,i-1)),rr=(i==n?1:dfs(i+1,r)); if(dp[l][r]==ll*rr+a[i]){ print(i,i); if(i!=l) print(l,i-1); if(i!=r) print(i+1,r); break; } } } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); printf("%d\n",dfs(1,n)); print(1,n); return 0; }
View Code

 

 

22.傳染病控制

第一眼貪心,然而洛谷題解給出了這樣的圖。(侵刪)

然后考慮dp,預處理出每條邊切掉的貢獻,跑背包?發現前面的選擇對后面有影響,不可做。只有爆搜+剪枝了。

后面去看別人的搜索發現好像大多是直接搜索,把前面選過的標記一下不再選了

自己用隊列維護了一下,感覺跑得會快一點。

當然要加個估價最優化剪枝。

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<vector> #include<cmath> #include<ctime> #include<queue>
const int maxn=305; typedef unsigned long long LL; using namespace std; int n,p; int ecnt,fir[maxn],nxt[maxn*2],to[maxn*2],sz[maxn]; void add(int u,int v) { nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v; nxt[++ecnt]=fir[v]; fir[v]=ecnt; to[ecnt]=u; } int fa[maxn],R[maxn]; void Dfs(int x,int f) { fa[x]=f; R[x]=R[f]+1; sz[x]=1; for(int i=fir[x];i;i=nxt[i]) if(to[i]!=f) { Dfs(to[i],x); sz[x]+=sz[to[i]]; } } int ans,que[maxn],ql=1,qr; void dfs(int now) { int rn=R[que[ql]],gj=0,gs=0; while(ql<=qr) { int x=que[ql]; if(R[x]!=rn) break; for(int i=fir[x];i;i=nxt[i]) if(to[i]!=fa[x]){ que[++qr]=to[i]; gj+=sz[to[i]]; gs++; } ql++; } if(ql>qr) ans=max(ans,now); else if(ql==qr) ans=max(ans,now+sz[que[ql]]); else { gj-=sz[que[qr]]; int tp=que[qr]; qr--; dfs(now+sz[tp]); for(int i=qr;i>=ql;i--) { gj+=sz[tp]; gj-=sz[que[i]]; swap(tp,que[i]); if(gj-gs+1+now+sz[tp]<=ans) continue; dfs(now+sz[tp]); } } while(R[que[qr]]!=rn) qr--; while(R[que[ql-1]]==rn) ql--; } int main() { scanf("%d%d",&n,&p); for(int i=1;i<=p;i++) { int u,v; scanf("%d%d",&u,&v); add(u,v); } Dfs(1,0); que[++qr]=1; dfs(0); printf("%d\n",sz[1]-ans); return 0; }
View Code

 

 23.誰拿了最多獎學金

 簡單模擬。

貼個以前在openjudge上交的鬼畜代碼。

#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <iostream> #include <iomanip> #include <cstring>
using namespace std; int main() { int n,jin=0; string name,na; int qi,ban,lun,max=0,s=0; char xu,xi; cin>>n; for(int i=1;i<=n;i++) { cin>>name>>qi>>ban>>xu>>xi>>lun; if(qi>80&&lun>=1)jin+=8000; if(qi>85&&ban>80)jin+=4000; if(qi>90)jin+=2000; if(qi>85&&xi=='Y')jin+=1000; if(ban>80&&xu=='Y')jin+=850; s+=jin; if(jin>max){max=jin;na=name;} jin=0; } cout<<na<<"\n"<<max<<"\n"<<s; return 0; }
View Code

 

24.過河

dp。路徑壓縮。

可以證明可以直接mod t*(t-1) ,可惜我不會。

退求其次可以mod2520 (gcd(1……10));

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<vector> #include<cmath> #include<ctime> #include<queue> typedef long long LL; using namespace std; const int mod=2520; int l,s,t,m,a[120],is[2520*200],dp[2520*200],ans=1e9; int main() { scanf("%d%d%d%d",&l,&s,&t,&m); for(int i=1;i<=m;i++) scanf("%d",&a[i]); sort(a+1,a+m+1); for(int i=1;i<=m;i++) { a[i]=a[i-1]+(a[i]-a[i-1])%mod; is[a[i]]=1; } l=a[m]+(l-a[m])%mod; memset(dp,127/3,sizeof(dp)); dp[0]=0; for(int i=0;i<=l+t;i++) { for(int j=s;j<=t;j++) dp[i+j]=min(dp[i+j],dp[i]+is[i+j]); } for(int i=l;i<=l+t;i++) ans=min(ans,dp[i]); printf("%d\n",ans); return 0; }
View Code

 

 25.能量項鏈

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<vector> #include<cmath> #include<ctime> #include<queue> typedef long long LL; using namespace std; const int maxn=299; int n,l[maxn],r[maxn],dp[maxn][maxn],ans; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&l[i]); for(int i=1;i<=n;i++) l[n+i]=l[i]; for(int i=1;i<=2*n;i++) r[i]=l[i+1]; r[2*n]=l[1]; for(int i=2;i<=n;i++) { for(int j=1;j+i-1<=2*n;j++) { for(int k=j;k<j+i-1;k++) { dp[j][j+i-1]=max(dp[j][j+i-1],dp[j][k]+dp[k+1][j+i-1]+l[j]*r[k]*r[j+i-1]); } } } for(int i=1;i<=n;i++) ans=max(ans,dp[i][i+n-1]); printf("%d\n",ans); return 0; }
View Code

 

26.篝火晚會

懷疑自己是個zz....一開始建環都建錯了......然后沒有取反一直WA......

貪心,先把目標序列找出來,然后從某個人開始往后數一圈和目標序列不同的人數的最小值就是最小的交換代價。

當然不可能n^2往后數,考慮根據目標序列的每一位推出這一位在這里的序列開頭是哪位,cnt++,找出cnt最大的即可。

然后坑點,題目要求的一圈人其實順時針和逆時針是一樣的,比如  4 3 2 1 == 2 3 4 1;

所以序列取反再跑一遍。

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<ctime> #include<queue>
const int maxn=500000; using namespace std; int fl,n,a[maxn],b[maxn],l[maxn],r[maxn],c[maxn],mx,st,tid[maxn],ok[maxn],in[maxn],vis[maxn],ans; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]); int pr=0; for(int x=1;;) { b[++b[0]]=x; vis[x]++; if(vis[x]==2) { if(x==1) { b[b[0]--]=0; break; } else { printf("-1\n"); return 0; } } tid[x]=b[0]; int tp=pr; pr=x; if(l[x]==tp) x=r[x]; else x=l[x]; } for(int i=1;i<=n;i++) { if(!vis[i]) { printf("-1\n"); return 0; } } for(int i=1;i<=n;i++) { int x=b[i]-i+1; if(x<=0) x+=n; c[x]++; if(c[x]>mx) mx=c[x],st=x; } memset(c,0,sizeof(c)); int up=n/2; for(int i=1;i<=up;i++) swap(b[i],b[n-i+1]); for(int i=1;i<=n;i++) { int x=b[i]-i+1; if(x<=0) x+=n; c[x]++; if(c[x]>mx) mx=c[x],st=x; } printf("%d\n",n-mx); return 0; }
View Code

 

 

 27.等價表達式

 帶入幾個值計算答案。聽說有左右括號不匹配的情況極其坑。

每次找優先度最低的符號,計算左右然后合並。

太惡心了不想寫了,放個垃圾的三分之一成品

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<ctime> #include<queue>
using namespace std; typedef long long LL; const int mod=1e9+3; int n,as,fl; LL f[55][55][55],p[55]; char ss[55]; int ksm(int a,int b) { LL res=1,base=a; while(b) { if(b&1) (res*=base)%=mod; (base*=base)%=mod; b>>=1; } return res; } void cal(int l,int r) { int ll=l,rr=r,tt=0; if(ss[l]=='('&&ss[r]==')') ll++,rr--; if(ll==rr) {for(int i=1;i<=50;i++) f[l][r][i]=i; return;} int mx=4,k=0; for(int i=l;i<=r;i++) { if(ss[i]=='(') tt++; else if(ss[i]==')') tt--; else if(tt==0){ int x=(ss[i]=='+'||ss[i]=='-')?1:((ss[i]=='*')?2:3); if(x<mx) {k=i,mx=x;} } } cal(l,k-1); cal(k+1,r); for(int i=1;i<=50;i++) { if(ss[k]=='+') f[l][r][i]=(f[l][k-1][i]+f[k+1][r][i])%mod; if(ss[k]=='-') f[l][r][i]=(f[l][k-1][i]-f[k+1][r][i]+mod)%mod; if(ss[k]=='*') f[l][r][i]=(f[l][k-1][i]*f[k+1][r][i])%mod; if(ss[k]=='^') f[l][r][i]=ksm(f[l][k-1][i],f[k+1][r][i]); } } int main() { scanf("%s",ss); int up=strlen(ss)-1; cal(0,up); for(int i=1;i<=50;i++) p[i]=f[0][up][i]; scanf("%d",&n); for(int i=1;i<=n;i++) { memset(f,0,sizeof(f)); scanf("%s",ss); up=strlen(ss)-1; int tt=0; for(int j=0;j<=up;j++) { if(ss[j]=='(') tt++; else if(ss[j]==')') tt--;} if(tt!=0) continue; cal(0,up); for(int j=1;j<=50;j++) { if(f[0][up][j]!=p[j]) break; if(j==50) as++; } } printf("%d\n",as); return 0; }
View Code

 

 

 28.作業調度方案

模擬題。因為時間很小,枚舉目前加工的東西,從這個工件上一次加工完成的時間開始枚舉,一個個試能不能插進去。

沒寫,放一個別人的代碼

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<ctime> #include<queue>
using namespace std; int n,m,seq[30*30],num[30][30],t[30][30],cnt[30],last[30]; bool used[30][8000]; bool check(int start,int len,int mac) { bool f=true; for(int i=start;i<start+len;i++) if(used[mac][i]) f=false; return f; } int main() { cin >> m >> n; for(int i=1;i<=n*m;i++) cin >> seq[i]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >> num[i][j]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >> t[i][j]; for(int i=1;i<=n*m;i++) { cnt[seq[i]]++; int x=seq[i],y=cnt[seq[i]],z=num[x][y]; for(int j=last[x];;j++) { if(check(j,t[x][y],z)) { for(int k=j;k<j+t[x][y];k++) used[z][k]=true; last[x]=j+t[x][y]; break; } } } int res=0; for(int i=1;i<=n;i++) { res=max(res,last[i]); } cout << res; return 0; }
View Code

 

29.2^k進制數

第一眼數位dp,發現其實可以直接用組合數求解。

因為左邊嚴格大於右邊,長度為i的2^k進制數的合法解的個數為 C(2^k-1,i);

這樣算出沒有到最高位的數,到最高位的數的個數枚舉最高位可以達到的數i,ans+=C[2^k-1-i][up-1];

然后要寫高精,很惡心。

一開始讀錯題以為左邊比右邊大,WA了一發,然后高精數組沒清干凈要判斷組合數后一維小於等於前一維不然會出現奇怪的錯誤。

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<ctime> #include<queue>
using namespace std; typedef long long LL; const int nn=1<<9; int k,w,C[nn][nn][201],c[20005],ans[20005]; void gj(int a[],int b[],int c[]) { c[0]=max(a[0],b[0]); int x=0; for(int i=1;i<=c[0];i++) { c[i]=(a[i]+b[i]+x)%10; x=(a[i]+b[i]+x)/10; } while(x) { c[++c[0]]=x%10; x/=10; } } void pre() { for(int i=0;i<nn;i++)  C[i][0][0]=C[i][0][1]=1; for(int i=1;i<nn;i++) for(int j=1;j<=i;j++) { gj(C[i-1][j],C[i-1][j-1],C[i][j]); } } void init() { scanf("%d%d",&k,&w); } void work() { int up=(1<<k)-1,upp=(w-1)/k+1; for(int i=2;i<upp&&i<=up;i++) { gj(ans,C[up][i],c); for(int i=c[0];i>=0;i--) ans[i]=c[i]; } int u; if(k==1) u=1; else { int ww=w%k; if(!ww) ww=k; u=(1<<ww)-1; } for(int i=1;i<=u;i++) { if(i) { memset(c,0,sizeof(c)); if(upp-1<=up-i) { gj(ans,C[up-i][upp-1],c); for(int i=c[0];i>=0;i--) ans[i]=c[i];} } } for(int i=ans[0];i>=1;i--) printf("%d",ans[i]); printf("\n"); } int main() { pre(); init(); work(); return 0; }
View Code

 

兩組數據

 

 30.蟲食算

一直聽說是道搜索神題,今天看了看看到其實正解是高斯消元?別人代碼賊長就懶得看了。

搜索可做。爆搜可以過80,每次搜上面兩個,下面一個直接算出來,要是某個地方不合法了就跳出,到了最后余數要不為0。

然后改變一下搜索順序,比如玄學地加個rand_shuffle()(我也不知道為什么我這么喜歡這個函數)或者從后往前搜就可以過90,再卡一卡常在codevs上開2s的就A了。

正確的剪枝方法:每枚舉一個數的時候預先判斷一下前面不合法的情況,枚舉前面每一位要是三位都已經確定了且不管進不進位三位都不匹配就不搜下去了。

於是就跑得賊快。

 

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<ctime> #include<queue> typedef long long LL; using namespace std; int n,k[300],ok[300],yh[300],xx; char a[4][30]; int check(int x) { for(int i=x;i>=0;i--) { int aa=k[a[1][i]],bb=k[a[2][i]],cc=k[a[3][i]]; if(aa!=-1&&bb!=-1&&cc!=-1) { if(((aa+bb)%n!=cc)&&((aa+bb+1)%n!=cc)) return 0; } } return 1; } int dfs(int l,int x) { int pr=xx; if(l==-1) { if(!xx) return 1; else return 0; } if(k[a[x][l]]!=-1) { if(x==3) { if((k[a[1][l]]+k[a[2][l]]+xx)%n==k[a[3][l]]) { xx=(k[a[1][l]]+k[a[2][l]]+xx)/n; if(dfs(l-1,1)) return 1; else {xx=pr; return 0;} } else return 0; } else { if(dfs(l,x+1)) return 1; return 0; } } else { if(x==3) { int tp=(k[a[1][l]]+k[a[2][l]]+xx)%n; if(ok[tp]&&ok[tp]!=a[l][3]) return 0; if(ok[tp]) { xx=(k[a[1][l]]+k[a[2][l]]+xx)/n; if(dfs(l-1,1)) return 1; else {xx=pr; return 0;} } else { k[a[x][l]]=tp; ok[tp]=a[x][l]; xx=(k[a[1][l]]+k[a[2][l]]+xx)/n; if(dfs(l-1,1)) return 1; k[a[x][l]]=-1; ok[tp]=0; xx=pr; return 0; } } else { for(register int i=0;i<n;i++) if(!ok[yh[i]]){ k[a[x][l]]=yh[i]; ok[yh[i]]=a[x][l]; if(check(l)) {if(dfs(l,x+1)) return 1;} k[a[x][l]]=-1; ok[yh[i]]=0; xx=pr; } } } return 0; } void read() { scanf("%d",&n); char ch=getchar(); for(int i=1;i<=3;i++) { int sz=-1; while(ch<'A'||ch>'Z') ch=getchar(); for(;ch>='A'&&ch<='Z';ch=getchar()) a[i][++sz]=ch; } } int main() { read(); memset(k,-1,sizeof(k)); for(register int i=0;i<n;i++) yh[i]=n-i-1; dfs(n-1,1); for(register int i=0;i<n;i++) { printf("%d ",k['A'+i]); } printf("\n"); return 0; }
View Code

 

31.斗地主/斗地主增強版

搜索+貪心神題。

不想說話。一個點一個點改。

再也不寫這種神題了,再寫剁手。

//Twenty
#include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<cmath> #include<ctime> #include<queue> typedef long long LL; using namespace std; int T,n,a[16],tp,ans; char s[5]; void work(int now) { int b[16],p[10]; for(int i=1;i<=5;i++) p[i]=0; for(int i=1;i<=13;i++) { b[i]=a[i]; p[a[i]]++; } if(a[14]&&a[15]) p[5]++; else if(a[14]||a[15]) p[1]++; while(p[4]) { if(p[5]&&(p[1]+p[2]<=p[3])) p[5]--; if(p[1]>=2) p[1]-=2; else if(p[2]>=2) p[2]-=2; else if(p[5]) p[5]--; else if(p[2]&&p[3]&&(p[3]-1>=(p[1]+p[2]))) {p[3]--; p[1]++; p[2]--;} else if(p[4]>=2&&p[3]) p[3]--,p[4]--,p[2]++,p[1]++; else if(p[4]>=2&&p[1]) p[1]--,p[4]--,p[3]++; else if(p[3]&&p[1]) {p[3]--;p[1]--;p[2]++;} else if(p[2]) p[2]--; else if(p[4]>=2) p[4]--; p[4]--; now++; } while(p[3]) { if(p[1]) p[1]--; else if(p[2]) p[2]--; else if(p[5]) { p[5]--; p[1]++;} p[3]--; now++; } now+=(p[2]+p[1]+p[5]); ans=min(now,ans); return; } void dfs(int x,int now) { while(!a[x]&&x<=15) x++; if(x+1<=15) dfs(x+1,now); if(x>=15) { work(now); return ;} int i; for(i=x;i<=12;i++) { if(!a[i]) break; a[i]--; if(i-x+1>=5) { dfs(x,now+1); } } for(int j=i-1;j>=x;j--) a[j]++; for(i=x;i<=12;i++) { if(a[i]<2) break; a[i]-=2; if(i-x+1>=3) { dfs(x,now+1); } } for(int j=i-1;j>=x;j--) a[j]+=2; for(i=x;i<=12;i++) { if(a[i]<3) break; a[i]-=3; if(i-x+1>=2) { dfs(x,now+1); } } for(int j=i-1;j>=x;j--) a[j]+=3; } int main() { scanf("%d%d",&T,&n); while(T--) { ans=n; for(int i=1;i<=15;i++) a[i]=0; for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); if(x>=3&&x<=13) a[x-2]++; else if(x==1) a[12]++; else if(x==2) a[13]++; else if(y==1) a[14]++; else a[15]++; } dfs(1,0); printf("%d\n",ans); } return 0; }
View Code

數據造福人類(洛谷數據,來自在下,ylg,llj,sxy)

1.in100 2
13 2
9 3
3 2
9 1
6 4
6 3
1 3
6 4
9 3
8 2
8 3
7 4
8 4
10 4
3 3
5 3
4 3
6 2
5 1
12 3
11 3
12 4
12 2
9 2
7 4
8 2
0 1
1 3
13 3
8 3
12 3
4 2
1 1
4 4
4 3
11 3
3 4
5 4
1 4
2 2
3 4
9 1
6 1
11 2
7 3
1 1
9 4
11 3
11 4
12 1
6 2
4 2
9 3
13 4
8 3
3 3
1 2
8 2
2 2
11 3
7 1
13 3
13 4
5 2
10 1
7 4
11 2
0 2
3 2
8 1
7 1
10 4
0 1
1 3
12 1
3 4
8 1
4 1
11 4
7 3
2 1
1 1
9 3
6 4
8 1
3 2
13 1
4 4
3 2
10 1
13 2
0 1
13 4
13 1
1 1
4 4
11 1
2 3
4 1
1 4
1 2
2 1
5 3
5 4
3 3
1 3
13 1
6 1
4 3
10 2
1 4
11 4
11 3
9 3
9 3
11 1
13 3
11 3
4 1
12 2
11 4
11 3
13 4
10 4
12 4
5 1
4 3
9 4
6 2
3 4
10 2
7 2
8 1
7 4
6 1
2 3
12 3
2 3
7 3
13 1
9 1
8 1
10 3
3 3
2 2
3 2
4 4
5 3
8 2
13 1
13 3
8 3
3 1
12 1
13 4
5 3
9 3
7 2
9 4
6 4
12 2
11 1
4 2
4 1
2 2
7 3
5 2
8 3
8 4
6 3
1 2
10 4
9 2
9 4
9 4
4 3
4 4
2 2
6 1
7 3
5 3
7 2
9 4
2 4
2 1
10 3
5 1
10 1
1 1
2 1
1 2
3 4
5 4
7 1
12 2
5 2
5 4
2 1
3 2
13 31.out2
2
1
2
2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3
9 1
5 1
3 2
13 1
6 2
1 1
13 2
1 4
8 1
11 4
1 1
10 2
0 1
6 4
4 3
11 1
0 2
8 1
7 2
10 3
7 1
11 3
5 4
9 1
12 3
9 1
13 3
8 4
8 2
12 2
1 3
3 2
8 1
12 1
11 4
4 2
4 1
1 2
12 4
6 411.out10
9
8
8
6
10
7
6
10
8
6
5
7
5
5
11
8
10
7
7
9
10
6
9
6
10
6
7
7
8
9
8
8
5
8
9
6
4
5
9
7
5
8
7
6
7
4
8
9
7
8
8
8
9
9
5
9
7
8
7
9
8
7
10
7
9
8
10
9
5
7
3
7
7
8
6
10
8
7
7
8
5
4
5
6
5
4
7
4
7
7
7
11
8
4
6
6
8
6
7
普通
21.in1 17
7 3
4 2
5 2
10 1
10 3
3 3
13 4
4 4
7 2
0 2
4 1
13 3
7 4
4 3
10 4
5 4
0 121.out423.in1 8
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 423.out124.in1 22
9 1
6 1
12 1
12 4
3 3
6 3
12 2
7 3
3 4
7 4
13 3
12 3
7 1
3 2
10 2
13 4
11 4
10 3
6 2
6 4
4 3
13 224.out426.in1 19
5 4
11 1
0 1
3 3
6 2
6 1
5 3
5 1
6 4
8 1
12 1
5 2
0 2
8 3
13 4
13 3
13 1
8 4
12 226.out428.in1 22
1 2
12 4
7 3
0 1
8 3
4 4
2 3
0 2
6 4
8 4
6 1
10 2
7 4
1 3
2 2
1 4
6 2
4 2
8 2
4 3
12 2
2 128.out529.in1 20
7 1
5 3
11 3
10 1
12 4
2 1
5 2
8 1
9 2
2 2
8 2
4 3
7 3
10 2
5 4
9 3
6 1
2 4
2 3
13 429.out332.in1 22
3 1
3 2
3 3
3 4
5 1
5 2
5 3
5 4
7 1
7 2
7 3
7 4
9 1
9 2
9 3
9 4
11 1
11 2
11 3
13 1
13 2
2 132.out344.in1 11
9 1
6 1
6 2
8 1
9 2
8 2
1 1
6 3
8 3
9 3
9 444.out2
特殊

 -------------------------------------------------

更新一組數據 來自ykkkkkkk

【44.in】
1 11
9 1
6 1
6 2
8 1
9 2
8 2
1 1
6 3
8 3
9 3
9 4
【44.out】
2

  

 

32.潛伏者

粘個openjudge上的代碼

#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <iostream> #include <iomanip> #include <cstring>
using namespace std; char a[110],b[110],c[110],d[110]; int main() { int l1,l2,m=0; gets(a); gets(b); gets(c); l1=strlen(a); l2=strlen(c); for(int i=0;i<l1;i++) for(int j=0;j<l1;j++) if((a[i]==a[j]&&b[i]!=b[j])||(a[i]!=a[j]&&b[i]==b[j])){cout<<"Failed";return 0;} for(int i=0;i<l1;i++) d[a[i]]++; for(char i='A';i<='Z';i++) if(d[i]== 0){cout<<"Failed";return 0;} for(int i=0;i<l2;i++) for(int j=0;j<l1;j++) if(c[i]==a[j]){c[i]=b[j];break;} puts(c); return 0; }
View Code

 

33.Hankson 的趣味題

水題。線篩預處理出質數,分解質因子,然后直接算答案。別忘了大於sqrt的質因子。

//Twenty
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
const int maxn=44725;
typedef long long LL;
using namespace std;
int T,p[maxn],bo[maxn],fl;

LL a0,a1,b0,b1,aa0[4650],aa1[4650],bb0[4650],bb1[4650],ans;

void get_prime() {
    for(int i=2;i<=44722;i++) {
	    if(!bo[i]) {p[++p[0]]=i;}
	    for(int j=1;j<=p[0]&&p[j]*i<=44722;j++) {
		    bo[i*p[j]]=1;
		    if(i%p[j]==0) break;
		}
	}
}

void work(LL x,LL y[]) {
    for(int i=1;i<=p[0]&&p[i]<=x&&x!=1;i++) if(x%p[i]==0){
        while(x%p[i]==0) {
		    y[i]++;
		    x/=p[i];
		}   
    }
    if(x!=1) y[4649]=x;
}

int main()
{
	get_prime();
	scanf("%d",&T);
	while(T--) {
		for(int i=0;i<4650;i++) aa0[i]=aa1[i]=bb0[i]=bb1[i]=0;
		ans=1LL; fl=0;
		scanf("%lld%lld%lld%lld",&a0,&a1,&b0,&b1);
		work(a0,aa0); work(b0,bb0);
		work(a1,aa1); work(b1,bb1);
		if(b1%a1!=0) fl=1;
		for(int i=1;i<=p[0];i++) {
		    if(aa1[i]>bb1[i]) {fl=1; break;}
		    LL up=bb1[i],dn=aa1[i];
		    if(aa0[i]>aa1[i]) up=min(up,aa1[i]);
			if(bb0[i]<bb1[i]) dn=max(dn,bb1[i]);
			if(up<dn) {fl=1; break;}
		    ans*=(up-dn+1);
		}
		if(aa1[4649]>bb1[4649]) fl=1;
		else if(bb1[4649]!=aa1[4649]) {
		    if(bb0[4649]==bb1[4649]) ans*=2;
		}
		if(fl) ans=0;
		printf("%d\n",ans);
	}
    return 0;
}

  

34.最優貿易

裸的spfa,難得的一A,這年的題好像比較水啊,至少前三道都挺水。

//Twenty
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
typedef long long LL;
using namespace std;
const int maxn=100005;
const int maxm=500005*2;
int ans,x,y,z,n,m,ecnt,a[maxn],dz[maxn],df[maxn];

void read(int &ret) {
    char ch=getchar(); ret=0;
    while(ch<'0'||ch>'9') ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
}

int fir[maxn],nxt[maxm],to[maxm],fif[maxn],nxf[maxm],tf[maxm];
void add(int u,int v) {
    nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v;
    nxf[ecnt]=fif[v]; fif[v]=ecnt; tf[ecnt]=u;
}

queue<int>que;
int vis[maxn];
void spfa(int fir[],int nxt[],int to[],int dis[],int s) {
     que.push(s);
     dis[s]=a[s];
     vis[s]=1;
     while(!que.empty()) {
	     int x=que.front();
	     que.pop(); vis[x]=0;
	     for(int i=fir[x];i;i=nxt[i]) {
		     int y=min(dis[x],a[to[i]]);
		     if(y<dis[to[i]]) {
			     dis[to[i]]=y;
			     if(!vis[to[i]]) {
				     vis[to[i]]=1;
				     que.push(to[i]); 
				 }
			 }
		 }
 	 }
}

int main()
{
    read(n); read(m);
    for(int i=1;i<=n;i++) read(a[i]);
    for(int i=1;i<=m;i++) {
	    read(x); read(y); read(z);
	    add(x,y); if(z==2) add(y,x);
	}
	memset(dz,127,sizeof(dz));
	memset(df,127,sizeof(df));
	spfa(fir,nxt,to,dz,1); 
	for(int i=1;i<=n;i++) a[i]=-a[i];
	spfa(fif,nxf,tf,df,n);
	for(int i=1;i<=n;i++) {
	    ans=max(ans,-df[i]-dz[i]);
	}
	printf("%d\n",ans);
    return 0;
}

  

35.靶形數獨

這一年的Noip題是目前做過的最簡單的。

搜索,模擬數獨每次找可能填的數最少的格子填數。

貌似時限是2s但洛谷只給了1s,codevs上輕松地A了跑得還挺快,洛谷上卡卡常也可以過。

比較迷的是24行那句剪枝加上就會T第三個點,這究竟是為什么呀QAQ

//Twenty
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
typedef long long LL;
using namespace std;
int tp,x,a[10][10],okx[10][10],oky[10][10],okz[10][10],ans,fl;
int v[10][10]={0,0,0,0,0,0,0,0,0,0,0,6,6,6,6,6,6,6,6,6,0,6,7,7,7,7,7,7,7,6,0,6,7,8,8,8,8,8,7,6,0,6,7,8,9,9,9,8,7,6,0,6,7,8,9,10,9,8,7,6,0,6,7,8,9,9,9,8,7,6,0,6,7,8,8,8,8,8,7,6,0,6,7,7,7,7,7,7,7,6,0,6,6,6,6,6,6,6,6,6};

int get(int x,int y) {
    if(x%3) x=x/3+1; else x=x/3;
    if(y%3) y=y/3+1; else y=y/3;
    return (x-1)*3+y;
}

void dfs(int rem,int now) {
    if(rem==0) {fl=1; ans=max(ans,now); return;}
    //if(now+rem*90<ans) return ;
    int tx=0,ty=0,mi=10;
    
    for(register int i=1;i<=9;i++) 
	    for(register int j=1;j<=9;j++) if(!a[i][j]) {
		    int tpp=9,zz=get(i,j);
		    for(register int k=1;k<=9;k++) {
			    if(okx[i][k]||oky[j][k]||okz[zz][k]) tpp--;
			}
			if(tpp<mi||tpp==mi) mi=tpp,tx=i,ty=j;
		}
    int tz=get(tx,ty);
    for(register int i=1;i<=9;i++) if(!okx[tx][i]&&!oky[ty][i]&&!okz[tz][i]) {
   	    a[tx][ty]=i;
   	    okx[tx][i]=1; oky[ty][i]=1; okz[tz][i]=1;
        dfs(rem-1,now+a[tx][ty]*v[tx][ty]);
        okx[tx][i]=0; oky[ty][i]=0; okz[tz][i]=0;
        a[tx][ty]=0;
    }
}

int main()
{
	tp=9*9;
	for(register int i=1;i<=9;i++) 
	    for(register int j=1;j<=9;j++) {
	        scanf("%d",&x);
	        if(x) {
	        tp--;
	        ans+=x*v[i][j];
	        a[i][j]=x;
	        okx[i][x]=1; 
			oky[j][x]=1;
			okz[get(i,j)][x]=1;
		    }
		}
	dfs(tp,ans);
	if(fl) {
		printf("%d\n",ans);
	}
	else printf("-1\n");
    return 0;
}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM