AcWing周赛44
周赛44
4317. 不同正整数的个数
link:https://www.acwing.com/problem/content/4320/
我直接set
#include <iostream>
#include <set>
using namespace std;
int n;
int a[105];
set<int> p;
int main (){
cin >> n;
for (int i = 1; i <= n; i ++){
cin >> a[i];
if (a[i] > 0)
p.insert (a[i]);
}
cout << p.size() << endl;
}
4318. 最短路径
link:https://www.acwing.com/problem/content/4321/
情况要考虑周全:
不能有环 (走过的标记一下)
不能相邻 (起点或终点的相邻块数目 > 1 或者 其余任何一点的相邻块数目 > 2 )考试的时候没想到
注意边界问题(起点坐标要设置为地图大小的一半)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 205;
typedef pair <int, int> pii;
string s;
bool a[N * 2][N * 2];
int x = N, y = N;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
vector <pii> v;
int main (){
cin >> s;
a[x][y] = true;
v.push_back ({x, y});
//判相交
for (int i = 0; i < s.size(); i ++){
if (s[i] == 'U')
x --;
if (s[i] == 'D')
x ++;
if (s[i] == 'L')
y --;
if (s[i] == 'R')
y ++;
v.push_back ({x, y});
if (a[x][y]){
cout << "NO";
return 0;
}
a[x][y] = true;
}
int n = v.size();
bool flag = true;
//判相邻:大于二(起点终点:大于一)
//起点终点
int cnt0 = 0, cntn = 0;
for (int i = 0; i < 4; i ++){
int xx = v[0].first + dx[i], yy = v[0].second + dy[i];
if (a[xx][yy])
cnt0 ++;
}
for (int i = 0; i < 4; i ++){
int xx = v[n - 1].first + dx[i], yy = v[n - 1].second + dy[i];
if (a[xx][yy])
cntn ++;
}
if (cnt0 > 1 || cntn > 1){
cout << "NO";
return 0;
}
//其余点
for (int j = 0; j < v.size(); j ++){
int cnt = 0;
for (int i = 0; i < 4; i ++){
int xx = v[j].first + dx[i], yy = v[j].second + dy[i];
if (a[xx][yy])
cnt ++;
}
if (cnt > 2){
cout << "NO";
return 0;
}
}
cout << "YES";
}
4319. 合适数对
link:https://www.acwing.com/problem/content/4322/
算术基本定理
本题就是求所有质因子的个数能被 k 整除
看公式:
a_i = p_1^{\alpha _ 1}...p_k^{\alpha _k}\\
a_j = p_1^{\beta _ 1}...p_k^{\beta _k}\\
则需满足 k | (\alpha _ i + \beta_ i)
\]
然后用粗略计算一下,可以发现 $2 * 3 * 5 * 7 * 11 * 13 * 17 = 510510 > 100000 $所以最多只有六种质因子(最多六项)
统计质因子次数
//大佬的STL做法
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
LL a[N];
map <vector<PII>, int> cnt;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> a[i];
LL ans = 0;
for (int i = 1; i <= n; i ++) {
int x = a[i];
vector <PII> b, c;
for (int j = 2; j <= x / j; j ++) {
int c = 0;
if (x % j == 0) {
while (x % j == 0) x /= j, ++c;
}
if (c % m) b.push_back({j, c % m});
}
if (x > 1) b.push_back({x, 1});
for (auto [x, y] : b) {
c.push_back({x, m - y});
}
ans += 1ll * cnt[c];
cnt[b]++;
}
cout << ans;
return 0;
}
AcWing周赛44的更多相关文章
- AcWing周赛43
AcWing周赛43 题源:https://www.acwing.com/activity/content/1233/ 4314. 三元组 直接暴力做就是了,我一开始还在找规律..悲 我滴代码 #in ...
- 【AcWing】周赛
A.糖果 题目链接 链接 题目描述 给定三个正整数 a,b,c. 请计算 ⌊a+b+c2⌋,即 a,b,c 相加的和除以 2 再下取整的结果. 输入格式 第一行包含整数 T,表示共有 T 组测试数据. ...
- AcWing 44. 分行从上往下打印二叉树
地址 https://www.acwing.com/problem/content/description/42/ 题目描述从上到下按层打印二叉树,同一层的结点按从左到右的顺序打印,每一层打印到一行. ...
- 【AcWing】第 62 场周赛 【2022.07.30】
AcWing 4500. 三个元素 题目描述 给定一个长度为 \(n\) 的数组 \(r\_1,r\_2,-,r\_n\). 请你找到其中的三个元素 \(r\_a,r\_b,r\_c\),使得 \(r ...
- 周赛-Equidistant String 分类: 比赛 2015-08-08 15:44 6人阅读 评论(0) 收藏
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- AcWing 第11场周赛题解
计算abc 首先 \(0<=a<=b<=c\) 会随机给出 \(a+b,a+c,b+c,a+b+c\)的值 因为\(a,b,c\)都为正整数,所以\(a+b+c\)一定为最大值 然后 ...
- PYOJ 44. 【HNSDFZ2016 #6】可持久化线段树
#44. [HNSDFZ2016 #6]可持久化线段树 统计 描述 提交 自定义测试 题目描述 现有一序列 AA.您需要写一棵可持久化线段树,以实现如下操作: A v p x:对于版本v的序列,给 A ...
- xwalk_core_library-15.44.384 .13.aar 百度云分享
xwalk_core_library-15.44.384.13.aar 这玩意下载很慢 特意放到百度,需要的可以通过百度下载 http://pan.baidu.com/s/1nt0Cmbn 下完后放到 ...
- 云计算之路-阿里云上:13:43-13:44之间RDS故障影响了全站的正常访问
抱歉!13:43-13:44之间,由于阿里云RDS(云数据库)出现2分钟突发故障,影响了全站的正常访问,给大家带来了麻烦,望大家谅解! 故障期间,应用程序日志中记录的错误信息如下: System.Da ...
随机推荐
- Zabbix 4.4管理界面中文乱码解决方法
1.zabbix 4.4 安装配置过程可参考官方文档: 文档链接地址:https://www.zabbix.com/download?zabbix=4.4&os_distribution=ce ...
- location 匹配规则
location 匹配规则 语法规则 location [=||*|^~] /uri/ { - } 模式 含义 location = /uri = 表示精确匹配,只有完全匹配上才能生效 locatio ...
- 利用DNSLog实现无回显注入
测试一些网站的时候,一些注入都是无回显的,我们可以写脚本来进行盲注,但有些网站会ban掉我们的ip,这样我们可以通过设置ip代理池解决, 但是盲注往往效率很低,所以产生了DNSlog注入 DNSLOG ...
- Netty之DefaultAttributeMap与AttributeKey的机制和原理
一.介绍和原理分析 1.什么是 DefaultAttributeMap? DefaultAttributeMap 是一个 数组 + 链表 结构的线程安全Map. 2.什么是 AttributeKey? ...
- mysql 在已存在的表中添加/删除字段约束AUTO_INCREMENT遇到的问题
1. 在已存在的表中添加字段约束AUTO_INCREMENT修饰符 mysql> alter table user modify uid int auto_increment primary k ...
- Linux Centos7使用ping命令ping不通网络的解决方案
本解决方案不配置dns,都是ping的IP地址,所以如果想ping域名,则加上DNS项的配置后自行尝试吧 我使用的虚拟机系统信息: Linux:Centos7 Network:虚拟机设置的桥接模式(自 ...
- 为什么 wait, notify 和 notifyAll 这些方法不在 thread 类里面?
一个很明显的原因是 JAVA 提供的锁是对象级的而不是线程级的,每个对象都有 锁,通过线程获得.由于 wait,notify 和 notifyAll 都是锁级别的操作,所以把他 们定义在 Object ...
- 分布式集群中为什么会有 Master?
在分布式环境中,有些业务逻辑只需要集群中的某一台机器进行执行,其他的机 器可以共享这个结果,这样可以大大减少重复计算,提高性能,于是就需要进行 leader 选举.
- 学习openstack(一)
一.云计算 云计算特点:必须通过网络使用:弹性计算(按需付费):对用户是透明的(用户不考虑后端的具体实现): 云计算分类:私有云.公有云(amazon是老大.aliyun.tingyun.tencen ...
- ES6技术之“判空方案”
一.常用方案 直接判断 代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...