当前位置: 首页 > news >正文

深圳专业网站制作费用北京搜索引擎优化seo专员

深圳专业网站制作费用,北京搜索引擎优化seo专员,如何做好seo,东莞常平网站建设目录 C. Socks 2 D. Reindeer and Sleigh E. Christmas Color Grid 1 C. Socks 2 首先先对 k 进行分类: (1) k 为偶数,直接从头开始两两配对 (2)k 为奇数,此时一定会有一只袜子无法配对。当没有…

目录

        C. Socks 2

        D. Reindeer and Sleigh 

        E. Christmas Color Grid 1


 

 

 

C. Socks 2

        首先先对 k 进行分类:

        (1) k 为偶数,直接从头开始两两配对

        (2)k 为奇数,此时一定会有一只袜子无法配对。当没有思路的时候,就去想把什么作为枚举量,显然这里枚举哪一只袜子丢弃不配对。容易证明丢弃的袜子一定是奇数位。此时的问题就类似于讲一个数组从某一点切成两端,典型的需要同时维护前后缀。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, INF = 1e18;int T, n, k, cnt, ans, a[N], f[N], g[N];signed main()
{cin >> n >> k;for (int i = 1; i <= k; i ++)cin >> a[i];sort(a + 1, a + k + 1);if (k % 2 == 0){for (int i = 2; i <= k; i += 2)ans += a[i] - a[i - 1];}else{ans = INF;for (int i = 2; i <= k; i += 2)f[i] = f[i - 2] + a[i] - a[i - 1];for (int i = k - 1; i >= 1; i -= 2)g[i] = g[i + 2] + a[i + 1] - a[i];for (int i = 1; i <= k; i += 2)ans = min(ans, f[i - 1] + g[i + 1]);}cout << ans;return 0;
}

 

 

 

 

 

D. Reindeer and Sleigh 

 

        首先明确,最后是要查询 n 匹鹿能拉多少雪橇,那么用来查询的答案数组的下标就一定是鹿的匹数,这样就能实现 O(1) 的查询。看到鹿匹数数据量达 1e9,可以想到肯定不可能把答案数组填满,但是可以通过 upper 查询来实现。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, INF = 1e18;int T, n, q, cnt, ans, a[N], d[N];signed main()
{cin >> n >> q;for (int i = 1; i <= n; i ++)cin >> a[i];sort(a + 1, a + n + 1);for (int i = 1; i <= n; i ++)d[i] = d[i - 1] + a[i];while (q --){int x;cin >> x;if (x > d[n])ans = n;else{int pos = upper_bound(d + 1, d + n + 1, x) - d;ans = pos - 1;}cout << ans << '\n';}return 0;
}

 

 

 

 

 

E. Christmas Color Grid 1

 

         看到判连通块数量,而且后续存在连通块合并的操作,用并查集。

        对于每一红色的点,如果将它染成绿色会导致与它相邻的绿色连通块合并,那么连通块数量是减少的。

        如何在二维地图上用并查集呢?方法是把二维坐标转换成一维数组

 

行优先
n 行 m 列的地图,行列下标都从 1 开始
(x, y) --> (x - 1) * m + y下标从 0 开始
(x, y) --> x * m + y - 1

 

        在枚举红色的点的时候,将其四周的绿色的点所在集合的代表存入 set 即可去重,set.size()就是红点直接相邻的绿色集合数。

 

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e3 + 5, INF = 1e18, mod = 998244353;struct node
{int x, y;
};int T, n, m, cnt, tot, cnth, ans, fa[N * N];
char c[N][N];
set<int> se;int fpow(int a, int b)
{int res = 1;while (b){if (b & 1)res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}int find(int x)
{if (x == fa[x])return x;return fa[x] = find(fa[x]);
}void join(int x, int y)
{x = find(x), y = find(y);if (x != y)fa[x] = y;
}int get(int x, int y)
{return (x - 1) * m + y;
}signed main()
{cin >> n >> m;int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};for (int i = 1; i <= n; i ++)for (int j = 1; j <= m; j ++)cin >> c[i][j];for (int i = 1; i <= n * m; i ++)fa[i] = i;for (int i = 1; i <= n; i ++)for (int j = 1; j <= m; j ++)if (c[i][j] == '#')for (int k = 0; k < 4; k ++){int tx = i + dx[k], ty = j + dy[k];if (tx < 1 || tx > n || ty < 1 || ty > m || c[tx][ty] == '.')continue;join(get(i, j), get(tx ,ty));}for (int i = 1; i <= n; i ++)for (int j = 1; j <= m; j ++)if (c[i][j] == '#')se.insert(find(get(i, j)));cnt = se.size();for (int i = 1; i <= n; i ++)for (int j = 1; j <= m; j ++)if (c[i][j] == '.'){cnth ++;set<int> se2;for (int k = 0; k < 4; k ++){int tx = i + dx[k], ty = j + dy[k];if (tx < 1 || tx > n || ty < 1 || ty > m || c[tx][ty] == '.')continue;se2.insert(find(get(tx, ty)));}if (se2.size() == 0)tot += cnt + 1;elsetot += cnt - (se2.size() - 1);}ans = tot % mod * fpow(cnth, mod - 2) % mod;cout << ans;return 0;
}
http://www.hengruixuexiao.com/news/20108.html

相关文章:

  • 网站设计 注意代运营服务
  • 可做外链的网站媒体平台推广
  • 用php做的网站必备那些文件抖音推广公司
  • 做网站的难题怎样在平台上发布信息推广
  • 广州网站建设出名 乐云践新搜索引擎优化seo多少钱
  • 桂林北站停车场收费标准seo网络推广外包公司
  • 网站问答平台推广方案接app推广接单平台
  • 2012服务器如何做网站新网站如何快速收录
  • 纹身网站建设案例个人接外包的网站
  • 电器网站制作价格站长网站推广
  • 深圳网站制作收费商丘网站seo
  • 建个淘宝那样的网站需要多少钱企业网络营销成功案例
  • 做书的网站有哪些内容软文写作是什么
  • 京东商城网站怎么做的自适应网站服务器软件
  • 手机app设计网站建设百度资源搜索资源平台
  • 小兽 wordpress深圳seo优化排名
  • 百度网站是百度公司做的吗网站seo视频狼雨seo教程
  • 做ppt赚钱的网站百度手机端推广
  • logo在线制作免费网站深圳网站搜索优化工具
  • 网站正能量入口郴州网络推广公司排名
  • 电子商城网站模板学技术包分配的培训机构
  • 电子商务网站建设重要性企业做推广有用吗
  • 江门网站制作网页设计制作网站模板图片
  • 杭州做营销型网站一周热点新闻
  • web网站开发实训总结郑州seo排名工具
  • 搜狐视频网站联盟怎么做chrome手机版
  • 四川疫情最新情况分布图重庆seo整站优化系统
  • html购物网站设计武汉seo 网络推广
  • 怎么将自己做的网站放到网上互联网推广渠道
  • 网站tag标签功能实现小红书如何引流推广