A. ABB

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define PB push_back
  4. #define ZERO (1e-10)
  5. #define INF int(1e9+1)
  6. #define CL(A,I) (memset(A,I,sizeof(A)))
  7. #define DEB printf("DEB!\n");
  8. #define D(X) cout<<" "<<#X": "<<X<<endl;
  9. #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
  10. typedef long long ll;
  11. typedef pair<ll,ll> pll;
  12. typedef vector<int> vi;
  13. typedef pair<int,int> ii;
  14. typedef vector<ii> vii;
  15. #define IN(n) int n;scanf("%d",&n);
  16. #define FOR(i, m, n) for (int i(m); i < n; i++)
  17. #define F(n) FOR(i,0,n)
  18. #define FF(n) FOR(j,0,n)
  19. #define FT(m, n) FOR(k, m, n)
  20. #define aa first
  21. #define bb second
  22. void ga(int N,int *A){F(N)scanf("%d",A+i);}
  23. #define MX (1<<20)
  24. ll pw(ll n,ll k,ll MOD){
  25. ll r(1);
  26. while(k){
  27. if(k&1)r*=n,r%=MOD;
  28. n*=n,n%=MOD,k>>=1;
  29. }
  30. return r;
  31. }
  32. ll inv(ll a,ll MOD){return pw(a,MOD-2,MOD);}
  33. struct HSH{
  34. int MOD,N,I[MX],F[MX],P;
  35. void ini(char*r,int M=1000000007,ll b=257){
  36. MOD=M,N=strlen(r),P=1,*I=1,I[1]=inv(b,MOD),*F=*r;
  37. FT(2,N)I[k]=I[k-1]*ll(I[1])%MOD;
  38. FT(1,N)P=P*b%MOD,F[k]=(ll(P)*r[k]+F[k-1])%MOD;
  39. }
  40. ll get(int b,int e){if(b>e)swap(b,e);return (F[e]-ll(b?F[b-1]:0)+MOD)*I[b]%MOD;}
  41. }t,T,r,R;
  42. char s[MX];
  43. int N,X=INF;
  44. bool isP(int b,int e){
  45. int H=(e-b+1)/2;
  46. if((e-b+1)&1)return t.get(b,b+H)==r.get(N-1-b-H,N-1-e)&&T.get(b,b+H)==R.get(N-1-b-H,N-1-e);
  47. return t.get(b,b+H-1)==r.get(N-1-b-H,N-1-e)&&T.get(b,b+H-1)==R.get(N-1-b-H,N-1-e);
  48. }
  49. int main(void){
  50. scanf("%d%s",&N,s);
  51. t.ini(s),T.ini(s,1e9+9,661);
  52. reverse(s,s+N),r.ini(s),R.ini(s,1e9+9,661);
  53. F(N)if(isP(i,N-1))return printf("%d\n",i),0;
  54. assert(0);
  55. return 0;
  56. }

B. Be Geeks!

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define PB push_back
  4. #define ZERO (1e-10)
  5. #define INF int(1e9+1)
  6. #define CL(A,I) (memset(A,I,sizeof(A)))
  7. #define DEB printf("DEB!\n");
  8. #define D(X) cout<<" "<<#X": "<<X<<endl;
  9. #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
  10. typedef long long ll;
  11. typedef pair<ll,ll> pll;
  12. typedef vector<int> vi;
  13. typedef pair<int,int> ii;
  14. typedef vector<ii> vii;
  15. #define IN(n) int n;scanf("%d",&n);
  16. #define FOR(i, m, n) for (int i(m); i < n; i++)
  17. #define F(n) FOR(i,0,n)
  18. #define FF(n) FOR(j,0,n)
  19. #define FT(m, n) FOR(k, m, n)
  20. #define aa first
  21. #define bb second
  22. void ga(int N,int *A){F(N)scanf("%d",A+i);}
  23. #define LG (18)
  24. #define MX (1<<LG)
  25. #define P2(v) (!(v&(v-1)))
  26. struct RMQx{
  27. int dp[MX][LG+2],G[MX],XX,O=-1;
  28. void ini(int*A,int n){
  29. if(!XX++)FT(1,MX)G[k]=O+=P2(k);
  30. F(n)dp[i][0]=i;
  31. FT(1,k-(1<<k)+n+1)F(n+1-(1<<k))
  32. if(A[dp[i][k-1]]>A[dp[i+(1<<(k-1))][k-1]])
  33. dp[i][k]=dp[i][k-1];
  34. else dp[i][k]=dp[i+(1<<(k-1))][k-1];
  35. }
  36. int qy(int *A,int L,int R){
  37. int j(G[R-L+1]);
  38. if(A[dp[L][j]]>=A[dp[R-(1<<j)+1][j]])
  39. return dp[L][j];
  40. return dp[R-(1<<j)+1][j];
  41. }
  42. }R;
  43. struct RMQg{
  44. int dp[MX][LG+2],G[MX],XX,O=-1;
  45. void ini(int *A,int n){
  46. if(!XX++)FT(1,MX)G[k]=O+=P2(k);
  47. F(n)dp[i][0]=A[i];
  48. FT(1,k-(1<<k)+n+1)F(n+1-(1<<k))
  49. dp[i][k]=__gcd(dp[i][k-1],dp[i+(1<<(k-1))][k-1]);
  50. }
  51. int qy(int L,int R){
  52. int j(G[R-L+1]);
  53. return __gcd(dp[L][j],dp[R-(1<<j)+1][j]);
  54. }
  55. }G;
  56. #define MOD 1000000007
  57. int N,A[MX],S,g,I,x,y;
  58. bool OK(int t){
  59. if(t==y)return 1;
  60. return G.qy(I,t)<g;
  61. }
  62. bool ok(int t){
  63. if(t==x)return 1;
  64. return G.qy(t,I)<g;
  65. }
  66. int bs(int B,int E){
  67. int M;
  68. while(B+3<E)
  69. if(ok(M=(B+E)>>1))B=M;
  70. else E=M-1;
  71. while(!ok(E))--E;
  72. return E;
  73. }
  74. int BS(int B,int E){
  75. int M;
  76. while(B<E)
  77. if(OK(M=(B+E)>>1))E=M;
  78. else B=M+1;
  79. return E;
  80. }
  81. vi X,Y;
  82. #define DF(B,E) (max(B,E)-min(B,E))
  83. int go(int b,int e){
  84. if(b>e)return 0;
  85. x=b-1,y=e+1;
  86. I=R.qy(A,b,e);
  87. int S=0,J=I,F=I;
  88. X.clear(),Y.clear();
  89. X.PB(I-1),Y.PB(I+1);
  90. while(J<=e)g=G.qy(I,J),J=BS(J,e+1),X.PB(J-1);
  91. J=I;
  92. while(J>=b)g=G.qy(J,I),J=bs(b-1,J),Y.PB(J+1);
  93. FT(1,(int)X.size())FOR(i,1,(int)Y.size())
  94. S=(S+ll(A[I])*__gcd(G.qy(I,X[k]),G.qy(Y[i],I))%MOD*DF(X[k],X[k-1])%MOD*DF(Y[i],Y[i-1]))%MOD;
  95. return (ll(S)+go(b,F-1)+go(F+1,e))%MOD;
  96. }
  97. int main(void){
  98. scanf("%d",&N),ga(N,A),R.ini(A,N),G.ini(A,N);
  99. printf("%d\n",go(0,N-1));
  100. return 0;
  101. }

