留念

C - 志愿者

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

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
struct Node {
int t, k, id;
bool operator < (const Node &b) const {
if(t * k > b.t * b.k) return 1;
else if(t * k < b.t * b.k) return 0; if(t > b.t) return 1;
else if(t < b.t) return 0; return id < b.id;
}
}a[MAXN];
int main() {
int N = read();
for(int i = 1; i <= N; i++) {
a[i].t = read();
a[i].k = read();
a[i].id = i;
}
sort(a + 1, a + N + 1);
for(int i = 1; i <= N; i++)
cout << a[i].id << ' ';
return 0;
}

D - 终端

模拟一下就行了吧。。

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
map<string, int> mp;
string opt;
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
int N = read();
for(int i = 1; i <= N; i++) {
cin >> opt;
if(opt == "touch") {
string fn;
cin >> fn;
if(mp.find(fn) != mp.end()) continue;
mp[fn] = i;
} else if(opt == "rm") {
string fn;
cin >> fn;
if(mp.find(fn) == mp.end()) continue;
mp.erase(fn);
} else if(opt == "ls") {
vector<pair<int, string>> tmp;
for(auto &x: mp) {
tmp.push_back(make_pair(x.second, x.first));
}
sort(tmp.begin(), tmp.end());
for(auto x: tmp)
cout << x.second << '\n';
} else if(opt == "rename") {
string s1, s2;
cin >> s1 >> s2;
if(mp.find(s1) == mp.end()) continue;
int tmp = mp[s1];
mp.erase(s1);
mp[s2] = tmp;
}
}
return 0;
}

E - 运气

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

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
#define LL long long
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
LL N, K, ans;
void dfs(int x, LL val) {
if(x == N + 1) {
ans += (val % K == 0);
return ;
}
for(int i = 1; i <= 6; i++)
dfs(x + 1, val * 10 + i);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
N = read(); K = read();
dfs(1, 0);
cout << ans % mod;
return 0;
}

F - 游戏

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

