留念

C - 志愿者

排序。。按照题目规则说的排就可以。wa了两发我太菜了qwq

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1e6 + 10;
  4. inline int read() {
  5. char c = getchar(); int x = 0, f = 1;
  6. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  7. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  8. return x * f;
  9. }
  10. struct Node {
  11. int t, k, id;
  12. bool operator < (const Node &b) const {
  13. if(t * k > b.t * b.k) return 1;
  14. else if(t * k < b.t * b.k) return 0;
  15. if(t > b.t) return 1;
  16. else if(t < b.t) return 0;
  17. return id < b.id;
  18. }
  19. }a[MAXN];
  20. int main() {
  21. int N = read();
  22. for(int i = 1; i <= N; i++) {
  23. a[i].t = read();
  24. a[i].k = read();
  25. a[i].id = i;
  26. }
  27. sort(a + 1, a + N + 1);
  28. for(int i = 1; i <= N; i++)
  29. cout << a[i].id << ' ';
  30. return 0;
  31. }

D - 终端

模拟一下就行了吧。。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1e6 + 10;
  4. inline int read() {
  5. char c = getchar(); int x = 0, f = 1;
  6. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  7. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  8. return x * f;
  9. }
  10. map<string, int> mp;
  11. string opt;
  12. int main() {
  13. #ifndef ONLINE_JUDGE
  14. freopen("a.in", "r", stdin);
  15. #endif
  16. int N = read();
  17. for(int i = 1; i <= N; i++) {
  18. cin >> opt;
  19. if(opt == "touch") {
  20. string fn;
  21. cin >> fn;
  22. if(mp.find(fn) != mp.end()) continue;
  23. mp[fn] = i;
  24. } else if(opt == "rm") {
  25. string fn;
  26. cin >> fn;
  27. if(mp.find(fn) == mp.end()) continue;
  28. mp.erase(fn);
  29. } else if(opt == "ls") {
  30. vector<pair<int, string>> tmp;
  31. for(auto &x: mp) {
  32. tmp.push_back(make_pair(x.second, x.first));
  33. }
  34. sort(tmp.begin(), tmp.end());
  35. for(auto x: tmp)
  36. cout << x.second << '\n';
  37. } else if(opt == "rename") {
  38. string s1, s2;
  39. cin >> s1 >> s2;
  40. if(mp.find(s1) == mp.end()) continue;
  41. int tmp = mp[s1];
  42. mp.erase(s1);
  43. mp[s2] = tmp;
  44. }
  45. }
  46. return 0;
  47. }

E - 运气

显然每个位置只能是1-6,因此所有状态数是\(6^{10}\)不会很大,dfs一下

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1e6 + 10;
  4. const int mod = 1e9 + 7;
  5. #define LL long long
  6. inline int read() {
  7. char c = getchar(); int x = 0, f = 1;
  8. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  9. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  10. return x * f;
  11. }
  12. LL N, K, ans;
  13. void dfs(int x, LL val) {
  14. if(x == N + 1) {
  15. ans += (val % K == 0);
  16. return ;
  17. }
  18. for(int i = 1; i <= 6; i++)
  19. dfs(x + 1, val * 10 + i);
  20. }
  21. int main() {
  22. #ifndef ONLINE_JUDGE
  23. freopen("a.in", "r", stdin);
  24. #endif
  25. N = read(); K = read();
  26. dfs(1, 0);
  27. cout << ans % mod;
  28. return 0;
  29. }

F - 游戏

首先题目有个bug,没有描述序列中有相同数的情况

那就假设所有数都不相同

可以分两种情况考虑,\(c1 < c2\)和\(c1 > c2\),相等的话直接输出\((N - 1) * c1\)就行。

这两种是类似的,这里只说第一种。

显然,数组中的每一对数都有两种情况:1.异或之后二进制位仅有1位为1,2.有多位唯一。

