题目链接:https://codeforc.es/contest/1076

A. Minimizing the String

题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串。

题解:若存在一个位置 i 满足 a[i] > a[i+1],若不删除 a[i] 则后续操作不可能更优。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. const int INF = 0x3f3f3f3f;
  11. const double eps = 1e-;
  12. const int MAXN = 2e5 + ;
  13. const int MAXM = 2e5 + ;
  14. const ll mod = 1e9 + ;
  15.  
  16. char s[MAXN];
  17.  
  18. int main() {
  19. #ifdef local
  20. freopen("data.txt", "r", stdin);
  21. // freopen("data.txt", "w", stdout);
  22. #endif
  23. int n;
  24. scanf("%d%s",&n,s);
  25. int pos = n - ;
  26. for(int i = ; i < n - ; i++) {
  27. if(s[i] > s[i + ]) {
  28. pos = i;
  29. break;
  30. }
  31. }
  32. for(int i = ; i < n; i++)
  33. if(i != pos) printf("%c",s[i]);
  34. return ;
  35. }

B. Divisor Subtraction

题意:对于一个 n,每次减去它的最小质因子直到为 0,求操作次数。

题解:n <= 1e10,所以先筛出 1e5 以内的质因子,然后暴力找最小质因子,当最小质因子为 2 的时候,已经不存在更小的质因子,直接跳出循环即可。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. const int INF = 0x3f3f3f3f;
  11. const double eps = 1e-;
  12. const int MAXN = 2e5 + ;
  13. const int MAXM = 2e5 + ;
  14. const ll mod = 1e9 + ;
  15.  
  16. bool check[MAXN];
  17. int prime[MAXN];
  18. int tot;
  19.  
  20. void init() {
  21. mst(check, false);
  22. tot = ;
  23. for(int i = ; i <= 1e5; i++) {
  24. if(!check[i]) prime[tot++] = i;
  25. for(int j = ; j < tot; j++) {
  26. if(i * prime[j] > 1e5) break;
  27. check[i * prime[j]] = true;
  28. if(i % prime[j] == ) break;
  29. }
  30. }
  31. }
  32.  
  33. int main() {
  34. #ifdef local
  35. freopen("data.txt", "r", stdin);
  36. // freopen("data.txt", "w", stdout);
  37. #endif
  38. init();
  39. ll n;
  40. scanf("%lld",&n);
  41. ll ans = ;
  42. while(n) {
  43. bool flag = false;
  44. for(int i = ; i < tot && n >= prime[i]; i++) {
  45. if(n % prime[i] == ) {
  46. if(prime[i] == ) {
  47. flag = true;
  48. ans += n / ;
  49. n = ;
  50. break;
  51. }
  52. n -= prime[i];
  53. ans++;
  54. flag = true;
  55. break;
  56. }
  57. }
  58. if(!flag) {
  59. ans++;
  60. break;
  61. }
  62. }
  63. printf("%lld\n",ans);
  64. return ;
  65. }

C. Meme Problem

题意:给出一个 d,求是否存在 a + b = d 且 ab = d。

题解:解一元二次方程,判一下无解的条件即可。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. const int INF = 0x3f3f3f3f;
  11. const double eps = 1e-;
  12. const int MAXN = 2e5 + ;
  13. const int MAXM = 2e5 + ;
  14. const ll mod = 1e9 + ;
  15.  
  16. int main() {
  17. #ifdef local
  18. freopen("data.txt", "r", stdin);
  19. // freopen("data.txt", "w", stdout);
  20. #endif
  21. int t;
  22. cin >> t;
  23. while(t--) {
  24. int d;
  25. cin >> d;
  26. if(d < && d != ) {
  27. cout << "N" << endl;
  28. continue;
  29. }
  30. cout << "Y ";
  31. long double a = sqrt(((long double)d * d - 4.0 * (long double)d) / 4.0) + (long double)d / 2.0;
  32. long double b = (long double)d - a;
  33. cout << fixed << setprecision() << a << ' ';
  34. cout << fixed << setprecision() << b << endl;
  35. }
  36. return ;
  37. }

D. Edge Deletion

题意:给出一个 n 个点 m 条边的图,问最多保留 k 条边的情况下,起点 1 到每个点的最短路不变的最多有多少个,输出保留的边。

