题目地址:http://acm.upc.edu.cn/problemset.php?page=13  2217~2226

A.Rescue The Princess

一个等边三角形告诉前2个点,求逆时针序的第三个点坐标。

简单几何,其实做法有很多,好像大多数都是带直线方程然后判断方向做的。我觉得直接将A放在原点,让B绕A逆时针旋转60度,最后加上A的偏移更简单。旋转直接用方向向量乘旋转矩阵就好。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,n,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 2005
  36. #define maxe 10005
  37. const double sqt3=sqrt(3.0);
  38. ][],m3[][];
  39. ][]={{},{-sqt3/,0.5}};
  40. void gao()
  41. {
  42. memset(m3,,sizeof(m3));
  43. ;k<;++k)
  44. ;j<;++j)
  45. m3[][j]+=m1[][k]*m2[k][j];
  46. }
  47. int main()
  48. {
  49. read;
  50. int cas;
  51. scanf("%d",&cas);
  52. while(cas--)
  53. {
  54. double x1,x2,y1,y2;
  55. scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
  56. m1[][]=x2-x1;
  57. m1[][]=y2-y1;
  58. gao();
  59. printf(][]+x1,m3[][]+y1);
  60. }
  61. ;
  62. }

B.Thrall’s Dream

题干冗长,实际上就是在一个1000个点,10000条有向边的图上判断是否存在两个点A,B不可达,不可达定义为从A不能走到B且B不能走到A,A,B不能都动。

据说可以1000个点都暴力BFS过掉O(n*m)。此题可以先tarjan缩点,然后判断缩点后的图是否是一条链即可。链的充要条件应该不止一个,比较好想的是只有1个入度为0出度为1的点,只有1个入度为1出度为0的点,剩下的全是出度和入度均为1的点,平凡图特判。做的时候没考虑重边,WA了4次,还好赛场上不是我写这道题。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,n,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 2005
  36. #define maxe 10005
  37.  
  38. struct str
  39. {
  40. int u,v,n;
  41. }edge[maxe];
  42. int head[maxn],cnt;
  43. int dfn[maxn],low[maxn];
  44. bool ins[maxn];
  45. int incom[maxn];
  46. int dep,comn;
  47. stack<int>st;
  48. void init()
  49. {
  50. memset(dfn,,sizeof(dfn));
  51. memset(ins,,sizeof(ins));
  52. memset(head,-,sizeof(head));
  53. dep=comn=cnt=;
  54. }
  55. void addEdge(int u,int v)
  56. {
  57. edge[cnt].u=u;
  58. edge[cnt].v=v;
  59. edge[cnt].n=head[u];
  60. head[u]=cnt++;
  61. }
  62. void tarjan(int u)
  63. {
  64. dfn[u]=low[u]=++dep;
  65. ins[u]=true;
  66. st.push(u);
  67. for(int i=head[u];~i;i=edge[i].n)
  68. {
  69. int v=edge[i].v;
  70. if(!dfn[v])
  71. {
  72. tarjan(v);
  73. if(low[v]<low[u])
  74. low[u]=low[v];
  75. }
  76. else if(ins[v]&&dfn[v]<low[u])
  77. low[u]=dfn[v];
  78. }
  79. if(dfn[u]==low[u])
  80. {
  81. int v;
  82. ++comn;
  83. do
  84. {
  85. v=st.top();
  86. st.pop();
  87. ins[v]=false;
  88. incom[v]=comn;
  89. }while(v!=u);
  90. }
  91. }
  92. ];
  93. bool gao()
  94. {
  95. )return true;
  96. memset(du,,sizeof(du));
  97. ;i<cnt;++i)
  98. {
  99. int u=incom[edge[i].u],v=incom[edge[i].v];
  100. if(u==v)continue;
  101. ++du[u][];
  102. ++du[v][];
  103. }
  104. int c1,c2,c3;
  105. c1=c2=c3=;
  106. ;i<=comn;++i)
  107. {
  108. ]==&&du[i][]==)++c1;
  109. ]==&&du[i][]==)++c2;
  110. ]==&&du[i][]==)++c3;
  111. }
  112. &&c2==&&c3==(comn-));
  113. }
  114. bool vis[maxn][maxn];
  115. int main()
  116. {
  117. //read;
  118. int cas;
  119. scanf("%d",&cas);
  120. ;xx<=cas;++xx)
  121. {
  122. int n,m;
  123. scanf("%d%d",&n,&m);
  124. init();
  125. int u,v;
  126. memset(vis,,sizeof(vis));
  127. ;i<m;++i)
  128. {
  129. scanf("%d%d",&u,&v);
  130. vis[u][v]=true;
  131. }
  132. ;i<=n;++i)
  133. ;j<=n;++j)
  134. if(vis[i][j])addEdge(i,j);
  135. ;i<=n;++i)
  136. if(!dfn[i])tarjan(i);
  137. bool ff=gao();
  138. printf("Case %d: ",xx);
  139. if(!ff)puts("The Burning Shadow consume us all");
  140. else puts("Kalimdor is just ahead");
  141. }
  142. ;
  143. }

