经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C » 查看文章
11.1NOIP模拟赛解题报告
来源:cnblogs  作者:自为风月马前卒  时间:2018/11/2 9:15:55  对本文有异议

心路历程

预计得分:\(100 + 100 + 50\)

实际得分:\(100 + 100 + 50\)

感觉老师找的题有点水呀。

上来看T1,woc?裸的等比数列求和?然而我不会公式呀。。感觉要凉

T2应该比较简单,T3 dp能拿很多部分分。

但是T1只打暴力感觉好丢人啊。。想了10min发现不用公式也能做,就直接倍增一下就好了。

T2水题。感觉比T1还简单。。

T3。。。。。这个就比较厉害了呀。赛后我大概问了一下,发现全机房一共读出了\(4\)种题意Orzzz。

然后我花了\(2h\)做了一道水题。。然后发现错误的时候考试马上就结束了,然后只能打个暴力走人。。。

T1

Orz zbq现场推出等比数列求和公式

Orz 好像除了我都会等比数列求和公式

Orzzzzzzzzzzzzzzzzz

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<set>
  6. #include<cmath>
  7. #include<iostream>
  8. using namespace std;
  9. const int MAXN =1e5 + 10, mod = 1e9 + 7;
  10. inline int read() {
  11. char c = getchar(); int x = 0, f = 1;
  12. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  13. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  14. return x * f;
  15. }
  16. int add(int x, int y) {
  17. if(x + y < 0) return x + y + mod;
  18. return x + y >= mod ? x + y - mod : x + y;
  19. }
  20. int mul(int x, int y) {
  21. return 1ll * x * y % mod;
  22. }
  23. int fp(int a, int p) {
  24. int base = 1;
  25. while(p) {
  26. if(p & 1) base = mul(base, a);
  27. a = mul(a, a); p >>= 1;
  28. }
  29. return base;
  30. }
  31. int N, M, pok[MAXN], g[MAXN];
  32. int solve(int k, int n) {
  33. int len = 1;
  34. while((1ll << len) <= n) len <<= 1;
  35. pok[0] = k;
  36. for(int i = 1; i <= len; i++) pok[i] = mul(pok[i - 1], pok[i - 1]);
  37. g[0] = k;
  38. for(int i = 1; i <= len; i++) g[i] = add(g[i - 1], mul(g[i - 1], pok[i - 1]));
  39. int ans = 0, now = 0, base = 1;
  40. for(int i = len; i >= 0; i--)
  41. if(now + (1 << i) <= n)
  42. ans = add(ans, mul(g[i], base)), base = mul(base, pok[i]), now += (1 << i);
  43. return ans;
  44. }
  45. main() {
  46. freopen("sum.in", "r", stdin);
  47. freopen("sum.out", "w", stdout);
  48. N = read(); M = read();
  49. int ans = 0;
  50. for(int i = 1; i <= N; i++) {
  51. if(M & 1) ans = add(ans, add(solve(i, M - 1), fp(i, M)));
  52. else ans = add(ans, solve(i, M));
  53. // cout << ans << endl;
  54. }
  55. cout << ans;
  56. return 0;
  57. }

T2

\(ans = all - min(sum[i])\)

all表示所有边权和

\(sum[i]\)表示第\(i\)个节点到根的路径

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<set>
  6. #include<cmath>
  7. #include<iostream>
  8. #define Pair pair<int, int>
  9. #define MP make_pair
  10. #define fi first
  11. #define se second
  12. using namespace std;
  13. const int MAXN = 1e5 + 10, INF = 1e9 + 7;
  14. inline int read() {
  15. char c = getchar(); int x = 0, f = 1;
  16. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  17. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  18. return x * f;
  19. }
  20. int N, sum[MAXN], All;
  21. vector<Pair> v[MAXN];
  22. void dfs(int x, int fa) {
  23. for(int i = 0, to; i < v[x].size(); i++) {
  24. if((to = v[x][i].fi) == fa) continue;
  25. sum[to] = sum[x] + v[x][i].se;
  26. dfs(to, x);
  27. }
  28. }
  29. int main() {
  30. freopen("tour.in", "r", stdin);
  31. freopen("tour.out", "w", stdout);
  32. N = read();
  33. for(int i = 1; i <= N - 1; i++) {
  34. int x = read(), y = read(), z = read(); All += z;
  35. v[x].push_back(MP(y, z));
  36. v[y].push_back(MP(x, z));
  37. }
  38. dfs(1, 0);
  39. All <<= 1;
  40. int ans = INF;
  41. for(int i = 1; i <= N; i++) ans = min(ans, All - sum[i]);
  42. cout << ans;
  43. return 0;
  44. }