C. Bob in Wonderland

  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <sstream>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. typedef long long int ll;
  16. typedef pair<int, int> pii;
  17.  
  18. #define PB push_back
  19. #define MP make_pair
  20.  
  21. #define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
  22. #define FORD(prom, a, b) for(int prom = (a); prom > (b); prom--)
  23. #define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
  24. #define R1(a) do{scanf("%d", &(a));}while(0)
  25. #define R2(a, b) do{scanf("%d%d", &(a), &(b));}while(0)
  26. #define R3(a, b, c) do{scanf("%d%d%d", &(a), &(b), &(c));}while(0)
  27. #define SV(vec) do{int s_v_;scanf("%d", &(s_v_));vec.PB(s_v_);}while(0)
  28. #define MM(co, cim) memset((co), (cim), sizeof((co)))
  29. #define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
  30. #define INF 1000000007
  31.  
  32. int n, from, to, res;
  33. vector<int> g[300014];
  34.  
  35. int main ()
  36. {
  37. R1(n);
  38. FOR(i, 0, n - 1)
  39. {
  40. R2(from, to);
  41. --from;
  42. --to;
  43. g[from].PB(to);
  44. g[to].PB(from);
  45. }
  46. res = 0;
  47. FOR(i, 0, n) res += max((int)g[i].size() - 2, 0);
  48. printf("%d\n", res);
  49. return 0;
  50. }

D. Deep800080

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. typedef double ld;
  5. typedef vector<ll> vi;
  6. // push_back insert lower_bound upper_bound erase
  7. #define F(a) for ( ll i = 0; i < (ll)(a); ++i )
  8.  
  9. #define EPS (1e-8)
  10. bool eq(ld a, ld b) { return fabs(a-b) <= fabs(a+b) * EPS; }
  11.  
  12. struct Pt{
  13. ld x, y;
  14. ll flag;
  15. bool operator <(const Pt &p) const {
  16. return x < p.x-EPS || (eq(x, p.x) && y < p.y-EPS);
  17. }
  18. Pt operator+(const Pt &p){ return{x+p.x, y+p.y}; }
  19. Pt operator-(const Pt &p){ return{x-p.x, y-p.y}; }
  20. Pt operator-(){ return{-x, -y}; }
  21. Pt operator*(ld d){ return {x*d, y*d}; }
  22. Pt operator/(ld d){ return {x/d, y/d}; }
  23. friend ostream &operator<<(ostream &os, const Pt &a){ os<<a.x<<' '<<a.y; return os; }
  24. friend istream &operator>>(istream &is, Pt &a){ is>>a.x>>a.y; return is; }
  25. };
  26. struct Line {
  27. Pt a, b;
  28. bool operator<(Line &l){
  29. Pt v=b-a, w=l.b-l.a;
  30. return atan2(v.y, v.x) < atan2(w.y, w.x);
  31. }
  32. };
  33. struct Cir {
  34. Pt s;
  35. ld r;
  36. Pt point(double a)const{ return {s.x+cos(a)*r, s.y+sin(a)*r}; }
  37. bool operator<(const Cir &a){ return r<a.r; }
  38. };
  39. ld vec(Pt a, Pt b){ return a.x*b.y-a.y*b.x; }
  40. ld vec(Pt a, Pt b, Pt c){ return vec(b-a, c-a); }
  41. ld norm(Pt a){ return hypot(a.x, a.y); }
  42. ld line_point_dist(Line l, Pt p){ return fabs(vec(p-l.a, l.b-l.a)/norm(l.b-l.a)); }
  43. Pt scale_to(Pt a, ld res){ return a*res/norm(a); }
  44. Pt normal(Pt a){ ld n=norm(a); return {-a.y/n, a.x/n}; }
  45. Pt lines_intersection(Line p, Line q){
  46. Pt v=p.b-p.a;
  47. Pt w=q.b-q.a;
  48. ld t=vec(w, p.a-q.a)/vec(v, w);
  49. return p.a+v*t;
  50. }
  51. Pt line_point_closest_point(Line a, Pt b){
  52. return lines_intersection(a, {b, b+normal(a.b-a.a)});
  53. }
  54. ld circle_line_distance(Cir &a, Line &b){
  55. return max(line_point_dist(b, a.s)-a.r, 0.);
  56. }
  57. ll circle_line_intersection(Cir a, Line b, Pt &p1, Pt &p2){
  58. if(circle_line_distance(a, b)>0)return 0;
  59. Pt dv = line_point_closest_point(b, a.s);
  60. ld d = norm(dv-a.s);
  61. ld h = sqrt(a.r*a.r-d*d);
  62. Pt n = scale_to(b.b-b.a, h);
  63. p1 = dv+n;
  64. p2 = dv-n;
  65. return 1+!(eq(p1.x, p2.x) && eq(p1.y, p2.y)); // returns the number of intersections
  66. }
  67.  
  68. ll solve(ll N, ld R, Line l, vector<Cir> a){
  69. for(Cir &p:a) p.r = R+0.00001;
  70. vector<Pt> p;
  71. F(N){
  72. Pt q, w;
  73. ll e = circle_line_intersection(a[i], l, q, w);
  74. if(e){
  75. q.flag = +1;
  76. w.flag = -1;
  77. p.push_back(q);
  78. p.push_back(w);
  79. }
  80. }
  81. sort(p.begin(), p.end());
  82. //for(Pt q:p)cerr<<q<<endl;
  83. ll mx=0,s=0;
  84. for(Pt q : p){
  85. s += q.flag;
  86. mx = max(mx, abs(s));
  87. }
  88. return mx;
  89. }
  90.  
  91. int main(){
  92. ll N;
  93. ld R;
  94. Line l;
  95. l.a = {0, 0};
  96. cin >> N >> R >> l.b;
  97. vector<Cir> a(N);
  98. for(Cir &p:a) cin >> p.s;
  99. ll mx=solve(N, R, l, a);
  100. //ll mx2=solve(N, R+0.00101, l, a); // safe margin
  101. //assert(mx==mx2);
  102. cout<<mx<<endl;
  103. return 0;
  104. }