接下来我是转化成了图论问题去考虑,不然感觉有点复杂。

我们把所有异或之后二进制位仅有1个1的点之间连边。

考虑得到的这张图的性质:

对于任意一个联通块,我们一定能通过使用c1代价来每次消掉一个元素,并能保证最后只剩下一个元素。

emmm,,至于为什么,,可以从联通块中抽出一个树来,显然每次从叶子节点删,一定满足条件。

这样的话,只需要dfs出所有联通块,并求出其大小就好。

然后加加减减把答案算出来,具体看代码

复杂度\(O(n^2)\)(实际上还可以优化为\(O(nlogn)\),这里不再赘述)

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1e6 + 10;
  4. const int mod = 1e9 + 7;
  5. #define LL long long
  6. inline int read() {
  7. char c = getchar(); int x = 0, f = 1;
  8. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  9. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  10. return x * f;
  11. }
  12. int N, c1, c2, a[MAXN], vis[MAXN];
  13. LL cnt = 0, ans;
  14. vector<int> v[MAXN];
  15. void dfs(int x) {
  16. cnt++;
  17. vis[x] = 1;
  18. for(auto &to: v[x]) {
  19. if(!vis[to])
  20. dfs(to);
  21. }
  22. }
  23. void dfs2(int i) {
  24. cnt++;
  25. vis[i] = 1;
  26. for(int j = 1; j <= N; j++) {
  27. if(__builtin_popcount(a[i] ^ a[j]) != 1 && i != j && vis[j] == 0) {
  28. dfs2(j);
  29. }
  30. }
  31. }
  32. int main() {
  33. #ifndef ONLINE_JUDGE
  34. freopen("a.in", "r", stdin);
  35. #endif
  36. N = read();
  37. c1 = read(); c2 = read();
  38. for(int i = 1; i <= N; i++) a[i] = read();
  39. if(c1 == c2) cout << 1ll * (N - 1) * c1;
  40. else if(c1 < c2) {
  41. for(int i = 1; i <= N; i++)
  42. for(int j = 1; j <= N; j++)
  43. if(__builtin_popcount(a[i] ^ a[j]) == 1 && i != j)
  44. v[i].push_back(j);
  45. LL sum = N;
  46. for(int i = 1; i <= N; i++) {
  47. if(!vis[i]) {
  48. dfs(i);
  49. ans += 1ll * (cnt - 1) * c1;
  50. sum -= (cnt - 1);
  51. cnt = 0;
  52. }
  53. }
  54. ans += 1ll * (sum - 1) * c2;
  55. cout << ans << '\n';
  56. } else {
  57. LL sum = N;
  58. for(int i = 1; i <= N; i++) {
  59. if(!vis[i]) {
  60. dfs2(i);
  61. ans += 1ll * (cnt - 1) * c2;
  62. sum -= (cnt - 1);
  63. cnt = 0;
  64. }
  65. }
  66. ans += 1ll * (sum - 1) * c1;
  67. cout << ans << '\n';
  68. }
  69. return 0;
  70. }
  71. /*
  72. */

G - 森林

(好久没打比赛,开场还以为是个LCT,后来又想操作子树的好像是ETT,不过还好及时终止了自己的危险想法)

感觉这题思维上比上一题简单不少,

对于第一个删边比较难操作

可以倒序考虑转化成加边。

然后并查集维护连通性就ok了