题解:先对起点 1 跑一遍 dij,因为 n - 1 条边可以构成图的最短路,每条边产生对一个点的最短路,故跑 dij 时记录一下走当前这个点的边,跑 dfs 按顺序输出结果即可。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. const int INF = 0x3f3f3f3f;
  11. const double eps = 1e-;
  12. const int MAXN = 3e5 + ;
  13. const int MAXM = 2e5 + ;
  14. const ll mod = 1e9 + ;
  15.  
  16. struct edge {
  17. int v,w,id;
  18. };
  19.  
  20. vector<edge>g[MAXN];
  21. bool vis[MAXN];
  22. ll dis[MAXN];
  23. vector<int>ans;
  24. pii add[MAXN];
  25.  
  26. void dij(int s, int n) {
  27. ll inf2 = 1e16;
  28. for(int i = ; i <= n; ++i)
  29. dis[i] = inf2, vis[i] = ;
  30. dis[s] = ;
  31. priority_queue<pair<ll, int> >q;
  32. q.push(mp(, s));
  33. for(; !q.empty();) {
  34. int u = q.top().second;
  35. q.pop();
  36. if(vis[u]) continue;
  37. vis[u] = ;
  38. for(int j = , sz = g[u].size(); j < sz; ++j) {
  39. int v = g[u][j].v;
  40. int w = g[u][j].w;
  41. int id = g[u][j].id;
  42. if(dis[v] > dis[u] + w) {
  43. add[v] = mp(u,id);
  44. dis[v] = dis[u] + w;
  45. q.push(mp(-dis[v], v));
  46. }
  47. }
  48. }
  49. }
  50.  
  51. vector<pii>vec[MAXN];
  52. int tot;
  53.  
  54. void dfs(int u) {
  55. vis[u] = true;
  56. for(int i = ; i < vec[u].size() && tot; i++) {
  57. int v = vec[u][i].first, id = vec[u][i].second;
  58. if(vis[v]) continue;
  59. printf("%d ",id);
  60. tot--;
  61. dfs(v);
  62. }
  63. }
  64.  
  65. int main() {
  66. #ifdef local
  67. freopen("data.txt", "r", stdin);
  68. // freopen("data.txt", "w", stdout);
  69. #endif
  70. int n,m,k;
  71. scanf("%d%d%d",&n,&m,&k);
  72. for(int i = ; i <= m; i++) {
  73. int u,v,w;
  74. scanf("%d%d%d",&u,&v,&w);
  75. g[u].pb({v,w,i});
  76. g[v].pb({u,w,i});
  77. }
  78. dij(,n);
  79. for(int i = ; i <= n; i++) {
  80. vec[i].push_back(mp(add[i].first,add[i].second));
  81. vec[add[i].first].push_back(mp(i,add[i].second));
  82. }
  83. tot = min(n - ,k);
  84. printf("%d\n",min(n - ,k));
  85. mst(vis, false);
  86. dfs();
  87. return ;
  88. }

E. Vasya and a Tree

题意:有一棵 n 个点的树,有 m 次操作(v,d,x),每次将以 v 为根且距离 v <= d 的点加上权值 x(初始权值为0),输出最后每个点的权值。

题解:考虑离线操作,把每个点作为根的操作存起来,dfs 记录当前深度所增加的权值,对于不可到达的深度,用一个数组来记录要减去的值,差分的思想,详见代码~

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. const int INF = 0x3f3f3f3f;
  11. const double eps = 1e-;
  12. const int MAXN = 3e5 + ;
  13. const int MAXM = 2e5 + ;
  14. const ll mod = 1e9 + ;
  15.  
  16. vector<int>vec[MAXN];
  17. vector<pii>q[MAXN];
  18.  
  19. int h = -;
  20. ll ans[MAXN],dep[MAXN],now = ;
  21.  
  22. void dfs(int u,int fa) {
  23. h++;
  24. now += dep[h];
  25. for(int i = ; i < q[u].size(); i++) {
  26. int d = q[u][i].first, x = q[u][i].second;
  27. now += x;
  28. if(h + d + < MAXN) dep[h + d + ] -= x;
  29. }
  30. // cout << u << " " << fa << ":" << now << endl;
  31. ans[u] += now;
  32. for(int i = ; i < vec[u].size(); i++) {
  33. int v = vec[u][i];
  34. if(v == fa) continue;
  35. dfs(v,u);
  36. }
  37. for(int i = ; i < q[u].size(); i++) {
  38. int d = q[u][i].first, x = q[u][i].second;
  39. now -= x;
  40. if(h + d + < MAXN) dep[h + d + ] += x;
  41. }
  42. now -= dep[h];
  43. h--;
  44. }
  45.  
  46. int main() {
  47. #ifdef local
  48. freopen("data.txt", "r", stdin);
  49. // freopen("data.txt", "w", stdout);
  50. #endif
  51. int n;
  52. scanf("%d",&n);
  53. for(int i = ; i < n; i++) {
  54. int u,v;
  55. scanf("%d%d",&u,&v);
  56. vec[u].push_back(v);
  57. vec[v].push_back(u);
  58. }
  59. int m;
  60. scanf("%d",&m);
  61. while(m--) {
  62. int v,d,x;
  63. scanf("%d%d%d",&v,&d,&x);
  64. q[v].push_back(mp(d,x));
  65. }
  66. dfs(,);
  67. for(int i = ; i <= n; i++)
  68. printf("%lld ",ans[i]);
  69. return ;
  70. }

F. Summer Practice Report