C.A^X mod P

f(x) = K, x = 1 . f(x) = (a*f(x-1) + b)%m , x > 1 . 求( A^(f(1)) + A^(f(2)) + A^(f(3)) + ...... + A^(f(n)) ) modular P (n<10^6,其余<10^9  )

总感觉可以无脑快速幂搞过的样子,赛场上没几个出的,就想肯定不可能了。其实这题只需要预处理下所有A^(1,10^9)就行,可是10^9空间和时间上都不允许。于是我们找一个k,让所有x=k*i+j,所以先求出A^k,那么A^x==(A^k)^i * A^j。感觉不是很难,还在自己太弱了。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,n,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 50005
  36. #define maxm 100005
  37. ll p1[maxm+],p2[maxm+];
  38. ll n, A, K, a, b, m, P;
  39. void init()
  40. {
  41. p1[]=p2[]=1LL;
  42. ;i<=maxm;++i)
  43. p1[i]=(A*p1[i-])%P;
  44. ;i<=maxm;++i)
  45. p2[i]=(p2[i-]*p1[maxm])%P;
  46. }
  47. ll gao()
  48. {
  49. ll t=K,ans=;
  50. ;i<=n;++i)
  51. {
  52. ans=(ans+p2[t/maxm]*p1[t%maxm])%P;
  53. t=(a*t+b)%m;
  54. }
  55. return ans;
  56. }
  57. int main()
  58. {
  59. //read;
  60. int cas;
  61. scanf("%d",&cas);
  62. ;xx<=cas;++xx)
  63. {
  64. scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&A,&K,&a,&b,&m,&P);
  65. init();
  66. printf("Case #%d: %lld\n",xx,gao());
  67. }
  68. ;
  69. }

D.Rubik’s cube

给一个乱的2色4格魔方,求拧成每面同色的最小步数。

其实转的方法一共12种,前后 上下 左右 各四种(上面2个格子2个方向 下面2个格子2个方向),由于转上面2个格子等于反向转下面的格子,所以实际上只有6种。求最少步数,暴力BFS可过,中间需要记录某个状态是否拧出来过。唯一蛋疼的地方是每个面的1234顺序不完全对应。找准转的时候是哪些面的哪个格子转动到的目标面和目标格子就好。这类题,我一直不知道怎么写简单,完全暴力模拟,代码巨丑 300+,这里不贴了。可以参见这份报告:http://blog.csdn.net/binwin20/article/details/9073941  瞬间感觉被爆了。

E.Mountain Subsequences

给出一个10^5长的字符串,字母的ASCII码做权值,问有多少个长度大于3,形如: a1 < ...< ai < ai+1 < Amax > aj > aj+1 > ... > an的序列。