E. Zeldain Garden

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define PB push_back
  4. #define ZERO (1e-10)
  5. #define INF int(1e9+1)
  6. #define CL(A,I) (memset(A,I,sizeof(A)))
  7. #define DEB printf("DEB!\n");
  8. #define D(X) cout<<" "<<#X": "<<X<<endl;
  9. #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
  10. typedef long long ll;
  11. typedef pair<ll,ll> pll;
  12. typedef vector<int> vi;
  13. typedef pair<int,int> ii;
  14. typedef vector<ii> vii;
  15. #define IN(n) int n;scanf("%d",&n);
  16. #define FOR(i, m, n) for (int i(m); i < n; i++)
  17. #define F(n) FOR(i,0,n)
  18. #define FF(n) FOR(j,0,n)
  19. #define FT(m, n) FOR(k, m, n)
  20. #define aa first
  21. #define bb second
  22. void ga(int N,int *A){F(N)scanf("%d",A+i);}
  23. ll X,N,Q,S;
  24. ll go(ll N){
  25. if(!N)return 0;
  26. Q=sqrt(N+ZERO),S=0;
  27. for(ll i=1;i<=Q;++i)S+=N/i;
  28. return ll(S*__int128(2)-__int128(Q)*Q);
  29. }
  30. int main(void){
  31. scanf("%lld%lld",&X,&N);
  32. printf("%lld\n",go(N)-go(X-1));
  33. return 0;
  34. }

F. Light Emitting Hindenburg

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define PB push_back
  4. #define ZERO (1e-10)
  5. #define INF int(1e9+1)
  6. #define CL(A,I) (memset(A,I,sizeof(A)))
  7. #define DEB printf("DEB!\n");
  8. #define D(X) cout<<" "<<#X": "<<X<<endl;
  9. #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
  10. typedef long long ll;
  11. typedef pair<ll,ll> pll;
  12. typedef vector<int> vi;
  13. typedef pair<int,int> ii;
  14. typedef vector<ii> vii;
  15. #define IN(n) int n;scanf("%d",&n);
  16. #define FOR(i, m, n) for (int i(m); i < n; i++)
  17. #define F(n) FOR(i,0,n)
  18. #define FF(n) FOR(j,0,n)
  19. #define FT(m, n) FOR(k, m, n)
  20. #define aa first
  21. #define bb second
  22. void ga(int N,int *A){F(N)scanf("%d",A+i);}
  23. vi A,B;
  24. int N,K,a,o=~0;
  25. int main(void){
  26. scanf("%d%d",&N,&K);
  27. F(N)scanf("%d",&a),A.PB(a);
  28. for(int i=1<<29;i;i>>=1){
  29. B.clear();
  30. for(int h:A)if(h&i)B.PB(h);
  31. if((int)B.size()>=K)A=B;
  32. }
  33. for(int h:A)o&=h;
  34. printf("%d\n",o);
  35. return 0;
  36. }

G. K==S

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define PB push_back
  4. #define ZERO (1e-10)
  5. #define INF int(1e9+1)
  6. #define CL(A,I) (memset(A,I,sizeof(A)))
  7. #define DEB printf("DEB!\n");
  8. #define D(X) cout<<" "<<#X": "<<X<<endl;
  9. #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
  10. typedef long long ll;
  11. typedef pair<ll,ll> pll;
  12. typedef vector<int> vi;
  13. typedef pair<int,int> ii;
  14. typedef vector<ii> vii;
  15. #define IN(n) int n;scanf("%d",&n);
  16. #define FOR(i, m, n) for (int i(m); i < n; i++)
  17. #define F(n) FOR(i,0,n)
  18. #define FF(n) FOR(j,0,n)
  19. #define FT(m, n) FOR(k, m, n)
  20. #define aa first
  21. #define bb second
  22. void ga(int N,int *A){F(N)scanf("%d",A+i);}
  23. #define MX (106)
  24. #define AL (26)
  25. int g[MX][AL],f[MX],E,q[MX],O[MX];
  26. void ini(){E=1;F(AL)g[0][i]=0;CL(f,0),CL(O,0);}
  27. void add(char*s){
  28. int L=strlen(s),u=0,c;
  29. F(L){
  30. if(!g[u][c=s[i]-97]){
  31. g[u][c]=E++;
  32. F(AL)g[E-1][i]=0;
  33. }
  34. u=g[u][c];
  35. }
  36. O[u]=1;
  37. }
  38. void bld(){
  39. int x,r,b=-1,e=0,u;
  40. F(AL)if(g[0][i])f[g[0][i]]=0,q[e++]=g[0][i];
  41. while(++b<e)F(AL){
  42. x=g[u=q[b]][i],r=g[f[u]][i];
  43. if(!x)g[u][i]=r;
  44. else{
  45. q[e++]=x,f[x]=r;
  46. O[x]|=O[r];
  47. }
  48. }
  49. }
  50. #define MM (MX)
  51. void mul(int A[MM][MM],int B[MM][MM],int R[MM][MM],int W,int M){
  52. F(W)FF(W)R[i][j]=0;
  53. F(W)FF(W){
  54. ll D=M*1ll*M,S=0;;
  55. FT(0,W)if((S+=A[i][k]*1ll*B[k][j])>=D)S-=D;
  56. R[i][j]=S%M;
  57. }
  58. }
  59. void pw(int M[MM][MM],int R[MM][MM],int W,ll k,int MD){
  60. static int E[MM][MM],H[MM][MM];
  61. F(W)FF(W)R[i][j]=E[i][j]=i==j;
  62. while(k){
  63. if(k&1)mul(E,M,R,W,MD),memcpy(E,R,sizeof(E));
  64. mul(M,M,H,W,MD);
  65. memcpy(M,H,sizeof(H));
  66. k>>=1;
  67. }
  68. }
  69. #define MOD 1000000007
  70. ll pw(ll n,ll k){
  71. ll r(1);
  72. while(k){
  73. if(k&1)r*=n,r%=MOD;
  74. n*=n,n%=MOD;
  75. k>>=1;
  76. }
  77. return r;
  78. }
  79. char s[MX];
  80. int L,N,Q,M[MX][MX],R[MX][MX];
  81. int main(void){
  82. scanf("%d%d",&N,&Q),ini();
  83. F(Q){
  84. scanf("%*d%s",s);
  85. add(s);
  86. }
  87. bld();
  88. F(E)FF(26)if(O[g[i][j]])++M[i][E];
  89. else ++M[i][g[i][j]];
  90. M[E][E]=26;
  91. pw(M,R,E+1,N,MOD);
  92. printf("%lld\n",(pw(26,N)-R[0][E]+MOD)%MOD);
  93. return 0;
  94. }

