C - Traveling

先看能不能走到,再看看奇偶性是否相同

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define mo 974711
  12. #define MAXN 200005
  13. //#define ivorysi
  14. using namespace std;
  15. typedef long long int64;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;char c = getchar();T f = 1;
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 + c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int N;
  39. void Solve() {
  40. int pt,px,py;
  41. int t,x,y;
  42. read(N);
  43. pt = 0,px = 0,py = 0;
  44. for(int i = 1 ; i <= N ; ++i) {
  45. read(t);read(x);read(y);
  46. int k = abs(x - px) + abs(y - py);
  47. if(k > t - pt) {
  48. puts("No");return;
  49. }
  50. if((k ^ t) & 1) {puts("No");return;}
  51. }
  52. puts("Yes");
  53. }
  54. int main() {
  55. #ifdef ivorysi
  56. freopen("f1.in","r",stdin);
  57. #endif
  58. Solve();
  59. return 0;
  60. }

D - Checker

我们计算右下角在\((-2k,-2k)\)到\((-1,-1)\)这个区域内,每个点所在的格子的颜色

发现根据右下角的位置会分成九个小块,把九个小块里的颜色和需求一样的矩阵用差分矩阵加,最后统计前缀和中最大的即可

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define mo 974711
  12. #define MAXN 200005
  13. //#define ivorysi
  14. using namespace std;
  15. typedef long long int64;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;char c = getchar();T f = 1;
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 + c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int N,K;
  39. int a[2005][2005];
  40. int dx[5],dy[5];
  41. void add(int x1,int y1,int x2,int y2) {
  42. if(x1 > x2 || y1 > y2) return;
  43. a[x1][y1]++;a[x2 + 1][y2 + 1]++;
  44. a[x1][y2 + 1]--;a[x2 + 1][y1]--;
  45. }
  46. void Solve() {
  47. read(N);read(K);
  48. int x,y;char c[5];
  49. for(int i = 1 ; i <= N ; ++i) {
  50. read(x);read(y);scanf("%s",c + 1);
  51. ++x;++y;
  52. int tx = x % K,ty = y % K;
  53. int now = ((x / K) ^ (y / K)) & 1,u;
  54. if(c[1] == 'W') u = 0;
  55. else u = 1;
  56. dx[1] = K - tx,dx[2] = K,dx[3] = tx;
  57. dy[1] = K - ty,dy[2] = K,dy[3] = ty;
  58. for(int i = 1 ; i <= 3 ; ++i) dx[i] += dx[i - 1],dy[i] += dy[i - 1];
  59. for(int h = 1 ; h <= 3 ; ++h) {
  60. for(int t = 1 ; t <= 3 ; ++t) {
  61. int w = (h ^ t ^ now) & 1;
  62. if(w == u) {
  63. add(dx[h - 1] + 1,dy[t - 1] + 1,dx[h],dy[t]);
  64. }
  65. }
  66. }
  67. }
  68. int ans = 0;
  69. for(int i = 1 ; i <= 2 * K ; ++i) {
  70. for(int j = 1 ; j <= 2 * K ; ++j) {
  71. a[i][j] = a[i][j] + a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
  72. ans = max(ans,a[i][j]);
  73. }
  74. }
  75. out(ans);enter;
  76. }
  77. int main() {
  78. #ifdef ivorysi
  79. freopen("f1.in","r",stdin);
  80. #endif
  81. Solve();
  82. return 0;
  83. }

E - GraphXY

显然\(ax + by + f(a,b) >= d(x,y)\)

\(a\)最多100个\(b\)最多100个,可以都构建出来

然后对于每个\((a,b)\)求出来\(f(a,b)\)