赛场上真是跪给这个题了,想到了正确思路,先WA后T,回来写就AC了。DP[i][j]表示前i个字符,以j为结尾的上升序列个数,正着和反着都做一遍,然后枚举中点,两边一组合就行了。复杂度O(n*26)。其实可以降到1维,顺序扫i的时候只需要查询前面val小于val[i]的个数就可以了,然后再更新。这样写起来就很像线段树了。

dp:

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define read freopen("in.txt","r",stdin)
  33. #define write freopen("out.txt","w",stdout)
  34. #define maxn 100005
  35. #define MOD 2012
  36. char ss[maxn];
  37. ],dp2[maxn][];
  38. //dp[i][j]代表前i个单词权值小于等于j的上升序列方案数,dp2同理,只不过是反过来。
  39. int main()
  40. {
  41. //read;
  42. int n;
  43. while(~scanf("%d",&n))
  44. {
  45. scanf("%s",ss);
  46. memset(dp,,sizeof(dp));
  47. memset(dp2,,sizeof(dp2));
  48. ;i<=n;++i)
  49. {
  50. ]-;
  51. dp[i][t]=;
  52. ;j<t;++j)
  53. dp[i][t]=(dp[i][t]+dp[i-][j])%MOD;
  54. ;j<=;++j)
  55. dp[i][j]=(dp[i][j]+dp[i-][j])%MOD;
  56. }
  57. ;i<=n;++i)
  58. ;j<=;++j)
  59. dp[i][j]=(dp[i][j]+dp[i][j-])%MOD;
  60.  
  61. ;--i)
  62. {
  63. ]-;
  64. dp2[i][t]=;
  65. ;j<t;++j)
  66. dp2[i][t]=(dp2[i][t]+dp2[i+][j])%MOD;
  67. ;j<=;++j)
  68. dp2[i][j]=(dp2[i][j]+dp2[i+][j])%MOD;
  69. }
  70. ;i<=n;++i)
  71. ;j<=;++j)
  72. dp2[i][j]=(dp2[i][j]+dp2[i][j-])%MOD;
  73. ;
  74. ;i<n;++i)
  75. {
  76. ]-;
  77. ans=(ans+dp[i-][t-]*dp2[i+][t-])%MOD;
  78. }
  79. printf("%d\n",ans);
  80. }
  81. ;
  82. }

seg:

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,26,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 100005
  36. #define maxm 30
  37. #define MOD 2012
  38. ];
  39. void pushup(int rt)
  40. {
  41. sum[rt]=(sum[rt<<]+sum[rt<<|])%MOD;
  42. return ;
  43. }
  44. void build(int l,int r,int rt)
  45. {
  46. if(l==r)
  47. {
  48. sum[rt]=;
  49. return ;
  50. }
  51. ;
  52. build(lson);
  53. build(rson);
  54. pushup(rt);
  55. }
  56. void update(int p,int v,int l,int r,int rt)
  57. {
  58. if(l==r)
  59. {
  60. sum[rt]=(sum[rt]+v)%MOD;
  61. return ;
  62. }
  63. ;
  64. if(p<=m)update(p,v,lson);
  65. else update(p,v,rson);
  66. pushup(rt);
  67. }
  68. int query(int l1,int r1,int l,int r,int rt)
  69. {
  70. if(l1<=l&&r1>=r)
  71. return sum[rt];
  72. ,ans=;
  73. if(l1<=m)ans=(ans+query(l1,r1,lson))%MOD;
  74. if(r1>m)ans=(ans+query(l1,r1,rson))%MOD;
  75. return ans;
  76. }
  77. char ss[maxn];
  78. ];
  79. int main()
  80. {
  81. //read;
  82. int n;
  83. while(~scanf("%d",&n))
  84. {
  85. scanf();
  86. memset(tot,,sizeof(tot));
  87. build(root);
  88. ;i<=n;++i)
  89. {
  90. ,t;
  91. )t=;
  92. ,p-,root)+;
  93. update(p,t,root);
  94. tot[i][]=(t-+MOD)%MOD;
  95. }
  96. build(root);
  97. ;--i)
  98. {
  99. ,t;
  100. )t=;
  101. ,p-,root)+;
  102. update(p,t,root);
  103. tot[i][]=(t-+MOD)%MOD;
  104. }
  105. ;
  106. ;i<n;++i)
  107. ans=(ans+tot[i][]*tot[i][])%MOD;
  108. printf("%d\n",ans);
  109. }
  110. ;
  111. }