H. Ponk Warshall

  1. /**
  2. * CTU Open 2019
  3. * Problem Solution: DNA Swaps
  4. */
  5.  
  6. #include <cassert>
  7. #include <iostream>
  8. #include <vector>
  9. #include <set>
  10. #include <map>
  11.  
  12. using namespace std;
  13.  
  14. int main(void)
  15. {
  16. map<char, int> letterid {{'A', 0}, {'C', 1}, {'G', 2}, {'T', 3}};
  17. string dna1, dna2;
  18. while (cin >> dna1 >> dna2)
  19. {
  20. int len = dna1.length();
  21. vector<vector<int>> ecnt(4, vector<int>(4));
  22. for (int i = 0; i < len; ++i) {
  23. int l1 = letterid[dna1[i]];
  24. int l2 = letterid[dna2[i]];
  25. ++ecnt[l1][l2];
  26. }
  27. int result = 0;
  28. for (int i = 0; i < 4; ++i)
  29. for (int j = 0; j < 4; ++j)
  30. if(i != j && ecnt[i][j] >= ecnt[j][i]) {
  31. result += ecnt[j][i];
  32. ecnt[i][j] -= ecnt[j][i];
  33. ecnt[j][i] = 0;
  34. }
  35. for (int i = 0; i < 4; ++i)
  36. for (int j = 0; j < 4; ++j)
  37. for (int k = 0; k < 4; ++k) {
  38. if(i == j || i == k || j == k)
  39. continue;
  40. int min = std::min(std::min(ecnt[i][j], ecnt[j][k]), ecnt[k][i]);
  41. result += 2 * min;
  42. ecnt[i][j] -= min;
  43. ecnt[j][k] -= min;
  44. ecnt[k][i] -= min;
  45. }
  46. int rest = 0;
  47. for (int i = 0; i < 4; ++i)
  48. for (int j = 0; j < 4; ++j)
  49. if(i != j)
  50. rest += ecnt[i][j];
  51. result += 3 * rest / 4;
  52. cout << result << endl;
  53. }
  54. return 0;
  55. }

I. Saba1000kg

  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <sstream>
  8. #include <map>
  9. #include <set>
  10. #include <queue>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. typedef long long int ll;
  16. typedef pair<int, int> pii;
  17.  
  18. #define PB push_back
  19. #define MP make_pair
  20.  
  21. #define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
  22. #define FORD(prom, a, b) for(int prom = (a); prom > (b); prom--)
  23. #define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
  24. #define R1(a) do{scanf("%d", &(a));}while(0)
  25. #define R2(a, b) do{scanf("%d%d", &(a), &(b));}while(0)
  26. #define R3(a, b, c) do{scanf("%d%d%d", &(a), &(b), &(c));}while(0)
  27. #define SV(vec) do{int s_v_;scanf("%d", &(s_v_));vec.PB(s_v_);}while(0)
  28. #define MM(co, cim) memset((co), (cim), sizeof((co)))
  29. #define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
  30. #define INF 1000000007
  31.  
  32. int n, m, q, from, to, sqn, qs, x, u[100014], cc;
  33. vector<int> g[100014], qvec, ng[100014];
  34. set<pii> edg;
  35. set<int> qset;
  36.  
  37. pair<int, int> ge (int from, int to)
  38. {
  39. return MP(min(from, to), max(from, to));
  40. }
  41.  
  42. void go (int x)
  43. {
  44. if (u[x]) return;
  45. u[x] = 1;
  46. FOR(i, 0, (int)ng[x].size()) go(ng[x][i]);
  47. }
  48.  
  49. int main ()
  50. {
  51. R3(n, m, q);
  52. FOR(i, 0, m)
  53. {
  54. R2(from, to);
  55. g[from].PB(to);
  56. g[to].PB(from);
  57. edg.insert(ge(from, to));
  58. }
  59. sqn = 1;
  60. while (sqn * sqn < n) ++sqn;
  61. FOR(qn, 0, q)
  62. {
  63. qvec.clear();
  64. qset.clear();
  65. R1(qs);
  66. FOR(i, 0, qs)
  67. {
  68. R1(x);
  69. qvec.PB(x);
  70. qset.insert(x);
  71. ng[x].clear();
  72. u[x] = 0;
  73. }
  74. if (qs <= sqn)
  75. {
  76. FOR(i, 0, qs) FOR(j, i + 1, qs)
  77. {
  78. from = qvec[i];
  79. to = qvec[j];
  80. if (edg.count(ge(from, to)))
  81. {
  82. ng[from].PB(to);
  83. ng[to].PB(from);
  84. }
  85. }
  86. }
  87. else
  88. {
  89. FOR(i, 0, qs) FOR(j, 0, (int)g[qvec[i]].size())
  90. {
  91. from = qvec[i];
  92. to = g[from][j];
  93. if (qset.count(to))
  94. {
  95. ng[from].PB(to);
  96. ng[to].PB(from);
  97. }
  98. }
  99. }
  100. cc = 0;
  101. FOR(i, 0, qs) if (!u[qvec[i]])
  102. {
  103. go(qvec[i]);
  104. ++cc;
  105. }
  106. printf("%d\n", cc);
  107. }
  108.  
  109. return 0;
  110. }