具体看代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1e6 + 10;
  4. const int mod = 1e9 + 7;
  5. #define LL long long
  6. inline int read() {
  7. char c = getchar(); int x = 0, f = 1;
  8. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  9. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  10. return x * f;
  11. }
  12. int N, M;
  13. int fa[MAXN], sum[MAXN];
  14. struct Edge {
  15. int u, v;
  16. }E[MAXN];
  17. struct Opt {
  18. int opt, a, b;
  19. }op[MAXN];
  20. int val[MAXN], flag[MAXN];
  21. int find(int x) {
  22. return x == fa[x] ? x : fa[x] = find(fa[x]);
  23. }
  24. void unionn(int x, int y) {
  25. int fx = find(x), fy = find(y);
  26. sum[fy] += sum[fx];
  27. sum[fx] = 0;
  28. fa[fx] = fy;
  29. }
  30. int query(int x) {
  31. return sum[find(x)];
  32. }
  33. vector<int> ans;
  34. int main() {
  35. #ifndef ONLINE_JUDGE
  36. freopen("a.in", "r", stdin);
  37. #endif
  38. N = read(); M = read();
  39. for(int i = 1; i <= N; i++) val[i] = read(), fa[i] = i;
  40. for(int i = 1; i < N; i++) {
  41. E[i].u = read();
  42. E[i].v = read();
  43. }
  44. for(int i = 1; i <= M; i++) {
  45. op[i].opt = read();
  46. if(op[i].opt == 1) {
  47. op[i].a = read();//add E[a]
  48. flag[op[i].a] = 1;
  49. } else if(op[i].opt == 2) {
  50. op[i].a = read(), op[i].b = read();
  51. int tmp = val[op[i].a];//ÖÇ°µÄval
  52. val[op[i].a] = op[i].b;
  53. op[i].b = tmp;
  54. } else {
  55. op[i].a = read();
  56. }
  57. }
  58. for(int i = 1; i <= N; i++) sum[i] = val[i];
  59. for(int i = 1; i < N; i++) {
  60. if(!flag[i]) {//not delet
  61. unionn(E[i].u, E[i].v);
  62. }
  63. }
  64. for(int i = M; i >= 1; i--) {
  65. if(op[i].opt == 1) {
  66. int id = op[i].a;
  67. unionn(E[id].u, E[id].v);
  68. } else if(op[i].opt == 2) {
  69. int id = op[i].a, pre = val[id];
  70. int fx = find(id);
  71. sum[fx] -= pre;
  72. sum[fx] += op[i].b;
  73. val[id] = op[i].b;
  74. } else {
  75. ans.push_back(query(op[i].a));
  76. }
  77. }
  78. reverse(ans.begin(), ans.end());
  79. for(auto &x: ans) cout << x << '\n';
  80. return 0;
  81. }
  82. /*
  83. */

