本来想说这场放掉了,算了还是补了吧...

以下题解包括:

\[1001【HDU-6614】 \\ 1003【HDU-6616】 \\ 1007【HDU-6620】 \\ 1008【HDU-6621】 \\ 1010【HDU-6623】\]

【1001】 思维 HDU-6614 AND Minimum Spanning Tree

http://acm.hdu.edu.cn/showproblem.php?pid=6614

需要建一颗树,使得边权值和最小,边权为两点的 “&” 值。

假设二进制位 101,那就和 2 连接;假设为 111,那就看一下有没有 8 这个点,没有的话就和点 1 连接。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;const int maxn = 2e5+5;int a[maxn];int wei(int x) {int ans = 0;while(x) {ans ++;x /= 2;}return ans;
}int main() {int t;scanf("%d", &t);while(t--) {int n;scanf("%d", &n);int x = wei(n);int s = 0;for(int i = 0; i < x; i++) {if((n>>i) & 1) {s++;}   }int ans = 0;if(s == x) {ans ++;}printf("%d\n", ans);for(int i = 2; i <= n; i++) {if(ans == 1 && i == n) {    printf("1\n");break;}for(int j = 0; j < x; j++) {if((i>>j) & 1) {continue;}printf("%d%c", (1<<j), i==n?'\n':' ');break;}} }return 0;
}

【1003】 思维 HDU-6616 Divide the Stones

http://acm.hdu.edu.cn/showproblem.php?pid=6616

给定重量 \(1\) 到 \(n\) 的 \(n\) 个石头,让你分成重量相等,数量也相等的 \(k\) 组,保证 \(k\) 是 \(n\) 的约数。输出具体的分配方案。

参考:https://www.cnblogs.com/isakovsky/p/11281662.html

首先,如果 \(1\) 到 \(n\) 之和不能整除 \(k\),那么一定不能分配;否则一定能。

设 \(m=n/k\)。\(m\) 是每组分到的石头块数。我们把n块石头排成这样 \(m*k\) 的矩阵,假设 12 块石头,分成 3 组。
\[ \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ 10 &11 &12 \end{bmatrix} \]

  • m为偶数,只要每次取头尾各 \(m/2\) 个即可。
  • m为奇数,将后两列之和构造成从上到下递增1,然后剩下的奇数个,一行构造成递增,一行构造成递减。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;int main() {int t;scanf("%d", &t);while(t--) {int n, k;scanf("%d%d", &n, &k);ll sum = 1ll*n*(n+1)/2;if(k == 1) {printf("yes\n");for(int i = 1; i <= n; i++) {printf("%d%c", i, i==n?'\n':' ');}}else if(sum % k) {printf("no\n");}else {printf("yes\n");if((n/k) % 2 == 0) {int x = n / k;int cnt = 0;for(int i = 1; i <= n/2; i++) {printf("%d %d", i, n-i+1);cnt += 2;if(cnt == x) {printf("\n");cnt = 0;}else {printf(" ");}}}else {int x = n / k;int tot = 1 + 2*k - k/2;int temp = 1;for(int i = 1; i <= k; i++) {for(int j = 1; j <= x-2; j++) {if(j % 2 == 1) {printf("%d ", n-(j-1)*k-i+1);}else {printf("%d ", n-j*k+1+i-1);}}printf("%d %d\n", temp, tot - temp);tot ++;temp += 2;if(temp > k) {temp = 2;}}}}}return 0;
}

【1007】 思维 HDU-6620 Just an Old Puzzle

http://acm.hdu.edu.cn/showproblem.php?pid=6620

给定一个数字拼图,问能否能复原成原来的样子(120步以内)。

经典的华容道问题变形。

定理:逆序数奇偶相同时,可以互相转化,逆序数奇偶不同,不能互相转化。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;int a[20];int main( ) {int t;scanf("%d", &t);int flag, ans;while(t--) {ans = 0;for(int i = 1; i <= 16; i++) {scanf("%d", &a[i]);if(a[i] == 0) {flag = i / 4 + (i % 4 != 0);}else {for(int j = 1; j < i; j++) {if(a[j] == 0) {continue;}if(a[j] > a[i]) {ans++;} }}}printf((4-flag) % 2 == ans % 2 ? "Yes\n" : "No\n");}return 0;
}

【1008】 主席树 HDU-6621 K-th Closest Distance

http://acm.hdu.edu.cn/showproblem.php?pid=6621

给定 \(n\) 个数,\(q\) 次查询,每次查询 \([l , r]\) 内, \(| a[i] - p |\) 第 \(k\) 大的数,且强制要求在线。其中 \(n \leq 1e^5 \ \ q \leq 1e^5\)