J. Screamers in the Storm

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. typedef double ld;
  5. typedef vector<ll> vi;
  6. // push_back insert lower_bound upper_bound erase
  7.  
  8. #define F(a) for ( ll i = 0; i < (ll)(a); ++i )
  9.  
  10. // 1e-12 is too low
  11. #define EPS (1e-10)
  12. //bool eq(ld a, ld b) { return fabs(a-b) <= fabs(a+b) * EPS; } // cannot compare very small numbers to each other
  13. bool eq(ld a, ld b) { return abs(a-b) <= EPS; }
  14. int dcmp(ld x){ return (fabs(x)<EPS) ? 0 : (x<0 ? -1 : 1); }
  15.  
  16. struct Pt{
  17. ld x, y;
  18. bool operator <(const Pt &p) const {
  19. return x < p.x-EPS || (eq(x, p.x) && y < p.y-EPS);
  20. }
  21. Pt operator+(const Pt &p){ return{x+p.x, y+p.y}; }
  22. Pt operator-(const Pt &p){ return{x-p.x, y-p.y}; }
  23. Pt operator-(){ return{-x, -y}; }
  24. Pt operator*(ld d){ return {x*d, y*d}; }
  25. Pt operator/(ld d){ return {x/d, y/d}; }
  26. friend ostream &operator<<(ostream &os, const Pt &a){ os<<a.x<<' '<<a.y; return os; }
  27. friend istream &operator>>(istream &is, Pt &a){ is>>a.x>>a.y; return is; }
  28. };
  29. struct Line {
  30. Pt a, b;
  31. ll side; // 0=east-west, 1=north-south, 2=outside the roof
  32. bool operator<(Line &l){
  33. Pt v=b-a, w=l.b-l.a;
  34. return atan2(v.y, v.x) < atan2(w.y, w.x);
  35. }
  36. friend ostream &operator<<(ostream &os, const Line &l){ os<<l.a<<' '<<l.b; return os; }
  37. };
  38. ld vec(Pt a, Pt b){ return a.x*b.y-a.y*b.x; }
  39. ld vec(Pt a, Pt b, Pt c){ return vec(b-a, c-a); }
  40. ld dot(Pt a, Pt b){ return a.x*b.x+a.y*b.y; }
  41. ld norm(Pt a){ return hypot(a.x, a.y); }
  42. ld line_point_dist(Line l, Pt p){ return fabs(vec(p-l.a, l.b-l.a)/norm(l.b-l.a)); }
  43. Pt scale_to(Pt a, ld res){ return a*res/norm(a); }
  44. Pt normal(Pt a){ ld n=norm(a); return {-a.y/n, a.x/n}; }
  45. ld points_distance(Pt a, Pt b){ return norm(b-a); }
  46. ld angle2(Pt a, Pt b){
  47. a=scale_to(a, 1);
  48. b=scale_to(b, 1);
  49. ld ang=acos(dot(a, b));
  50. //ld ang=acos(dot(a, b)/norm(a)/norm(b));
  51. if(ang>M_PI)ang-=2*M_PI;
  52. return ang;
  53. }
  54. ld angle(Pt a, Pt b){
  55. ld ang=atan2(vec(a,b),dot(a,b));
  56. if(ang>M_PI)ang-=2*M_PI;
  57. if(ang<-M_PI)ang+=2*M_PI;
  58. return ang;
  59. }
  60. Pt old_lines_intersection(Line p, Line q){
  61. Pt v=p.b-p.a;
  62. Pt w=q.b-q.a;
  63. ld t=vec(w, p.a-q.a)/vec(v, w);
  64. return p.a+v*t;
  65. }
  66. Pt lines_intersection(Line p, Line q){
  67. Pt v=p.b-p.a;
  68. Pt w=q.b-q.a;
  69. ld t=vec(w, p.a-q.a)/vec(v, w);
  70. Pt res=p.a+v*t;
  71. //assert(fabs((ld)0 - vec(p.a,p.b,res))<1e-2);
  72. //assert(fabs((ld)0 - vec(q.a,q.b,res))<1e-2);
  73. return res;
  74. }
  75. Pt line_point_closest_point(Line a, Pt b){
  76. return lines_intersection(a, {b, b+normal(a.b-a.a)});
  77. }
  78. bool is_point_on_segment(Pt p, Line s){
  79. return dcmp(vec(s.a-p, s.b-p))==0 && dcmp(dot(s.a-p, s.b-p))<=0;
  80. }
  81. bool is_point_in_polygon_clock(Pt p, vector<Line> &lines){
  82. for(Line &l:lines)if(is_point_on_segment(p, l))return true;
  83. ld sum = 0;
  84. for(Line &l:lines){
  85. ld ang=angle(l.a-p, l.b-p);
  86. //cerr<<"angle: "<<ang<<endl;
  87. sum += ang;
  88. }
  89. //cerr<<"sum: "<<sum<<", eq to 0: "<<eq(sum,0)<<endl;
  90. return !eq(sum, 0);
  91. }
  92.  
  93. int is_point_in_polygon(Pt p, vector<Line> &lines){
  94. ll n=lines.size(), wn=0;
  95. for(int i=0; i<n; ++i){
  96. Pt &p1 = lines[i].a;
  97. Pt &p2 = lines[i].b;
  98. if(is_point_on_segment(p, lines[i])) return 1;//point on the border
  99. int k = dcmp(vec(p2-p1, p-p1));
  100. int d1 = dcmp(p1.y-p.y);
  101. int d2 = dcmp(p2.y-p.y);
  102. if(k>0 && d1<=0 && d2>0) wn++;
  103. if(k<0 && d2<=0 && d1>0) wn--;
  104. }
  105. return wn;// wn=1 point is inside, 0 outisde
  106. }
  107. bool point_is_inside2(Pt p, vector<Line> &poly){
  108. for(Line &l:poly)if(is_point_on_segment(p, l))return true;
  109. ll r=0;
  110. p.x += EPS/2;
  111. p.y += EPS/2;
  112. for(int i=0; i<4; ++i){
  113. ll cnt = 0;
  114. for(Line &l:poly){
  115. if(p.y < l.a.y)
  116. if(l.a.x < p.x+EPS && p.x < l.b.x || l.b.x < p.x+EPS && p.x < l.a.x)
  117. cnt+=1;
  118. }
  119. if((cnt%2) == 0) r++;
  120. swap(p.x,p.y);
  121. p.y=-p.y;
  122. }
  123. return r<4;
  124. }
  125. bool point_is_inside(Pt p, vector<Line> &poly){
  126. vector<bool> res;
  127. //res.push_back(point_is_inside2(p, poly));
  128. //res.push_back(is_point_in_polygon(p, poly));
  129. res.push_back(is_point_in_polygon_clock(p, poly));
  130. assert(res.size());
  131. //cerr<<"inside?: "; F(res.size())cerr<<res[i]<<' '; cerr<<endl;
  132. F(res.size()-1){
  133. if(res[i]!=res[i+1]){
  134. cerr<<"point is inside results: "; for(ll n:res)cerr<<n<<' '; cerr<<endl;
  135. cerr<<"and polygon:";for(Line l:poly)cerr<<" ["<<l.a<<"]"; cerr<<endl;
  136. cerr<<fixed<<setprecision(12);
  137. cerr<<"for point ["<<p<<"]\n";
  138. cerr<<endl;
  139. //cerr<<is_point_in_polygon_clock(p, poly)<<endl;
  140. assert(res[i]==res[i+1]);
  141. }
  142. }
  143. return res[0];
  144. }
  145.  
  146. ll N, M;
  147. Line l;
  148. ld line_length, line_ang;
  149. vector<Pt> a;
  150. vector<Line> lines;
  151. void load(){
  152. cin>>N;
  153. cin>>l.a>>l.b;
  154. Pt d=l.b-l.a;
  155. a.assign(N, {});
  156. F(N) cin>>a[i];
  157. lines.assign(N, {});
  158. F(N) lines[i]={a[i], a[(i+1)%N]};
  159. F(N) lines[i].side=eq(lines[i].a.y,lines[i].b.y);
  160. }
  161.  
  162. Pt point_from_ratio(ld ratio){
  163. return l.a*(1-ratio)+l.b*ratio;
  164. }
  165.  
  166. pair<ll,ld> find_closest_side(ld ratio){
  167. if(!(ratio>-2*EPS && ratio<1+2*EPS)){
  168. cerr<<"ratio: "<<ratio<<endl;
  169. assert(false);
  170. }
  171. Pt center = point_from_ratio(ratio);
  172. ld dist=1e62;
  173. ll id=-1;
  174. bool inside = point_is_inside(center, lines);
  175. F(N){
  176. Pt d1=center-lines[i].a;
  177. Pt d2=center-lines[i].b;
  178. ld d=dist;
  179. if(!inside || vec(lines[i].a, lines[i].b, center)>=-EPS){
  180. if(d1.x==d2.x && (d1.y*d2.y<0 || min(abs(d1.y),abs(d2.y)) <= abs(d1.x))) { d=min(d, abs(d1.x)); }
  181. if(d1.y==d2.y && (d1.x*d2.x<0 || min(abs(d1.x),abs(d2.x)) <= abs(d1.y))) { d=min(d, abs(d1.y)); }
  182. }
  183. //cerr<<"point "<<center<<" is "<<d<<" close to "<<i<<endl;
  184. if(d<dist-EPS){ // strictly prefer the first found
  185. dist=d;
  186. id=i;
  187. }
  188. }
  189. assert(id!=-1);
  190. //if(ratio<0.1){
  191. //cerr<<"closest to "<<id<<" -- ["<<center<<"] in:"<<inside<<' '<<", dist: "<<dist<<endl;
  192. //}
  193. //cerr<<"closest side to "<<center<<" is "<<id<<endl;
  194. return {inside?id:(-1-id), dist};
  195. }
  196.  
  197. struct Res{
  198. ld ratio;
  199. ll eid, state;
  200. Pt point;
  201.  
  202. Res(ld ratio, ll eid):ratio(ratio),eid(eid){
  203. point = point_from_ratio(ratio+EPS);
  204. eid=find_closest_side(ratio).first;
  205. state = (eid<0) ? 2 : lines[eid].side; // outside is 2
  206. }
  207. };
  208. bool segment_intersect(Line s, Line t){
  209. ld c1=vec(s.b-s.a, t.a-s.a), c2=vec(s.b-s.a, t.b-s.a);
  210. ld c3=vec(t.b-t.a, s.a-t.a), c4=vec(t.b-t.a, s.b-t.a);
  211. return dcmp(c1)*dcmp(c2)<EPS && dcmp(c3)*dcmp(c4)<EPS;
  212. }
  213. bool line_line_equal_dir(Line a, Line b){
  214. return eq(0,vec(a.b-a.a, b.b-b.a));
  215. }
  216. pair<ld,ll> bsearch(ld low, ld high, ll low_edge_id){
  217. ld mid;
  218. //cerr<<setprecision(16);
  219. const ld max_step=0.5;
  220. while(low < high-EPS){
  221. mid = (low+high)/2;
  222. ld step_size = line_length*(mid-low);
  223. if(step_size > max_step){ // the biggest allowed step
  224. mid = low+max_step/line_length;
  225. }
  226. //cerr<<line_length<<' '<<low<<' '<<mid<<' '<<high<<endl;
  227. ll closest_eid = find_closest_side(mid).first;
  228. //cerr<<"FIND: "<<mid<<" -> "<<closest_eid<<" vs "<<low_edge_id<<" : "<<(closest_eid!=low_edge_id)<<endl;
  229. if(closest_eid != low_edge_id) high = mid;
  230. else low = mid+EPS;
  231. }
  232. return {high, find_closest_side(high).first};
  233. }
  234.  
  235. int main(){
  236. load();
  237. Pt ldif=l.b-l.a;
  238. line_length=hypot(ldif.x, ldif.y);
  239. line_ang=atan2(ldif.y, ldif.x);
  240. ll first=find_closest_side(0.0).first;
  241. ll last=find_closest_side(1.0).first;
  242. if(first<0){ cerr<<"FIRST: "<<first<<endl; }
  243. assert(first>=0);
  244. if(last<0){ cerr<<"LAST: "<<last<<endl; }
  245. assert(last>=0);
  246. vector<Res> path;
  247. path.push_back({0.0, first});
  248. ll current_eid=first;
  249. ld current_ratio=0.0;
  250. //cout<<"0\n";return 0;
  251.  
  252. // build all interesting points
  253. vector<Pt> crosses;
  254. // which cross with outer lines
  255. for(Line a:lines){
  256. if(segment_intersect(l, a)){
  257. Pt cross_point = lines_intersection(l, a);
  258. crosses.push_back(cross_point);
  259. }
  260. }
  261. // or lie at possible roof angle
  262. for(int i=0; i<lines.size(); ++i){ // even == horiz/vert
  263. Line q=lines[i];
  264. Pt qd=q.b-q.a;
  265. //ll sq=qd.x+qd.y;
  266. if(eq(qd.x,0))continue;
  267. for(int j=0; j<lines.size(); ++j){ // odd == vert/horiz
  268. Line w=lines[j];
  269. Pt wd=w.b-w.a;
  270. if(eq(wd.y,0))continue;
  271. //ll sw=wd.x+wd.y;
  272. //ld dir=sw*sq>0 ? -1. : 1.;
  273. Pt origin = lines_intersection(q, w);
  274. //cerr<<"o: "<<origin<<", "<<q.a<<' '<<q.b<<' '<<w.a<<' '<<w.b<<endl;
  275. Line ne={origin, origin+Pt{1, 1}};
  276. Line nr={origin, origin+Pt{1, -1}};
  277. if(!line_line_equal_dir(ne, l)){
  278. Pt cross_point = lines_intersection(ne, l);
  279. crosses.push_back(cross_point);
  280. }
  281. if(!line_line_equal_dir(nr, l)){
  282. Pt cross_point = lines_intersection(nr, l);
  283. crosses.push_back(cross_point);
  284. }
  285. }
  286. }
  287.  
  288. vector<ld> interesting_ratios;
  289. interesting_ratios.push_back(0.);
  290. interesting_ratios.push_back(1.);
  291. ld prev_ratio=-1;
  292. for(Pt cross:crosses){
  293. ld dist=points_distance(l.a, cross);
  294. //cerr<<cross<<' '<<dist<<endl;
  295. //ld mn_ratio=(dist-1e-2) / line_length;
  296. //ld mx_ratio=(dist+1e-2) / line_length;
  297. ld ratio=dist / line_length + 3*EPS;
  298. if((abs(ratio-prev_ratio)>EPS/2) && ratio>=-EPS && ratio < 1+EPS){
  299. interesting_ratios.push_back(ratio);
  300. prev_ratio=ratio;
  301. }
  302. }
  303. sort(interesting_ratios.begin(), interesting_ratios.end());
  304.  
  305. for(ld new_ratio : interesting_ratios){
  306. ll new_eid = find_closest_side(new_ratio).first;
  307. path.push_back({new_ratio, new_eid});
  308. }
  309. path.push_back({1.0, last});
  310. ld side_sum[3]; side_sum[0]=side_sum[1]=side_sum[2]=0; // north-south, east-west, outside
  311. ll last_side=-2;
  312. F(path.size()-1){
  313. ld dif=path[i+1].ratio-path[i].ratio;
  314. if(dif>EPS){
  315. ld eid=path[i].eid;
  316. ld ratio=path[i].ratio;
  317. //Pt center=l.a*(1-ratio)+l.b*ratio;
  318. ll side=path[i].state;
  319. assert(side >= 0 && side <= 2);
  320. side_sum[side]+=dif;
  321. //if(last_side != side){
  322. //cerr<<fixed<<setprecision(12);
  323. //cerr<<"add ref "<<ratio<<" to "<<side<<endl;
  324. //last_side = side;
  325. //}
  326. }
  327. }
  328. ld sum=side_sum[0]*(hypot(1, abs(cos(line_ang))))+side_sum[1]*(hypot(1, abs(sin(line_ang))))+side_sum[2];
  329. ld res=sum*hypot(ldif.x, ldif.y);
  330. cout<<fixed<<setprecision(12);
  331. cout<<res<<endl;
  332.  
  333. //cerr<<"sol: \n";F(3){ cerr<<"sum: "<<i<<": "<<side_sum[i]<<endl; }
  334. //ld sm=0;F(3)sm+=side_sum[i]; cerr<<"sumsum: "<<sm<<endl;
  335.  
  336. //for(ld r:interesting_ratios){ cerr<<r<<' '; } cerr<<endl;
  337. // only for drawing testcases visual correctness check:
  338. //cout<<fixed<<setprecision(6);
  339. //for(auto p:path){
  340. //auto pr=find_closest_side(p.ratio);
  341. ////ll id = pr.first;
  342. //ld dist = pr.second;
  343. //cout<<p.point<<' '<<max((ld)0.1,dist)<<' '<<(p.state!=2 ? p.state : -1)<<endl;
  344. //}
  345. return 0;
  346. }