F.Alice and Bob

一个多项式:(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1)  ,给出p,求x^p的系数 (n<50  0 <=P <=1234567898765432)

其实就是把P二进制展开,然后对应位为1的a乘起来就OK。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,26,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 105
  36. #define MOD 2012
  37. int a[maxn];
  38. int gao(ll p)
  39. {
  40. ;
  41. ;p;++i,p>>=)
  42. )ans=(ans*a[i])%MOD;
  43. return ans;
  44. }
  45. int main()
  46. {
  47. //read;
  48. int cas;
  49. scanf("%d",&cas);
  50. while(cas--)
  51. {
  52. int n,m;
  53. scanf("%d",&n);
  54. memset(a,,sizeof(a));
  55. ;i<=n;++i)
  56. scanf("%d",a+i);
  57. scanf("%d",&m);
  58. ll p;
  59. while(m--)
  60. {
  61. scanf("%lld",&p);
  62. printf("%d\n",gao(p));
  63. }
  64. }
  65. ;
  66. }

G.A-Number and B-Number

一个数如果某位含有7或能被7整除,那么这种数为A-Number ,把A数写成数列,如果下标不是A-number的A-number是B-number。求第n个B-number,保证答案不超long long

这题真像腾讯马拉松 HDU 4507,首先如果我们知道n以内有多少个A-Number,那么不仅第n个A-Number可以通过二分求出,B-Number,同理也能求出。问题的关键就是求n以内A-Number的个数。可以用数位DP求出n内的A-Number,其中DP[i][j][k]表示i位数,mod 7 ==j  k==1?数位含7:不含7的数的A-Number的个数,将n十进制分解,然后逐位累加就可以求出答案了。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,n,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 25
  36. #define MOD 2012
  37. int d[maxn];
  38. ull dp[maxn][][];
  39.  
  40. ull dfs(int dx,int mod7,int have7,int limit)
  41. {
  42. if(!dx)return (!mod7||have7);
  43. if(!limit&&~dp[dx][mod7][have7])
  44. return dp[dx][mod7][have7];
  45. ;
  46. if(limit)w=d[dx];
  47. ull tot=0ULL;
  48. ;i<=w;++i)
  49. {
  50. *mod7+i)%;
  51. );
  52. tot+=dfs(dx-,tmod7,thave7,limit&&i==w);
  53. }
  54. if(!limit)dp[dx][mod7][have7]=tot;
  55. return tot;
  56. }
  57. ull gao(ull n)
  58. {
  59. ;
  60. while(n)
  61. {
  62. d[++cnt]=n%;
  63. n/=;
  64. }
  65. ull t=dfs(cnt,,,);
  66. ;
  67. }
  68. ull bin(ull n)
  69. {
  70. ull l=7ULL,r=(1ULL<<)-,m;
  71. while(l<=r)
  72. {
  73. m=(l+r)>>;
  74. ull t1=gao(m);
  75. ull t2=t1-gao(t1);
  76. ;
  77. ;
  78. }
  79. ;
  80. }
  81. int main()
  82. {
  83. //read;
  84. memset(dp,-,sizeof(dp));
  85. ull n;
  86. while(~scanf("%llu",&n))
  87. printf("%llu\n",bin(n));
  88. ;
  89. }