第三届“传智杯”全国大学生IT技能大赛(初赛A组)题解的更多相关文章

  1. 第四届“传智杯”全国大学生IT技能大赛题解

    目录 A B C D E F G 今年题目难度普遍偏低.只有 D,F 还好. A 按题目给的公式计算即可.注意应在最后的答案中去掉小数部分. B 按照题意模拟即可.注意答案要与 \(0\) 取 \(\ ...

  2. 第二届360杯全国大学生信息安全技术大赛部分解题思路(WEB安全)

    第一题如下: 用burpsuit设置好代理后,点击发送验证码,可以看到如下: 然后go之后可以看到如下的验证码: 提交验证码后即可获得key 第二题如下: 通过/data/mysql_error_tr ...

  3. 2019"深思杯"山东省大学生网络安全技能大赛部分wp

    签到 载入OD查看字符串 上下左右 这道题出来的时候真的是一点思路都没有,一直以为是什么编码来着,看了大佬们的 wp 原来是画图 拿大佬的脚本: from PIL import Image im = ...

  4. 2018年高教社杯全国大学生数学建模竞赛C题解题思路

    题目 C题   大型百货商场会员画像描绘 在零售行业中,会员价值体现在持续不断地为零售运营商带来稳定的销售额和利润,同时也为零售运营商策略的制定提供数据支持.零售行业会采取各种不同方法来吸引更多的人成 ...

  5. 2018年高教社杯全国大学生数学建模竞赛D题解题思路

    题目 D题   汽车总装线的配置问题 一.问题背景 某汽车公司生产多种型号的汽车,每种型号由品牌.配置.动力.驱动.颜色5种属性确定.品牌分为A1和A2两种,配置分为B1.B2.B3.B4.B5和B6 ...

  6. 2018年高教社杯全国大学生数学建模竞赛B题解题思路

    题目 先贴下B题的题目吧 问题B    智能RGV的动态调度策略 图1是一个智能加工系统的示意图,由8台计算机数控机床(Computer Number Controller,CNC).1辆轨道式自动引 ...

  7. 2018年高教社杯全国大学生数学建模竞赛A题解题思路

    题目 先贴一下A的题目吧 A题   高温作业专用服装设计 在高温环境下工作时,人们需要穿着专用服装以避免灼伤.专用服装通常由三层织物材料构成,记为I.II.III层,其中I层与外界环境接触,III层与 ...

  8. 2021陕西省大学生网络安全技能大赛 Web ez_checkin

    web ez_checkin 进去看了一会,啥也没找到,直接上dirsearch 扫到一个index.php~,打开看一看,是php审计 <?php error_reporting(0); in ...

  9. 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 题解

    比赛链接:http://acm-software.hrbust.edu.cn/contest.php?cid=1082 A.好SB啊真是,还以为lis-数有多少个数不一样. #include < ...

随机推荐

  1. 基于hadoop_yarn的资源隔离配置

    目录 yarn的基本概念 scheduler 集群整体的资源定义 fair scheduler简介 配置demo 队列的资源限制 基于具体资源限制 基于权重资源限制 队列运行状态限制 基于用户和分组限 ...

  2. layui 如果调用 from 内嵌入的 iframe子页面方法

    (人笨,占时想法的办法,不要骂,不要骂,怕了怕了,想到别的会来改的) 父页面; <%@ page language="java" contentType="text ...

  3. 如何将rabbitmq集群中的某个节点移除.

    首先将要移除的节点停机. root@rabbitmq-03:~# rabbitmqctl stop Stopping and halting node 'rabbit@rabbitmq-03' ... ...

  4. 动图图解!怎么让goroutine跑一半就退出?

    光看标题,大家可能不太理解我说的是啥. 我们平时创建一个协程,跑一段逻辑,代码大概长这样. package main import ( "fmt" "time" ...

  5. [loj3331]选课

    考虑$P=0$,由于$T-\sum_{i=1}^{m}s_{i}\le 40$,因此一个第$i$个分类中最多得到$s_{i}+42$的学分,可以对每一类分别背包 暴力背包复杂度为$o(n^{2})$, ...

  6. [luogu5426]Balancing Inversions

    由于交换是相邻交换,所以分为两类:1.左右区间内部交换,那么一定会让逆序对数量$\pm 1$,也就是说如果没有左右区间之间交换,那么答案就是$|ansL-ansR|$(ans表示逆序对数量)2.左右区 ...

  7. 【Redis】(1)-- 关系型数据库与非关系型数据库

    关系型数据库与非关系型数据库 2019-07-02  16:34:48  by冲冲 1. 关系型数据库 1.1 概念 关系型数据库,是指采用了关系模型来组织数据的数据库.关系模型指的就是二维表格模型, ...

  8. go 自定义http.Client - 动态修改请求Body

    前言 在对接Alexa Smart Home时,有的请求Payload中需要传入Access Token,但是这个Token是由OAuth2 Client管理的,封装Payload时并不知道Acces ...

  9. 【树莓派】Python开发工控机急停设计

    背景 我们在一些工业产品中使用树莓派替代了PLC和上位机,并借助树莓派的算力将AI和机器视觉引入工业领域. 以前的产品都不存在动作机构,仅仅将结果输出到指示灯.蜂鸣器或者显示器上,没有安全隐患, 现在 ...

  10. Redis概述以及Linux安装

    Redis 概述 Redis是什么 Redis,Remote Dictionary Server,远程字典服务.是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.key-v ...