K. The Bugs

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define PB push_back
  4. #define ZERO (1e-10)
  5. #define INF int(1e9+1)
  6. #define CL(A,I) (memset(A,I,sizeof(A)))
  7. #define DEB printf("DEB!\n");
  8. #define D(X) cout<<" "<<#X": "<<X<<endl;
  9. #define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
  10. typedef long long ll;
  11. typedef pair<ll,ll> pll;
  12. typedef vector<int> vi;
  13. typedef pair<int,int> ii;
  14. typedef vector<ii> vii;
  15. #define IN(n) int n;scanf("%d",&n);
  16. #define FOR(i, m, n) for (int i(m); i < n; i++)
  17. #define F(n) FOR(i,0,n)
  18. #define FF(n) FOR(j,0,n)
  19. #define FT(m, n) FOR(k, m, n)
  20. #define aa first
  21. #define bb second
  22. void ga(int N,int *A){F(N)scanf("%d",A+i);}
  23. #include <ext/pb_ds/assoc_container.hpp>
  24. using namespace __gnu_pbds;
  25. struct TP{
  26. typedef int tp;
  27. tree<tp,null_type,less<tp>,rb_tree_tag,tree_order_statistics_node_update> T;
  28. void add(tp a){T.insert(a);}
  29. void del(tp a){T.erase(a);}
  30. int cnt(tp a){return T.order_of_key(a);}
  31. tp kth(int a){return *T.find_by_order(a);}
  32. int gt(tp b,tp e){return cnt(e+1)-cnt(b);}
  33. int sz(){return T.size();}
  34. void clr(){T.clear();}
  35. int mn(){return kth(0);}
  36. int mx(){return kth(sz()-1);}
  37. }T;
  38. #define LG (18)
  39. #define MX (1<<LG)
  40. #define P2(v) (!(v&(v-1)))
  41. struct RMQ{
  42. int dp[LG+2][MX],XX,O=-1,G[MX];
  43. void ini(int*A,int n){
  44. if(!XX++)FT(1,MX)G[k]=O+=P2(k);
  45. F(n)dp[0][i]=i;
  46. FT(1,k-(1<<k)+n+1)F(n+1-(1<<k))
  47. if(A[dp[k-1][i]]<A[dp[k-1][i+(1<<(k-1))]])
  48. dp[k][i]=dp[k-1][i];
  49. else dp[k][i]=dp[k-1][i+(1<<(k-1))];
  50. }
  51. int qy(int*A,int L,int R){
  52. const int j=G[R-L+1];
  53. if(A[dp[j][L]]<=A[dp[j][R-(1<<j)+1]])
  54. return A[dp[j][L]];
  55. return A[dp[j][R-(1<<j)+1]];
  56. }
  57. }b;
  58. struct RMQ2{
  59. int dp[MX][LG+2],G[MX],XX,O=-1;
  60. void ini(int*A,int n){
  61. if(!XX++)FT(1,MX)G[k]=O+=P2(k);
  62. F(n)dp[i][0]=i;
  63. FT(1,k-(1<<k)+n+1)F(n+1-(1<<k))
  64. if(A[dp[i][k-1]]>A[dp[i+(1<<(k-1))][k-1]])
  65. dp[i][k]=dp[i][k-1];
  66. else dp[i][k]=dp[i+(1<<(k-1))][k-1];
  67. }
  68. int qy(int *A,int L,int R){
  69. int j(G[R-L+1]);
  70. if(A[dp[L][j]]>=A[dp[R-(1<<j)+1][j]])
  71. return A[dp[L][j]];
  72. return A[dp[R-(1<<j)+1][j]];
  73. }
  74. }e;
  75. int N,A[MX],X[MX][5],Y[MX][5];
  76. int nrm(int a,int b,int c){
  77. int B[3]={a,b,c},L;
  78. sort(B,B+3),L=unique(B,B+3)-B;
  79. unordered_map<int,int> T;
  80. F(L)T[B[i]]=i+1;
  81. return 100*T[a]+10*T[b]+T[c];
  82. }
  83. void go(int X[MX][5]){
  84. T.clr();
  85. FT(1,N){
  86. T.add(A[k-1]);
  87. if(T.mn()<A[k])X[k][0]=T.mn();
  88. if(T.mx()>A[k])X[k][4]=T.mx();
  89. int I=T.cnt(A[k]);
  90. if(T.mx()>=A[k]&&T.kth(I)==A[k])X[k][2]=A[k];
  91. if(T.mn()<A[k])X[k][1]=T.kth(I-1);
  92. if(T.mx()>A[k])X[k][3]=~X[k][2]?T.kth(I+1):T.kth(I);
  93. }
  94. }
  95. set<int> O;
  96. map<int,int> L;
  97. int main(void){
  98. scanf("%d",&N),ga(N,A),CL(X,-1),CL(Y,-1),b.ini(A,N),e.ini(A,N);
  99. F(N){
  100. if(L.count(A[i])){
  101. if(b.qy(A,L[A[i]],i)<A[i])O.insert(212);
  102. if(e.qy(A,L[A[i]],i)>A[i])O.insert(121);
  103. }
  104. L[A[i]]=i;
  105. }
  106. go(X);
  107. reverse(A,A+N),go(Y);
  108. reverse(A,A+N);
  109. F(N/2)FF(5)swap(Y[i][j],Y[N-i-1][j]);
  110. // F(N){
  111. // DEB
  112. // printf("%d: ",A[i]);FF(5)printf(" %d",X[i][j]);puts("");
  113. // printf("%d: ",A[i]);FF(5)printf(" %d",Y[i][j]);puts("");
  114. // }
  115. F(N)FF(5)if(~X[i][j])FT(0,5)if(~Y[i][k])O.insert(nrm(X[i][j],A[i],Y[i][k]));
  116. for(auto&h:O)printf("%d\n",h);
  117. return 0;
  118. }