H.Boring Counting

一个长度为n的数组,q次询问[L,R]之间在[A,B]范围内的个数(n,q<5*10^4)。

这题很像HDU 4417 ,线段树离线操作,可以先把数组和询问全部保存下来,然后数组按照权从小到大排序,然后询问先按照B从小到大排序,然后线段树在按序插入数组中的数,然后就可以依次回答排序后的询问了,同理再按A排序,做差就是答案。另外还可以用划分树做。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define root 1,n,1
  33. #define read freopen("in.txt","r",stdin)
  34. #define write freopen("out.txt","w",stdout)
  35. #define maxn 50005
  36. #define MOD 2012
  37. ];
  38. struct str1
  39. {
  40. int h,dx;
  41. bool operator <(const str1 t) const{return h<t.h;}
  42. }nd[maxn];
  43. struct str2
  44. {
  45. int l,r,h1,h2,dx;
  46. }que[maxn];
  47. bool cmp1(str2 s1,str2 s2)
  48. {
  49. return s1.h1<s2.h1;
  50. }
  51. bool cmp2(str2 s1,str2 s2)
  52. {
  53. return s1.h2<s2.h2;
  54. }
  55. ];
  56. void pushup(int rt)
  57. {
  58. sum[rt]=sum[rt<<]+sum[rt<<|];
  59. return ;
  60. }
  61. void build(int l,int r,int rt)
  62. {
  63. if(l==r)
  64. {
  65. sum[rt]=;
  66. return ;
  67. }
  68. ;
  69. build(lson);
  70. build(rson);
  71. pushup(rt);
  72. }
  73. void update(int p,int l,int r,int rt)
  74. {
  75. if(l==r)
  76. {
  77. ++sum[rt];
  78. return ;
  79. }
  80. ;
  81. if(p<=m)update(p,lson);
  82. else update(p,rson);
  83. pushup(rt);
  84. }
  85. int query(int l1,int r1,int l,int r,int rt)
  86. {
  87. if(l1<=l&&r1>=r)
  88. return sum[rt];
  89. ,ans=;
  90. if(l1<=m)ans+=query(l1,r1,lson);
  91. if(r1>m)ans+=query(l1,r1,rson);
  92. return ans;
  93. }
  94. int main()
  95. {
  96. //read;
  97. int cas;
  98. scanf("%d",&cas);
  99. ;xx<=cas;++xx)
  100. {
  101. int n,m;
  102. scanf("%d%d",&n,&m);
  103. //保存节点和查询信息,离线线段树
  104. ;i<=n;++i)
  105. {
  106. scanf("%d",&nd[i].h);
  107. nd[i].dx=i;
  108. }
  109. ;i<=m;++i)
  110. {
  111. scanf("%d%d%d%d",&que[i].l,&que[i].r,&que[i].h1,&que[i].h2);
  112. que[i].dx=i;
  113. }
  114. //对于每个节点,按权值从小到大排序
  115. sort(nd+,nd+n+);
  116. //对每个询问,先按h2从小到大排序
  117. sort(que+,que++m,cmp2);
  118. build(root);
  119. ;
  120. ;i<=m;++i)
  121. {
  122. while(cnt<=n&&nd[cnt].h<=que[i].h2)
  123. {
  124. update(nd[cnt].dx,root);
  125. ++cnt;
  126. }
  127. ans[que[i].dx][]=query(que[i].l,que[i].r,root);
  128. }
  129. build(root);
  130. //再对每个询问,先按h1从小到大排序
  131. sort(que+,que++m,cmp1);
  132. cnt=;
  133. ;i<=m;++i)
  134. {
  135. while(cnt<=n&&nd[cnt].h<que[i].h1)
  136. {
  137. update(nd[cnt].dx,root);
  138. ++cnt;
  139. }
  140. ans[que[i].dx][]=query(que[i].l,que[i].r,root);
  141. }
  142. printf("Case #%d:\n",xx);
  143. //答案就是两次统计的差值
  144. ;i<=m;++i)
  145. printf(]-ans[i][]);
  146. }
  147. ;
  148. }