题意:一本书有 n 页,每页有 xi 个 0 和 yi 个 1,问存不存在每页的数字构成一个序列,连起来之后最多连续的 0 和 1 不超过 k。

题解:记录每一页组成序列之后,连续 1 和连续 0 的最小值,转移即可。因为一页中连续的 1 最多 k 个,所以可容纳的 0 的个数为 pre0 + k * x,记录这个数是否大于 0 即可判断是否合法,1 也同理。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. const int INF = 0x3f3f3f3f;
  11. const double eps = 1e-;
  12. const int MAXN = 3e5 + ;
  13. const int MAXM = 2e5 + ;
  14. const ll mod = 1e9 + ;
  15.  
  16. ll x[MAXN],y[MAXN];
  17.  
  18. int main() {
  19. #ifdef local
  20. freopen("data.txt", "r", stdin);
  21. // freopen("data.txt", "w", stdout);
  22. #endif
  23. int n;
  24. ll k;
  25. scanf("%d%lld",&n,&k);
  26. for(int i = ; i <= n; i++) scanf("%lld",&x[i]);
  27. for(int i = ; i <= n; i++) scanf("%lld",&y[i]);
  28. ll nowx = -k, nowy = -k;
  29. for(int i = ; i <= n; i++) {
  30. nowx += x[i] - y[i] * k;
  31. nowy += y[i] - x[i] * k;
  32. if(nowx < -k) nowx = -k;
  33. if(nowy < -k) nowy = -k;
  34. if(nowx > || nowy > ) {
  35. puts("NO");
  36. return ;
  37. }
  38. }
  39. puts("YES");
  40. return ;
  41. }

G. Array Game(待补)

题意:

题解:

Codeforces Educational Codeforces Round 54 题解的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Codeforces Educational Codeforces Round 57 题解

    传送门 Div 2的比赛,前四题还有那么多人过,应该是SB题,就不讲了. 这场比赛一堆计数题,很舒服.(虽然我没打) E. The Top Scorer 其实这题也不难,不知道为什么这么少人过. 考虑 ...

  4. Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学

    E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...

  5. Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法

    D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...

  6. Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集

    C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...

  7. Codeforces Educational Codeforces Round 5 B. Dinner with Emma 暴力

    B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides t ...

  8. Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟

    A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You ...

  9. Codeforces Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA链上最大值

    E. Minimum spanning tree for each edge 题目连接: http://www.codeforces.com/contest/609/problem/E Descrip ...

随机推荐

  1. react生成二维码

    图片实例: 简介: QRCode.js 是一个生成二维码的JS库.主要是通过获取 DOM 的节点,再通过 HTML5 Canvas 绘制而成,不依赖任何库. 用法: 1. 在项目中引入qrcode.m ...

  2. 《Mysql - 优化器是如何选择索引的?》

    一:概念 - 在 索引建立之后,一条语句可能会命中多个索引,这时,索引的选择,就会交由 优化器 来选择合适的索引. - 优化器选择索引的目的,是找到一个最优的执行方案,并用最小的代价去执行语句. 二: ...

  3. AtCoder练习

    1. 3721 Smuggling Marbles 大意: 给定$n+1$节点树, $0$为根节点, 初始在一些节点放一个石子, 然后按顺序进行如下操作. 若$0$节点有石子, 则移入盒子 所有石子移 ...

  4. 【微信支付】公众号 JSAPI支付 HTML5(使用MUI前端框架)+WebApi 实现流程

    必要参数:      1) AppID,AppSecret : 在微信公众号后台管理—>(菜单栏)开发 —> 基本设置     2)商户号 :在微信公众号后台管理—>(菜单栏)微信支 ...

  5. .NET CORE 下 MariaDB DBfirst 生成model层 并配置连接参数

    1.首先新建一个类库,然后通过NuGet安装下面三个包 2.然后在程序包管理器控制台中运行以下代码(ps:记得默认项目选择刚才新建的项目,同时设置为启动项) server 是服务器地址 databas ...

  6. mysql 添加省市编码表

    省表格: --省级 Provincial create table Provincial(pid int,Provincial varchar(50),primary key (pid)) inser ...

  7. AI 公司与比赛

    科大讯飞 网站:https://www.iflytek.com/ 比赛:http://challenge.xfyun.cn/2019/ AI 大学:https://www.aidaxue.com/ 华 ...

  8. JS中的兼容性问题

    事件对象兼容        window.event只能在IE下运行,而不能在Firefox下运行,这是因为Firefox的event只能在事件发生的现场使用.Firefox必须从源处加入event作 ...

  9. react中key值的理解

    react利用key来识别组件,它是一种身份标识标识,相同的key react认为是同一个组件,这样后续相同的key对应组件都不会被创建有了key属性后,就可以与组件建立了一种对应关系,react根据 ...

  10. centos7安装google浏览器

    1. 配置yum源 在目录 /etc/yum.repos.d/ 下新建文件 google-chrome.repo cd /ect/yum.repos.d/ vim google-chrome.repo ...