最后再对于每个\(x,y\)判一遍\(d(x,y)\)是否合法

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define mo 974711
  12. #define MAXN 200005
  13. //#define ivorysi
  14. using namespace std;
  15. typedef long long int64;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;char c = getchar();T f = 1;
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 + c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. int A,B;
  39. int d[15][15];
  40. int f[105][105],tot,gx[105],gy[105],S,T;
  41. pii p[305 * 305];
  42. int val[305 * 305],cnt;
  43. int check(int x,int y) {
  44. int res = 1000000;
  45. for(int i = 0 ; i <= 100 ; ++i) {
  46. for(int j = 0 ; j <= 100 ; ++j) {
  47. res = min(res,f[i][j] + i * x + j * y);
  48. }
  49. }
  50. return res;
  51. }
  52. void Solve() {
  53. read(A);read(B);
  54. for(int i = 1 ; i <= A ; ++i) {
  55. for(int j = 1 ; j <= B ; ++j) {
  56. read(d[i][j]);
  57. }
  58. }
  59. for(int i = 0 ; i <= 100 ; ++i) {
  60. for(int j = 0 ; j <= 100 ; ++j) {
  61. for(int k = 1 ; k <= A ; ++k) {
  62. for(int h = 1 ; h <= B ; ++h) {
  63. f[i][j] = max(f[i][j],d[k][h] - k * i - h * j);
  64. }
  65. }
  66. }
  67. }
  68. for(int i = 1 ; i <= A ; ++i) {
  69. for(int j = 1 ; j <= B ; ++j) {
  70. if(check(i,j) != d[i][j]) {
  71. puts("Impossible");
  72. return;
  73. }
  74. }
  75. }
  76. puts("Possible");
  77. S = ++tot;
  78. gx[0] = S;
  79. for(int i = 1 ; i <= 100 ; ++i) {
  80. gx[i] = ++tot;
  81. p[++cnt] = mp(gx[i - 1],gx[i]);
  82. val[cnt] = -2;
  83. }
  84. T = ++tot;
  85. gy[0] = T;
  86. for(int i = 1 ; i <= 100 ; ++i) {
  87. gy[i] = ++tot;
  88. p[++cnt] = mp(gy[i],gy[i - 1]);
  89. val[cnt] = -1;
  90. }
  91. for(int i = 0 ; i <= 100 ; ++i) {
  92. for(int j = 0 ; j <= 100 ; ++j) {
  93. p[++cnt] = mp(gx[i],gy[j]);
  94. val[cnt] = f[i][j];
  95. }
  96. }
  97. out(tot);space;out(cnt);enter;
  98. for(int i = 1 ; i <= cnt ; ++i) {
  99. out(p[i].fi);space;out(p[i].se);space;
  100. if(val[i] < 0) {
  101. if(val[i] == -2) {puts("X");}
  102. else puts("Y");
  103. }
  104. else {out(val[i]);enter;}
  105. }
  106. out(S);space;out(T);enter;
  107. }
  108. int main() {
  109. #ifdef ivorysi
  110. freopen("f1.in","r",stdin);
  111. #endif
  112. Solve();
  113. return 0;
  114. }

F - ColoringBalls

本来以为是个dp没想到是个搜索加剪枝,迷的很。。然而就是搜索我都写跪了……菜的要死QAQ

我们对于白块分成的每一个小块进行分组

然后把相邻的同颜色合起来,比如说RRBBRR变成RBR

然后我们根据所需要达到的最小操作次数来分组

1次操作 r R

2次操作 rb B BR RB BRB

3次操作 rb? BRB RBRB BRBR RBRBR

4次操作 rb?? BRBRB RBRBRB BRBRBR RBRBRBR

问号表示可以任意一种操作

然后对于一种序列,我们可以把必须要填的位置填上,然后挖上几个坑,往里扔数,方案数就是组合数了

例如序列 2 2 3

我们必须要填的是

BWBWBRB

然后挖的坑是

W/R/B/R/W/R/B/R/W/R/B/R/B/R/W

往坑里扔数就行