I.The number of steps

一个n行三角形迷宫,有概率向左,向左下,向右下移动。求从顶点移动到最左下角的步数期望(n<45)。

比较简单的期望题,因为递推关系中无环,所以DP线性递推。方向要搞对,从下向上,从左到右。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define read freopen("in.txt","r",stdin)
  33. #define write freopen("out.txt","w",stdout)
  34. #define maxn 55
  35. #define MOD 1000000007
  36. double dp[maxn][maxn];
  37. int main()
  38. {
  39. //read;
  40. int n;
  41. while(scanf("%d",&n),n)
  42. {
  43. double a,b,c,d,e;
  44. scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e);
  45. dp[n][]=;
  46. ;i<=n;++i)
  47. dp[n][i]=dp[n][i-]+1.0;
  48. ;i>;--i)
  49. {
  50. dp[i][]=a*dp[i+][]+b*dp[i+][]+1.0;
  51. ;j<n;++j)
  52. dp[i][j]=c*dp[i+][j]+d*dp[i+][j+]+e*dp[i][j-]+1.0;
  53. }
  54. printf(][]);
  55. }
  56. ;
  57. }

J.Contest Print Server

题意是模拟一个打印服务。

一道水题,可以直接模拟,由于赛场上一个很戏剧性的剧情,导致这个题AC的并不多。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <queue>
  5. #include <stack>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <vector>
  9. #include <bitset>
  10. #include <cstdio>
  11. #include <string>
  12. #include <numeric>
  13. #include <cstring>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <algorithm>
  17. #include <functional>
  18. using namespace std;
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21.  
  22. ]={-,,,};
  23. ]={,,-,};//up down left right
  24. ||x>n||y<||y>m)return false;return true;}
  25. )*m+y;}
  26.  
  27. #define eps 1e-8
  28. #define inf 0x7fffffff
  29. #define debug puts("BUG")
  30. #define lson l,m,rt<<1
  31. #define rson m+1,r,rt<<1|1
  32. #define read freopen("in.txt","r",stdin)
  33. #define write freopen("out.txt","w",stdout)
  34. #define maxn 105
  35. #define MOD 2012
  36. int n,s,x,y,mod;
  37. struct str
  38. {
  39. ];
  40. int p;
  41. };
  42. str tt[maxn];
  43. void gao(int ff)
  44. {
  45. int now=s;
  46. ;i<=n;++i)
  47. {
  48. if(tt[i].p<=now)
  49. {
  50. printf("%d pages for %s\n",tt[i].p,tt[i].name);
  51. now-=tt[i].p;
  52. }
  53. else
  54. {
  55. printf("%d pages for %s\n",now,tt[i].name);
  56. s=(x*s+y)%mod;
  57. now=s;
  58. --i;
  59. }
  60. }
  61. puts("");
  62. }
  63. int main()
  64. {
  65. //read;
  66. int cas;
  67. scanf("%d",&cas);
  68. while(cas--)
  69. {
  70. scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
  71. ],s2[];
  72. ;i<=n;++i)
  73. scanf("%s%s%d%s",tt[i].name,s1,&tt[i].p,s2);
  74. gao(cas);
  75. }
  76. ;
  77. }

这次省赛很悲剧,由于160min出第4题后一直哑火到比赛结束。最终只拿到银牌。

很讽刺的是这是最后一次参加比赛了,可却是总结最认真的一次。平时做题不好好总结,赛场上出这么多原题就傻眼了吧,看来这就是平时偷懒不认真总结的报应了。

最后感谢SDUT E_star 给了我一些题目的思路,并提供了标程和数据让我能对拍。