比赛时候一直想着主席树,一直没办法吧 k 这个大常数优化掉,就 T 了一整场。结果发现可以换一种存法就行了,或许应该叫权值主席树?QAQ

主席树的结点直接就是 \(1e^6\) 个值,不进行离散化,对每个值都单独统计出现的次数。二分查询 \((p-mid,p+mid)\) 中数的个数。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;const int maxn = 1e6 + 5;int n, m, cnt, new_n;
int a[maxn];
int root[maxn];
vector<int> v;
struct node {int l, r, sum;
}T[maxn*40];void init() {v.clear();cnt = 0;
}inline void update(int l, int r, int &x, int y, int val) {T[++cnt] = T[y];T[cnt].sum ++;x = cnt;if(l == r) {return ;}int mid = (l+r) / 2;if(mid >= val) {update(l, mid, T[x].l, T[y].l, val);}else {update(mid+1, r, T[x].r, T[y].r, val);}
}inline int query(int L, int R, int l, int r, int x, int y) {if(L <= l && r <= R) {return T[y].sum - T[x].sum;}int mid = (l+r) / 2;int ans = 0;if(L <= mid) {ans += query(L, R, l, mid, T[x].l, T[y].l);}if(R > mid) {ans += query(L, R, mid+1, r, T[x].r, T[y].r);}return ans;
}int main() {int t;scanf("%d", &t);while(t--) {init();int MAX = 1000000;scanf("%d%d", &n, &m);for(int i = 1; i <= n; i++) {scanf("%d", &a[i]);}for(int i = 1; i <= n; i++) {update(1, MAX, root[i], root[i-1], a[i]);}int ans = 0;for(int i = 1; i <= m; i++) {int l, r, p, k;scanf("%d%d%d%d", &l, &r, &p, &k);l = l^ans;r = r^ans;p = p^ans;k = k^ans;int L = 0;int R = MAX;while(L <= R) {int mid = (L+R) >> 1;if(query(max(1, p-mid), min(MAX, p+mid), 1, MAX, root[l-1], root[r]) >= k) {ans = mid;R = mid - 1;}else {L = mid + 1;}}printf("%d\n", ans);}}return 0;
}

【1010】 数学 HDU-6623 Minimal Power of Prime

http://acm.hdu.edu.cn/showproblem.php?pid=6623

给定一个数 \(n\),求它的素因子里最大的指数是多少。

考虑 \(n^{1/5}\) 范围内的素数,计算范围内的最小素数的次数是多少,然后除去这些素数,得到剩余的数字 \(m\),考虑 \(m\) 如果大于 10009(就是素数1~n^(1/5)范围内的素数,n的范围是(10009,1e18),此时已知最小素数时10009,所以最是最小素数的4次方,分别讨论m是否为素数的2,3,4次方即可,如果都不是,就是1次方)。要特判1。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;const int maxn = 1e4+5;int vis[maxn], pri[maxn];
int tot;
ll n;void prime() {for(int i = 2; i < maxn; i++) {if(vis[i] == 0) {pri[tot++] = i;for(int j = i*i; j < maxn; j+=i) {vis[j] = 1;}}}
}int check(ll x) {int l = 0;int r = 1000000;while(l <= r) {int mid = (l+r) >> 1;if(1ll*mid*mid*mid == x) {return 1;}if(1ll*mid*mid*mid > x) {r = mid-1;}else{l = mid+1;}}return 0;
}int main() {prime();int t;scanf("%d", &t);while(t--) {scanf("%lld", &n);if(n == 1) {printf("0\n");continue;}ll ans = n;for(int i = 0; i < tot; i++) {if(n == 1) {break;}if(n % pri[i] == 0) {int cnt = 0;while(n % pri[i] == 0) {cnt ++;n /= pri[i];}ans = min(ans, 1ll*cnt);}}if(n >= maxn) {ll s1 = (ll)sqrt(n);ll s2 = (ll)sqrt(s1);if(s2*s2*s2*s2 == n) {ans = min(ans, 4ll);}else if(s1*s1 == n) {ans = min(ans, 2ll);}else if(check(n)) {ans = min(ans, 3ll);}else {ans = min(ans, 1ll);}}printf("%lld\n", ans);}return 0;
}

转载于:https://www.cnblogs.com/Decray/p/11305275.html

暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第四场)相关推荐

  1. 暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第一场)

    杭电多校第一场属实恐怖,我连补题的冲动都莫得了. 本来还想说按去年的经验来说,杭电是要比牛客稍微友好那么一丢丢的吧.结果当场打脸,签到题来了个最短路*2+网络流,这谁顶得住啊. 所以这两天都没在补这场 ...

  2. 暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第二场)

    这段时间自己都不知道该干些什么,比赛时候什么都想不到,全靠队友A题维持生计这样...补题进度也是一拖再拖,明后天又是两场连打,感觉又要堆一堆题了...看着补算了. 以下题解包括: \[1005[HDU ...

  3. 暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第五场)

    开启疯狂水题解模式,大概会持续好几次...直到我赶上进度为止. 以下题解包括: \[1001[HDU-6624] \\ 1004[HDU-6627] \\ 1005[HDU-6628] \\ 1006 ...

  4. 暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第六场)

    我胡汉三又滚回来了....保质期过了的题也得记下来. 以下题解包括: \[1002[HDU-6635] \\ 1005[HDU-6638] \\ 1006[HDU-6639] \\ 1008[HDU- ...

  5. 暑假N天乐【比赛篇】 —— 2019杭电暑期多校训练营(第三场)

    以下题解包括: \[1002[HDU-6604] \\ 1004[HDU-6606] \\ 1006[HDU-6608] \\ 1007[HDU-6609] \\ 1009[HDU-6611]\] [ ...

  6. 暑假N天乐【比赛篇】 —— 2019牛客暑期多校训练营(第二场)

    最近几天都没写博客,真是没什么时间写了,专题卡着,一周四场比赛,场场爆零,补题都补傻了.第一场还差两题可能今天补掉吧,昨天的杭电也是完全没动,感觉...很烦 第二场牛客断断续续也是补了几天...大概一 ...

  7. 2019牛客暑期多校训练营(第一场)(B、C、E、F、H、I题待补、J)

    特别感谢 教我C题的杭电大佬.叉姐的题解(看了还是啥也不会) B.Integration(待定系数法) 求上述式子的值,输出对分数取模的值,ai<=1e9,n<=1e3 赛中的时候用裂项拆 ...

  8. 暑假N天乐【比赛篇】 —— 2019牛客暑期多校训练营(第一场)

    期待已久暑假的重头戏终于算是打响了第一枪吧...第一把不出所料的被吊打了...被满场的数学题和自己的菜鸡英语疯狂支配.补题的话,估计只能量力而行了吧 -- 一个题解都推不出来.标程都看不懂的鶸. A ...

  9. 2019牛客暑期多校训练营(第一场)E题 ABBA(DP)

    链接:https://ac.nowcoder.com/acm/contest/881/E 题目描述 Bobo has a string of length 2(n + m) which consist ...

最新文章

  1. 连续霸榜 Github!又有一个 Linux 神器出现了
  2. Registry Release Traces 版本功能迭代和 issue bugfix
  3. python3环境下“No module named nibabel”的解决办法
  4. stmt在java中的应用_JDBC技术基础总结转载,非原创
  5. c++ 多线程 垃圾回收器_7种jvm垃圾回收器,这次全部搞懂
  6. 关于Linux路由表的route命令
  7. IntelliJ IDEA代码分屏显示
  8. python3 读取文本文件_python3读取文件最简单的办法
  9. [导入]Fedora Linux 9 的硬盘安装
  10. java的tomcat_JAVA程序获取Tomcat的运行状态
  11. 11月17日站立会议内容
  12. 无约束最优化(二) 共轭方向法与共轭梯度法
  13. 切比雪夫多项式拟合 matlab,如何用matlab实现多项式拟合?要源代码
  14. JAVA类运行时,报错“Error occurred during initialization of boot layer”
  15. JQuery学习之路Part8:家族树操作(查找祖先、后代、兄弟同胞、绝对查找)【完结】
  16. win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
  17. Git详解之特殊配置与钩子应用
  18. Excel中反转一列数据的几种方法
  19. MySQL基础数据类型
  20. python的xlrd读取Excel数据失败: raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+‘; not supported‘) ...

热门文章

  1. mysql 3列索引_mysql多列索引
  2. JAVA中的通配符的符号_Linux下的通配符和特殊符号用法详解
  3. 半圆阴影_圆中阴影部分面积求法的常用方法
  4. 北航c语言简答题目汇总_2020下半年至2021年【化学/计算机/生物类】国际竞赛汇总!...
  5. a1278 win10声卡驱动_windows安装系列教程—驱动安装
  6. MLIR(Multi-Level Intermediate Representation)概述
  7. 【迁移学习(Transfer L)全面指南】方差、协方差和Pearson相关系数的关系
  8. python【数据结构与算法】Graph(图)的总结
  9. plsql与java_Oracle之PLSQL与Java应用
  10. js实现图片从左到右循环播放