2020.5.16-ICPC Central Europe Regional Contest 2019的更多相关文章

  1. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  2. 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)

    A. Assignment Algorithm 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string ...

  3. Central Europe Regional Contest 2012 Problem I: The Dragon and the Knights

    一个简单的题: 感觉像计算几何,其实并用不到什么计算几何的知识: 方法: 首先对每条边判断一下,看他们能够把平面分成多少份: 然后用边来对点划分集合,首先初始化为一个集合: 最后如果点的集合等于平面的 ...

  4. Central Europe Regional Contest 2012 Problem c: Chemist’s vows

    字符串处理的题目: 学习了一下string类的一些用法: 这个代码花的时间很长,其实可以更加优化: 代码: #include<iostream> #include<string> ...

  5. Central Europe Regional Contest 2012 Problem J: Conservation

    题目不难,感觉像是一个拓扑排序,要用双端队列来维护: 要注意细节,不然WA到死  = =! #include<cstdio> #include<cstring> #includ ...

  6. Central Europe Regional Contest 2012 Problem H: Darts

    http://acm.hunnu.edu.cn/online/problem_pdf/CERC2012/H.pdf HUNNU11377 题意:飞镖环有十个环,没个环从外到里对应一个得分1~10,每个 ...

  7. ICPC Central Russia Regional Contest (CRRC 19)题解

    题目连接:https://codeforces.com/gym/102780 寒假第二次训练赛,(某菜依旧是4个小时后咕咕咕),战况还行,个人表现极差(高级演员) A:Green tea 暴力枚举即可 ...

  8. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  9. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