[ACM]2013山东省“浪潮杯”省赛 解题报告的更多相关文章

  1. 2013山东省“浪潮杯”省赛 A.Rescue The Princess

    A.Rescue The PrincessDescription Several days ago, a beast caught a beautiful princess and the princ ...

  2. 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit    1000 ms Memory li ...

  3. ZROIDay4-比赛解题报告

    ZROIDay4-比赛解题报告 扯闲话 感觉这个出题人的题做起来全都没感觉啊,今天又凉了,T1完全不知道什么意思,T2只会暴力,T3现在还不懂什么意思,真的太菜了 A 题意半天没搞懂爆零GG了,讲了一 ...

  4. ZROIDay3-比赛解题报告

    ZROIDay3-比赛解题报告 瞎扯 从今天开始考试有点不在状态,可能是因为不太适应题目的原因,T1已经接近了思想但是没有想到状态转移,T2思考方向错误,T3不会打LCT,还是太菜了 A 考场上想到要 ...

  5. 10.30 NFLS-NOIP模拟赛 解题报告

    总结:今天去了NOIP模拟赛,其实是几道USACO的经典的题目,第一题和最后一题都有思路,第二题是我一开始写了个spfa,写了一半中途发现应该是矩阵乘法,然后没做完,然后就没有然后了!第二题的暴力都没 ...

  6. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  7. 2018.10.26NOIP模拟赛解题报告

    心路历程 预计得分:\(100 + 100 + 70\) 实际得分:\(40 + 100 + 70\) 妈妈我又挂分了qwq..T1过了大样例就没管,直到临考试结束前\(10min\)才发现大样例是假 ...

  8. 2014山东省“浪潮杯”第五届ACM省赛总结

    一次比赛做一次总结,弱菜又来总结了…… 我这种大四的又死皮赖来混省赛了,貌似就我和山大威海的某哥们(不详其大名)了吧.颁奖前和他聊天,得知他去百度了,真是不错,ORZ之. 比赛流水账: 题目目前不知道 ...

  9. Anagram(山东省2018年ACM浪潮杯省赛)

    Problem Description Orz has two strings of the same length: A and B. Now she wants to transform A in ...

随机推荐

  1. 简谈Redis

    1.为什么使用redis 分析:博主觉得在项目中使用redis,主要是从两个角度去考虑:性能和并发.当然,redis还具备可以做分布式锁等其他功能,但是如果只是为了分布式锁这些其他功能,完全还有其他中 ...

  2. Python之爬虫-猫眼电影

    Python之爬虫-猫眼电影 #!/usr/bin/env python # coding: utf-8 import json import requests import re import ti ...

  3. python flask获取微信用户信息报404,nginx问题

    在学习flask与微信公众号时问题,发现测试自动回复/wechat8008时正常,而测试获取微信用户信息/wechat8008/index时出现404.查询资料后收发是nginx配置问题. 在loca ...

  4. LeetCode(61) Rotate List

    题目 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Giv ...

  5. LeetCode(88)Merge Sorted Array

    题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note ...

  6. Borrowers

    Description I mean your borrowers of books - those mutilators of collections, spoilers of the symmet ...

  7. 下载Spring4.1.x源码并用IntelliJ IDEA打开-----

    下载Spring4.1.x源码并用IntelliJ IDEA打开-------https://blog.csdn.net/boling_cavalry/article/details/79426075 ...

  8. SPOJ 3261 (树套树傻逼题)

    As another one of their crazy antics, the N (1 ≤ N ≤ 100,000) cows want Farmer John to race against ...

  9. codeforces 362A找规律

    刚开始以为是搜索白忙活了原来是个简单的找规律,以后要多想啊 此题是两马同时跳 A. Two Semiknights Meet time limit per test 1 second memory l ...

  10. [转]MySQL5字符集支持及编码研究

    前言 在更新数据库时,有时会遇到这样的错误: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COER ...