怎么判断一个序列合不合法,找出所有的r以及它们最靠左没有被搭配过的b,从后往前枚举r,从小到大枚举所需要操作序列长度,对于一个b加上我后面需要用的位置的个数,统计一个后缀和看看合不合法即可

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define pdi pair<db,int>
  6. #define mp make_pair
  7. #define pb push_back
  8. #define enter putchar('\n')
  9. #define space putchar(' ')
  10. #define eps 1e-8
  11. #define mo 974711
  12. #define MAXN 1000005
  13. //#define ivorysi
  14. using namespace std;
  15. typedef long long int64;
  16. typedef double db;
  17. template<class T>
  18. void read(T &res) {
  19. res = 0;char c = getchar();T f = 1;
  20. while(c < '0' || c > '9') {
  21. if(c == '-') f = -1;
  22. c = getchar();
  23. }
  24. while(c >= '0' && c <= '9') {
  25. res = res * 10 + c - '0';
  26. c = getchar();
  27. }
  28. res *= f;
  29. }
  30. template<class T>
  31. void out(T x) {
  32. if(x < 0) {x = -x;putchar('-');}
  33. if(x >= 10) {
  34. out(x / 10);
  35. }
  36. putchar('0' + x % 10);
  37. }
  38. const int MOD = 1000000007;
  39. int N,K,C[1005][1005],L[75],fac[1005],invfac[1005],cnt;
  40. int sum[75],pos[75],tot,ans,matc[75];
  41. char s[75];
  42. bool vis[75];
  43. int inc(int a,int b) {
  44. return a + b >= MOD ? a + b - MOD : a + b;
  45. }
  46. int mul(int a,int b) {
  47. return 1LL * a * b % MOD;
  48. }
  49. void update(int &x,int y) {
  50. x = inc(x,y);
  51. }
  52. int fpow(int x,int c) {
  53. int res = 1,t = x;
  54. while(c) {
  55. if(c & 1) res = mul(res,t);
  56. t = mul(t,t);
  57. c >>= 1;
  58. }
  59. return res;
  60. }
  61. bool check() {
  62. if(tot < cnt) return false;
  63. memset(sum,0,sizeof(sum));
  64. int p = 1;
  65. for(int i = cnt ; i >= 1 ; --i) {
  66. sum[pos[i]]++;
  67. if(L[p] >= 2) {
  68. if(!matc[pos[i]]) return false;
  69. sum[matc[pos[i]]] += L[p] - 1;
  70. }
  71. ++p;
  72. }
  73. for(int i = K ; i >= 1 ; --i) {
  74. sum[i] += sum[i + 1];
  75. if(sum[i] > K - i + 1) return false;
  76. }
  77. return true;
  78. }
  79. bool dfs(int pre,int dep,int len) {
  80. cnt = dep;
  81. if(!check()) return false;
  82. int k = 1 + cnt;
  83. for(int i = 1 ; i <= cnt ; ++i) {
  84. if(L[i] == 1) ++k;
  85. else k += 2 * L[i] - 1;
  86. }
  87. int res = C[N - len + k - 1][k - 1];
  88. res = mul(res,fac[cnt]);
  89. int t = 0;
  90. for(int i = 1 ; i <= cnt ; ++i) {
  91. if(L[i] != L[i - 1]) {
  92. res = mul(res,invfac[t]);
  93. t = 0;
  94. }
  95. ++t;
  96. }
  97. res = mul(res,invfac[t]);
  98. update(ans,res);
  99. if(dep + 1 > tot) return true;
  100. for(int i = pre ; i <= 70 ; ++i) {
  101. int tl = len;
  102. if(dep != 0) ++tl;
  103. if(i == 1 || i == 2) tl += 1;
  104. else tl += i - 2 + i - 1;
  105. if(tl > N) break;
  106. L[dep + 1] = i;
  107. if(!dfs(i,dep + 1,tl)) break;
  108. }
  109. return true;
  110. }
  111. void Solve() {
  112. read(N);read(K);
  113. scanf("%s",s + 1);
  114. C[0][0] = 1;
  115. for(int i = 1 ; i <= 1000 ; ++i) {
  116. C[i][0] = 1;
  117. for(int j = 1 ; j <= i ; ++j) {
  118. C[i][j] = inc(C[i - 1][j - 1],C[i - 1][j]);
  119. }
  120. }
  121. fac[0] = 1;
  122. for(int i = 1 ; i <= 1000 ; ++i) fac[i] = mul(fac[i - 1],i);
  123. invfac[1000] = fpow(fac[1000],MOD - 2);
  124. for(int i = 999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
  125. tot = 0;
  126. for(int i = 1 ; i <= K ; ++i) {
  127. if(s[i] == 'r') {
  128. pos[++tot] = i;
  129. for(int j = i + 1 ; j <= K ; ++j) {
  130. if(s[j] == 'b' && !vis[j]) {matc[i] = j;vis[j] = 1;break;}
  131. }
  132. }
  133. }
  134. dfs(1,0,0);
  135. out(ans);enter;
  136. }
  137. int main() {
  138. #ifdef ivorysi
  139. freopen("f1.in","r",stdin);
  140. #endif
  141. Solve();
  142. return 0;
  143. }

【AtCoder】ARC089的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. 【BZOJ1083】[SCOI2005]繁忙的都市(最小生成树)

    [BZOJ1083][SCOI2005]繁忙的都市(最小生成树) 题面 BZOJ 洛谷 题解 模板题. #include<iostream> #include<cstdio> ...

  2. 【AGC006F】Blackout

    Description 题目链接 Solution 首先,把输入矩阵看成邻接矩阵,将问题转化到图上. 现在的问题变成:给定一个有向图,如果存在\((u,v)\)和\((v,w)\),则连边\((w,u ...

  3. Apache 的 ab 压测工具快速使用

    ab 是一个 httpd 自带的很好用的压力测试工具,它是 apache bench 命令的缩写.ab 命令会创建多个并发访问线程,模拟多个访问者同时对某一 URL 地址进行访问.可以用来测试 apa ...

  4. P3932 浮游大陆的68号岛

    P3932 浮游大陆的68号岛 妖精仓库的储物点可以看做在一个数轴上.每一个储物点会有一些东西,同时他们之间存在距离. 每次他们会选出一个小妖精,然后剩下的人找到区间[l,r]储物点的所有东西,清点完 ...

  5. MongoDB 聚合嵌入的数组(扁平化数据+管道)

    MongoDB学习教程 先看下要操作的主要数据结构: { "_id" : "000015e0-3e9c-40b3-bd0d-6e7949f455c0", &qu ...

  6. FFprobe使用指南

    http://blog.csdn.net/stone_wzf/article/details/45378759 http://blog.chinaunix.net/uid-26000296-id-42 ...

  7. Parquet 格式文件

    Apache Parquet是Hadoop生态圈中一种新型列式存储格式,它可以兼容Hadoop生态圈中大多数计算框架(Hadoop.Spark等),被多种查询引擎支持(Hive.Impala.Dril ...

  8. MongoDB探索之路(三)——索引

    1.索引介绍 2.创建语句 1)基础索引 在字段age 上创建索引,1(升序);-1(降序):db.users.ensureIndex({age:1}) _id 是创建表的时候自动创建的索引,此索引是 ...

  9. [转载]AngularJS之Factory vs Service vs Provider

    http://www.oschina.net/translate/angularjs-factory-vs-service-vs-provider http://tylermcginnis.com/a ...

  10. 天气窗件展示 -一个HTML5 地理位置应用的例子

         定位及地理位置信息是LBS应用的核心,和定位功能有所不同的是地理位置信息更关注如何得到有意义的信息.(例如一条街道的地址)      从这边文章里你会学到HTML5地理位置信息的各种功能.它 ...