那就假设所有数都不相同

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

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

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

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

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

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

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

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

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

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

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

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
#define LL long long
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, c1, c2, a[MAXN], vis[MAXN];
LL cnt = 0, ans;
vector<int> v[MAXN];
void dfs(int x) {
cnt++;
vis[x] = 1;
for(auto &to: v[x]) {
if(!vis[to])
dfs(to);
}
}
void dfs2(int i) {
cnt++;
vis[i] = 1;
for(int j = 1; j <= N; j++) {
if(__builtin_popcount(a[i] ^ a[j]) != 1 && i != j && vis[j] == 0) {
dfs2(j);
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
N = read();
c1 = read(); c2 = read();
for(int i = 1; i <= N; i++) a[i] = read();
if(c1 == c2) cout << 1ll * (N - 1) * c1;
else if(c1 < c2) {
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
if(__builtin_popcount(a[i] ^ a[j]) == 1 && i != j)
v[i].push_back(j);
LL sum = N;
for(int i = 1; i <= N; i++) {
if(!vis[i]) {
dfs(i);
ans += 1ll * (cnt - 1) * c1;
sum -= (cnt - 1);
cnt = 0;
}
}
ans += 1ll * (sum - 1) * c2;
cout << ans << '\n';
} else {
LL sum = N;
for(int i = 1; i <= N; i++) {
if(!vis[i]) {
dfs2(i);
ans += 1ll * (cnt - 1) * c2;
sum -= (cnt - 1);
cnt = 0;
}
}
ans += 1ll * (sum - 1) * c1;
cout << ans << '\n';
}
return 0;
}
/* */

G - 森林

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

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

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

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

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

具体看代码

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int mod = 1e9 + 7;
#define LL long long
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M;
int fa[MAXN], sum[MAXN];
struct Edge {
int u, v;
}E[MAXN];
struct Opt {
int opt, a, b;
}op[MAXN];
int val[MAXN], flag[MAXN];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void unionn(int x, int y) {
int fx = find(x), fy = find(y);
sum[fy] += sum[fx];
sum[fx] = 0;
fa[fx] = fy;
}
int query(int x) {
return sum[find(x)];
}
vector<int> ans;
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
N = read(); M = read();
for(int i = 1; i <= N; i++) val[i] = read(), fa[i] = i;
for(int i = 1; i < N; i++) {
E[i].u = read();
E[i].v = read();
}
for(int i = 1; i <= M; i++) {
op[i].opt = read();
if(op[i].opt == 1) {
op[i].a = read();//add E[a]
flag[op[i].a] = 1;
} else if(op[i].opt == 2) {
op[i].a = read(), op[i].b = read();
int tmp = val[op[i].a];//ÖǰµÄval
val[op[i].a] = op[i].b;
op[i].b = tmp;
} else {
op[i].a = read();
}
}
for(int i = 1; i <= N; i++) sum[i] = val[i];
for(int i = 1; i < N; i++) {
if(!flag[i]) {//not delet
unionn(E[i].u, E[i].v);
} }
for(int i = M; i >= 1; i--) {
if(op[i].opt == 1) {
int id = op[i].a;
unionn(E[id].u, E[id].v);
} else if(op[i].opt == 2) {
int id = op[i].a, pre = val[id];
int fx = find(id);
sum[fx] -= pre;
sum[fx] += op[i].b;
val[id] = op[i].b;
} else {
ans.push_back(query(op[i].a));
}
} reverse(ans.begin(), ans.end());
for(auto &x: ans) cout << x << '\n';
return 0;
}
/* */

第三届“传智杯”全国大学生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. 【Azure 环境】用 PowerShell 调用 AAD Token, 以及调用Azure REST API(如资源组列表)

    问题描述 PowerShell 脚本调用Azure REST API, 但是所有的API都需要进行权限验证.要在请求的Header部分带上Authorization参数,并用来对List Resour ...

  2. 使用Token进行CSRF漏洞防御

    1.登录验证成功之后,在会话SESSION["user_token"]中保存Token. 2.在后台操作中,增删改表单中添加隐藏域hidden,设置value为Token. 3.提 ...

  3. [gym102412D]The Jump from Height of Self-importance to Height of IQ Level

    考虑使用平衡树维护该序列,操作显然可以用fhq treap的分裂+合并来实现 进一步的,问题即变为维护哪些信息来支持push up的操作(并判定是否存在$a_{i}<a_{j}<a_{k} ...

  4. 应用程序池自动停止,事件查看器报错6D000780

    20210913 今天中午网站突然报错,后台程序无法访问,503错误. 调查发现"应用程序池"被关闭,但是手动开启后不久,又被关闭. 本地调试没问题,所以一开始怀疑是服务器或者Ng ...

  5. 关于"丢失的牛"这个题的教学反思

    某天上课讲到这样一个题:丢失的牛1~n,乱序排列,告诉从第二个位置到最后一个位置, 每个位置的前面的数字中比它小的数的个数,求每个位置的数字是多少N<=8000 FormatInput第一行给出 ...

  6. 力扣 - 剑指 Offer 46. 把数字翻译成字符串

    题目 剑指 Offer 46. 把数字翻译成字符串 思路1(递归,自顶向下) 这题和青蛙跳台阶很类似,青蛙跳台阶说的是青蛙每次可以跳一层或者两层,跳到第 n 层有多少种解法,而这题说的是讲数字翻译成字 ...

  7. CSP-S2021 挂分记

    赛前 数了数,这是我第五次来南航,不知道以后还有机会了(2018 NOIP, 2019CSP, 2020CSP, 2020NOIP). 上午一觉睡到 10 点,学了一下感觉很有用的 BIT 倍增,顺手 ...

  8. R绘图布局包 customLayout

    今天介绍一个R画图布局的包,地址如下: https://github.com/zzawadz/customLayout https://www.customlayout.zstat.pl/index. ...

  9. MybatisPlus的CRUD及拓展

    创建一个简单的MybatisPlus项目在上一篇博客:MybatisPlus入门程序 一.CRUD 1. select 1.1 查找全部用户 //查 @Test public void select( ...

  10. 简单的Mybatis程序

    1.新建一个普通Maven项目,导入 mybatis.mysql.junit(用于测试)3个依赖 Mybatis <dependency> <groupId>org.mybat ...