zoj 3202 second-price Auction
water problem, not explained, direct sticker code
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;struct node{int x;int y;}; struct node Number[105];int cmp (struct node a,struct node B) {return a.x>b.x;} int main () {int t;scanf ("%d", &t), int i;while (t--) {int n;scanf ("%d", &n), for (i=0;i<n;i++) {scanf ("%d",& number[i].x); number[i].y=i;} Sort (number,number+n,cmp);p rintf ("%d%d\n", number[0].y+1,number[1].x);} return 0;}
zoj 3203 Light Bulb
simple math problem, also does not explain, make a double crochet function, the most want to pay attention to judge have not shot to the wall can, direct paste code
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < Cmath>using namespace Std;int main () {int t,i;scanf ("%d", &t), while (t--) {double h,h,d;scanf ("%lf%lf%lf", &h , &h,&d);d ouble tmp=sqrt ((h-h) *d), if (tmp+h/h*d<d) {printf ("%.3lf\n", H/h*d);} else if (tmp<d) {printf ("%.3f\n", h+d-tmp-tmp);} else{printf ("%.3lf\n", h);}}
Zoj 3204 Connect them minimum spanning tree water problem, still does not explain
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < Cmath>using namespace Std;struct node{int a,b;int n;}; struct Rea{int A, b;}; struct node Edge[10005];int father[105];int cmp (struct node a,struct node B) {if (A.N==B.N) {if (A.A==B.A) {return a.b< b.b;} else return A.A<B.A;} return A.N<B.N;} int cmp1 (struct rea x,struct rea y) {if (X.A==Y.A) return x.b<y.b;else return x.a<y.a;} int Find (int n) {if (father[n]==n) return n;else return Father[n]=find (Father[n]);} struct REA relans[500];int main () {int t,i,j;scanf ("%d", &t), while (t--) {int n;scanf ("%d", &n); int K=0;for (i=1;i <=n;i++) father[i]=i;for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {int tmp;scanf ("%d", &tmp); if (tmp!=0) {edge[k ].a=i;edge[k].b=j;edge[k++].n=tmp;}}} Sort (edge,edge+k,cmp); int ans=0;for (i=0;i<k;i++) {int ta=find (EDGE[I].A); int tb=find (EDGE[I].B); if (TA!=TB) { father[ta]=tb;relans[ans].a=edge[i].a;relans[ans++].b=edge[i].b;} if (ans==n-1) break;} Sort (relans,relans+aNS,CMP1), if (ans==n-1) {for (i=0;i<ans;i++) {if (i==0) printf ("%d%d", relans[i].a,relans[i].b), Else printf ("%d%d", RELANS[I].A,RELANS[I].B);} printf ("\ n");} else{printf (" -1\n");}}}
Zoj 3205 Direct Sticker Code
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include < iostream> #include <queue> #include <map> #include <cmath>using namespace Std;const int mo= 1000000007;int C[200],p[200][200],a[200];long Long Po[105][105];long long power (int x,int y) {long long res=1; Long Long sum=x; while (y) {if (y%2==1) res= (res*sum)% Mo; sum= (sum*sum)% Mo; y/=2; } return res; int main () {int t; scanf ("%d", &t); for (int i=0, i<105; i++) for (int j=0; j<105; j + +) Po[i][j]=power (I,J); while (t) {int n,m,k; scanf ("%d%d", &n,&m); for (int i=0; i<n; i++) {scanf ("%d", &c[i]); for (int j=0; j<m; j + +) scanf ("%d", &p[i][j]); } scanf ("%d", &k); while (k--) {for (int i=0; i<m; i++) scanf ("%d", &a[i]); FoR (int j=0; j<m; J + +) {long long ans=0; for (int i=0; i<n; i++) {Long long sum=0; if (p[i][j]>0) {sum=c[i]*p[i][j]; for (int k=0; k<m; k++) {if (k==j) sum= (Sum*po[a[k]][p[i][k]-1] )% Mo; else sum= (sum*po[a[k]][p[i][k])% Mo; }} ans= (ans+sum)% Mo; } if (j==m-1) cout<<ans<<endl; else cout<<ans<< ""; }} if (--T) cout<<endl; } return 0;}
Zoj 3206 Disaster Area reconstruction
This problem is still more troublesome, the topic is to ask you to ask for a connected component, the number of vertices inside the connected component is the most, and output the connected component.
first of all, if this is a non-circular diagram, the direct tree DP to find the longest chain is good, so it is necessary to deal with the pre-ring situation.
Next, just do a strong connected component indent, then record a vertex number for each point, then DP a bit. The code is as follows:
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include < Algorithm> #include <stack>using namespace std;const int maxn = 50010;const int inf = 1000000;int N, m;vector<i Nt> Edge[maxn];int DFN[MAXN], LOW[MAXN], Tim;stack<int>s;bool instack[maxn];int BELONG[MAXN], MINID[MAXN], Num[maxn];int cnt;void Init () {for (int i = 0; I <= N; i++) edge[i].clear (); while (!s.empty ()) S.pop (); memset (instack, 0, sizeof (instack)); memset (num, 0, sizeof (num)); memset (Low, 0, sizeof (low)); memset (DFN, 0, sizeof (DFN)); Fill (MiniD, MINID+MAXN, INF); CNT = Tim = 0;} void Tarjan (int u) {dfn[u] = low[u] = ++tim; S.push (U); Instack[u] = 1; int len = Edge[u].size (); for (int i = 0; i < len; i++) {int v = edge[u][i]; if (dfn[v] = = 0) {Tarjan (v); Low[u] = min (Low[u], low[v]); } else if (instack[v] = = 1) {Low[u] = min (Low[u], dfn[v]); }} if(Dfn[u] = = Low[u]) {int V; CNT + +; do {v = s.top (); S.pop (); INSTACK[V] = 0; BELONG[V] = cnt;//this to which new point num[cnt]++;//shrinks how many points minid[cnt] = min (minid[cnt], v);//Minimum point label for indent}whi Le (U! = v); }}vector<int> newedge[maxn];void Build () {for (int i = 0; I <= n; i + +) newedge[i].clear (); for (int u = 1; u <= n; u++) {int len = edge[u].size (); for (int i = 0; i < len; i++) {int v = edge[u][i]; if (belong[u]! = Belong[v]) {newedge[belong[u]].push_back (belong[v]); }}}}int vis[maxn];int dp[maxn];int tail[maxn];void init_new () {for (int i = 0; I <= cnt; i++) Newedge[i]. Clear (); memset (Vis, 0, sizeof (VIS)); memset (DP, 0, sizeof (DP));} void Dfs (int u) {vis[u] = 1; Dp[u] = Num[u]; Tail[u] = u; int len = Newedge[u].size (); for (int i = 0; i < len; i++) {int v = newedge[u][i]; if (vis[v] = = 0) { DFS (v); } if (Dp[u] < Dp[v]+num[u]) {Dp[u] = Dp[v]+num[u]; Tail[u] = Tail[v]; } else if (dp[u] = = Dp[v]+num[u]) {if (Minid[tail[u] > Minid[tail[v]]) tail[u] = Tail[v]; }}}int Main () {int t; int A, B; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n, &m); Init (); for (int i = 0; I <m; i++) {scanf ("%d%d", &a, &b); Edge[a].push_back (b); } for (int i = 1; I <= n; i++) {if (dfn[i] = = 0) {Tarjan (i); }} int ans = 0; Init_new (); Build (); for (int i = 1; I <= cnt; i + +) {if (vis[i] = = 0) {DFS (i); }} pair<int, int> res = Make_pair (INF, INF); for (int i = 1; I <= cnt; i + +) {a = Minid[tail[i]], B = minid[i]; Pair<int, int> tmp = Make_pair (A, b); if (Dp[i] > ans) {ans = dp[i]; res = TMP; } else if (dp[i] = = ans) {if (TMP < res && Res.first! = Res.second | | tmp.first = = Tmp.second ) {res = TMP; }}} if (Res.first = = Res.second) {res = Make_pair (1, 2); } printf ("%d\n%d%d\n", ans, Res.first, res.second); }}
Zoj 3207 80ers ' Memory
water problem, do not explain, the code is not on the
Zoj 3208 Reforestation
This topic is a bit more, the title means: There is an observer is observing the surrounding situation, the Observer has been in (0,0) position. The title gives you the center of the tree, which has a radius of more than 1 per second, and if the trees collide or touch the observer, they stop growing and they block the observer's gaze, and the question is, when is the observer blocked? If you can't stop, output -1.
Ideas:
First, you can preprocess each tree when it stops growing, that is, each tree and all the other trees to calculate a time to minimize the intersection. Then you can think of two minutes, take the largest of all the stop time as the maximum time for two points, for each time as long as the calculation of the observer is blocked. The specific calculation, just to see whether [0,2π] within the scope of the field is blocked, if blocked, you know.
The code is as follows
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include < iostream> #include <queue> #include <map> #include <cmath>using namespace Std;const double o=1e-8; Const double PI = ACOs ( -1.0), struct da{double x,y,t;} a[10000];struct da1{double l,r;} Q[10000];int n,bo[400];d ouble ti[100000];d ouble min (double x, double y) {return x<y?x:y;} Double Max (double x,double y) {return x>y?x:y;} Double dis (int i,int j) {return sqrt ((a[i].x-a[j].x) * (a[i].x-a[j].x) + (A[I].Y-A[J].Y) * (A[I].Y-A[J].Y));} BOOL CMP (da1 A, da1 b) {return A.L<B.L;} BOOL Cmp2 (double a,double b) {return a<b;} BOOL Check (double res) {int sum=0; for (int i=1; i<=n; i++) {Double r = min (res,a[i].t); Double PH1,PH2; PH1 = atan2 (a[i].y,a[i].x); if (ph1<0) ph1+=pi*2; if (R-dis (0,i) <o) PH2 = ASIN (R/dis (0,i)); else ph2=pi/2.0; Double lnow=ph1-ph2,rnow=ph1+PH2; if (lnow<0) {q[sum].l=lnow+pi*2; q[sum].r=pi*2; sum++; q[sum].l=0; Q[sum].r=rnow; sum++; } else if (rnow>pi*2) {q[sum].l=lnow; q[sum].r=pi*2; sum++; q[sum].l=0; q[sum].r=rnow-pi*2; sum++; } else {Q[sum].l=lnow; Q[sum].r=rnow; sum++; }} sort (q,q+sum,cmp); Double rnow=o; for (int i=0; i<sum; i++) {if (Q[i].l>rnow) return true; Rnow = max (RNOW,Q[I].R); } if (rnow<pi*2) return true; return false;} int main () {int t; scanf ("%d", &t); while (t--) {scanf ("%d", &n); a[0].x=0,a[0].y=0; a[0].t=0; for (int i=1; i<=n; i++) { int x, y; scanf ("%d%d", &x,&y); A[i].x=x,a[i].y=y; a[i].t=999999; } double l=0.0,r=0.0; memset (bo,0,sizeof bo); Bo[0]=true; for (int i=1; i<=n; i++) {int tt=0; Double mint=999999; for (int j=1; j<=n; J + +) if (!bo[j]) {double Tmp=dis (0,j); for (int k=1; k<=n; k++) if (j!=k) {if (!bo[k]) tmp=min (Tmp,dis (j,k)/2.0); Else Tmp=min (Tmp,dis (j,k)-a[k].t); } if (tmp<mint) {tt=j; mint=tmp; }} bo[tt]=true; A[tt].t=mint; } for (int i=1; i<=n; i++) R=max (r,a[i].t); r+=1.0; if (check (r)) cout<< " -1.0" <<endl; else {while (r-l>1e-8) {double mid= (l+r)/2.0; if (check (mid)) L=mid; else R=mid; } printf ("%.8f\n", L); }} return 0;}
Zoj 3209 Treasure Map
with N*m as a column, each matrix as a row, Dancing link does not explain
#include <stdio.h> #include <string.h>const int ROW = 505;const int V = 452000;const int LIE = 905;int R[v],l[v], U[v],d[v],c[v];int h[row],s[lie];int n,m;int size;int ans;void link (int r,int C) {s[c]++; C[size]=c; U[SIZE]=U[C];D [u[c]]=size; D[size]=c; U[c]=size; if (h[r]==-1) h[r]=l[size]=r[size]=size; else {l[size]=l[h[r]]; R[l[h[r]]]=size; R[SIZE]=H[R]; L[h[r]]=size; } size++;} void remove (int c) {int i,j; L[R[C]]=L[C]; R[L[C]]=R[C]; for (I=d[c];i!=c;i=d[i]) {for (J=r[i];j!=i;j=r[j]) {s[c[j]]--; U[D[J]]=U[J]; D[U[J]]=D[J]; }}}void resume (int c) {int i,j; for (I=u[c];i!=c;i=u[i]) {for (J=l[i];j!=i;j=l[j]) {s[c[j]]++; U[d[j]]=d[u[j]]=j; }} l[r[c]]=c; R[l[c]]=c;} void Dance (int k) {int min,i,j,c;if (r[0]==0) {if (ans>k) {ans=k;} return;} for (Min=row,i=r[0];i;i=r[i]) {if (Min>s[i]) {min=s[i];c=i;}} Remove (c); for (i=d[c];i!=c;i=d[i]) {for (J=r[i];j!=i;j=r[j]) {remove (C[j]);} Dance (k+1); for (J=l[i];j!=i;j=l[j]) {resume (c[j]);}} Resume (c);} int main () {int t,i,j,row;scanf ("%d", &t), while (t--) {int p;scanf ("%d%d%d", &n,&m,&p); int count=n*m; for (i=0;i<=n*m;i++) {s[i]=0; U[i]=d[i]=i; L[i+1]=i; r[i]=i+1;} R[n*m]=0;size=n*m+1;for (row=1;row<=p;row++) {h[row]=-1;int x1,y1,x2,y2;scanf ("%d%d%d%d",&x1,&y1,& X2,&Y2); for (i=x1;i<x2;i++) {for (j=y1;j<y2;j++) {link (row,i*m+j+1);}}} Ans=row;dance (0); if (Ans==row) {printf (" -1\n");} else{printf ("%d\n", ans);}}
Zoj 3210 3211 3212 It's a water problem, no explanation.
The 6th session of Zhejiang Province Program design contest Knot report summary zoj3202-3212