随机推荐

  1. Data Leakage in Machine Learning 机器学习训练中的数据泄漏

    refer to:  https://www.kaggle.com/dansbecker/data-leakage There are two main types of leakage: Leaky ...

  2. Kickstart部署之HTTP架构

    原文转自:https://www.cnblogs.com/itzgr/p/10029527.html作者:木二 目录 一 准备 1.1 完整架构:Kickstart+DHCP+HTTP+TFTP+PX ...

  3. python 逆序按行读取文件

    How to read a file in reverse order? import os def readlines_reverse(filename): with open(filename) ...

  4. 你的 SQL 还在回表查询吗?快给它安排覆盖索引

    什么是回表查询 小伙伴们可以先看这篇文章了解下什么是聚集索引和辅助索引:Are You OK?主键.聚集索引.辅助索引,简单回顾下,聚集索引的叶子节点包含完整的行数据,而非聚集索引的叶子节点存储的是每 ...

  5. Linux环境搭建及项目部署

    一. VMWare安装图解 1.点击下一步 2.接受条款,下一步 3.选择安装目录,不建议有中文目录和空格目录.下一步 4.下一步 5.这两个选项根据可以爱好习惯选择,下一步 6.安装 7.完成 9. ...

  6. QT 4.7.3 交叉编译环境搭建

    测试平台 宿主机平台:Ubuntu 12.04.4 LTS 目标机:Easy-ARM IMX283 目标机内核:Linux 2.6.35.3 交叉编译器:arm-linux-gcc 4.4.4 tsl ...

  7. Python习题集(十一)

    每天一习题,提升Python不是问题!!有更简洁的写法请评论告知我! https://www.cnblogs.com/poloyy/category/1676599.html 题目 如果一个正整数等于 ...

  8. 文件流转换为url

      /**  * 文件流转换为url  * @param {} data //文件流  */ export function getObjectURL(data) {   var url = null ...

  9. 样式和模板快速入门Style,Template

    http://www.cnblogs.com/jv9/archive/2010/04/14/1711520.html 样式(Style)和模板(Template)的定义 在Silverlight中,样 ...

  10. NOIP初赛:完善程序做题技巧

    最近写的文章好像还很多的.那么今天我们来讨论NOIP初赛的题型--完善程序.完善程序相对是比较难的题目了.全卷100分,完善程序占了大概26分,占比非常大.如果和英语考试试卷做比较,相当于首字母填空( ...