T3

神仙阅读理解题,不过还是挺interesting的

首先,序列内的元素是无序的,这样我们可以对相同的数字一起考虑

稍微想一下不难发现,幸运数字最多有\(2^9\)

直接\(f[i][j]\)表示前\(i\)个数,选\(j\)的方案,dp一下

最后合并答案的时候背包一下

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cstdlib>
  4. #include<vector>
  5. #include<cmath>
  6. #include<set>
  7. #include<bitset>
  8. #include<iostream>
  9. #include<map>
  10. #define Pair pair<int, int>
  11. #define MP make_pair
  12. #define fi first
  13. #define se second
  14. //#define int long long
  15. using namespace std;
  16. const int MAXN = 1e5 + 10, mod = 1e9 + 7;
  17. inline int read() {
  18. char c = getchar(); int x = 0, f = 1;
  19. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  20. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  21. return x * f;
  22. }
  23. int N, K, a[MAXN], tot, cnt, fac[MAXN], ifac[MAXN];
  24. map<int, int> mp;
  25. int add(int &x, int y) {
  26. if(x + y < 0) x = x + y + mod;
  27. else x = (x + y >= mod ? x + y - mod : x + y);
  28. }
  29. int add2(int x, int y) {
  30. if(x + y < 0) return x + y + mod;
  31. else return x + y >= mod ? x + y - mod : x + y;
  32. }
  33. int mul(int x, int y) {
  34. return 1ll * x * y % mod;
  35. }
  36. int fp(int a, int p) {
  37. int base = 1;
  38. while(p) {
  39. if(p & 1) base = mul(base, a);
  40. a = mul(a, a); p >>= 1;
  41. }
  42. return base;
  43. }
  44. int C(int N, int M) {
  45. if(N < M) return 0;
  46. else return mul(fac[N], mul(ifac[M], ifac[N - M]));
  47. }
  48. int get(int x) {
  49. while(x) {
  50. if(x % 10 != 4 && x % 10 != 7) return 0;
  51. else x /= 10;
  52. }
  53. return 1;
  54. }
  55. map<int, Pair> id;
  56. int rev[MAXN], f[2333][2333];
  57. signed main() {
  58. freopen("lucky.in", "r", stdin);
  59. freopen("lucky.out", "w", stdout);
  60. N = read(); K = read();
  61. fac[0] = 1;
  62. for(int i = 1; i <= N; i++) fac[i] = mul(i, fac[i - 1]);
  63. ifac[N] = fp(fac[N], mod - 2);
  64. for(int i = N; i >= 1; i--) ifac[i - 1] = mul(ifac[i], i);
  65. for(int i = 1; i <= N; i++) {
  66. a[i] = read();
  67. if(get(a[i])) {
  68. if(!id[a[i]].fi) id[a[i]].fi = ++cnt, rev[cnt] = a[i];
  69. id[a[i]].se++;
  70. } else tot++;
  71. }
  72. f[0][0] = 1;
  73. for(int i = 1; i <= cnt; i++) {
  74. f[i][0] = 1;
  75. for(int j = 1; j <= cnt; j++)
  76. f[i][j] = add2(f[i - 1][j], mul(f[i - 1][j - 1], id[rev[i]].se));
  77. }
  78. int ans = 0;
  79. for(int i = 0; i <= cnt; i++) add(ans, mul(f[cnt][i], C(tot, K - i)));
  80. cout << ans;
  81. return 0;
  82. }
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号