AtCoder Regular Contest 113训练赛(暴力,快速幂,贪心)
ARC 113
传送门
A. A×B×C
https://atcoder.jp/contests/arc113/tasks/arc113_a
题意
给定一个正整数K,求出正整数排列(A,B,C),使A×B×C ≤ K,的组合个数。
思路
暴力,枚举A、B,求C的个数。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<vector>
#include<queue>
#include<functional>
#include<string>
#define INF 0x7fffffff
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
int k;int main(){IOS;cin >> k;ll res = 0;for(int c = 1;c <= k;c++){int ab = 0;ab = k / c;for(int a = 1;a <= ab;a++){res += ab / a;}}cout << res << endl;system("pause");return 0;
}
B.A ^ B ^C
https://atcoder.jp/contests/arc113/tasks/arc113_b
题意
给定三个数A,B,C,求出 a b c a^{b^c} abc的个位上的数。
思路
①由于我们只需求解个位上数,所以A的个位以上的数对结果无影响,所以我们对A取余。
②找规律,我们发现0-9中每个数的n次方的个位上的数是具有规律性的,结果如下:
③利用快速幂计算 b c b^c bc对a所在周期取余的结果
④在记录a的n次幂的个位的数组中输出结果。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<vector>
#include<queue>
#include<functional>
#include<string>
#define INF 0x7fffffff
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
int abc[10][5];ll pm(ll b,ll c,ll mod){ll res = 1;while(c){if(c & 1){(res *= b)%= mod;}c >>= 1;(b*=b)%= mod;}return res;
}int main(){IOS;int a,b,c;abc[2][0] = 6;abc[2][1] = 2;abc[2][2] = 4;abc[2][3] = 8;abc[3][0] = 1;abc[3][1] = 3;abc[3][2] = 9;abc[3][3] = 7;abc[4][0] = 6;abc[4][1] = 4;abc[7][0] = 1;abc[7][1] = 7;abc[7][2] = 9;abc[7][3] = 3;abc[8][0] = 6;abc[8][1] = 8;abc[8][2] = 4;abc[8][3] = 2;abc[9][0] = 1;abc[9][1] = 9;cin >> a >> b >> c;a = a%10;if(a == 0 || a == 1 || a == 5 || a == 6){cout << a << endl;}else{if(a == 4 || a == 9){ll bc = pm(b,c,2);cout << abc[a][bc] << endl;}else {ll bc = pm(b,c,4);cout << abc[a][bc] << endl;}}system("pause");return 0;
}
C. String Invasion
https://atcoder.jp/contests/arc113/tasks/arc113_c
题意
给定字符串s,若 s i = s i + 1 ≠ s i + 2 s_i = s_{i+1} ≠ s_{i+2} si=si+1=si+2,则将 s i + 2 s_{i+2} si+2替换为 s i s_i si,求最多替换的次数。
思路
①从后往前遍历字符串,记录在两个相同且相邻的字符出现之前,各字符的出现次数。
②当出现两个相同且相邻的字符时,让结果加上这两个字符后面的字符串的长度,再减去这两个字符在后面的字符串中的出现次数(相同的字符不用修改)。
③因为后面的字符串已经被改动,所以要更新记录各字符的出现次数的数组。
④循环进行上述过程,直到字符串全都遍历完。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<vector>
#include<queue>
#include<functional>
#include<string>
#define INF 0x7fffffff
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
string s;
int cnt[30];int main(){IOS;cin >> s;ll res = 0;int len = s.length();for(int i = len-2;i >= 0;i--){if(s[i] == s[i+1]){int after = len -(i+2);res += after - cnt[s[i]-'a'];memset(cnt,0,sizeof(cnt));cnt[s[i]-'a'] = after;}cnt[s[i+1]-'a']++;}cout << res << endl;system("pause");return 0;
}
D.Sky Reflector
https://atcoder.jp/contests/arc113/tasks/arc113_d
题意
给定N,M,K, A i A_i Ai是第 i i i行的最小值, B j B_j Bj是第 j j j列的最大值,网格中每个数的大小不超过K,求(A,B)的所有可能性(答案对998244353取模)
思路
①对于n=1 和 m=1的情况特判。
②其他情况,假设A取 a 1 , a 2 , . . . a , n a_1,a_2,...a,_n a1,a2,...a,n,则设 a m a x a_{max} amax为这n个数中的最大值,对于B,若 b 1 , b 2 , . . . . , b m b_1,b_2,....,b_m b1,b2,....,bm都 ≥ a m a x ≥a_{max} ≥amax则满足题意。
③通过行列的排列顺序不同,生成数组B,故对i进行枚举,可得公式
∑ i = 1 k ( i n − ( i − 1 ) n ) ∗ ( k − i + 1 ) m \sum_{i=1}^k(i^n-(i-1)^n)*(k-i+1)^m ∑i=1k(in−(i−1)n)∗(k−i+1)m
最后再对结果进行取余。
④需要用到快速幂。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<vector>
#include<queue>
#include<functional>
#include<string>
#define INF 0x7fffffff
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
const int mod = 998244353;
int n,m,k;ll po(ll a,ll n){ll res = 1;while(n){if(n & 1){res = res * a % mod; }a = a * a %mod;n >>= 1;}res %= mod;return res;
}int main(){IOS;cin >> n >> m >> k;if(n == 1){cout << po(k,m) << endl;}else if(m == 1){cout << po(k,n) << endl;}else{ll res = 0;for(int i=1;i<=k;i++)res=(res+(ll)(po(i,n)-po(i-1,n)+mod)%mod*po(k-i+1,m)%mod)%mod;cout << res << endl;}system("pause");return 0;
}
AtCoder Regular Contest 113训练赛(暴力,快速幂,贪心)相关推荐
- AtCoder Regular Contest 113 简单题解(AC了 A~C,缺 D~F)剩下的后面几天补一下
ARC 113 https://atcoder.jp/contests/arc113/tasks.总体来说,自己还是一个菜鸡,还需要继续努力.退化太多了. A题:A*B*C 题目链接 https:// ...
- AtCoder Regular Contest 100 E - Or Plus Max Sos dp
传送门 文章目录 题意: 思路: 题意: 给你一个长度为2n2^n2n的数组,让你对于所有的1≤k≤2n−11\le k\le 2^n-11≤k≤2n−1求最大的ai+aj,0≤i<j≤2n−1 ...
- AtCoder Regular Contest 061 E - Snuke‘s Subway Trip(建图 + dijkstra最短路 / 0/1bfs / 并查集)
AtCoder Regular Contest 061 E - Snuke's Subway Trip problem 洛谷翻译 my idea 最近一直在做网络流,所以一读这题后,我就想到了最小费用 ...
- AtCoder题解——AtCoder Regular Contest 107——B - Quadruple
题目相关 题目链接 AtCoder Regular Contest 107 B 题,https://atcoder.jp/contests/arc107/tasks/arc107_b. Problem ...
- AtCoder Regular Contest 065
AtCoder Regular Contest 065 C - Daydream Score : 300300300 points 倒着来就行了,正着来会产生歧义匹配,dreamer,dreamdre ...
- AtCoder Regular Contest 100 D - Equal Cut 思维 + 前缀和
传送门 文章目录 题意: 思路: 题意: 给你一个数组aaa,你要将其分成四份,让这四份中和的最大值−-−最小值最小,输出这个最小值. n≤2e5,ai≤1e9n\le2e5,a_i\le1e9n≤2 ...
- NOMURA Programming Contest 2021(AtCoder Regular Contest 121)
文章目录 A - 2nd Greatest Distance B - RGB Matching C - Odd Even Sort D - 1 or 2 E - Directed Tree F - L ...
- 杭电ACM-LCY算法进阶培训班-专题训练(矩阵快速幂)
杭电ACM-LCY算法进阶培训班-专题训练(矩阵快速幂)[模板] 传送门 杭电ACM-LCY算法进阶培训班-专题训练(矩阵快速幂)[模板] 矩阵快速幂模板 Count Problem Descript ...
- AtCoder Regular Contest 062 E - AtCoDeerくんと立方体づくり / Building Cubes with AtCoDeer
题目传送门:https://arc062.contest.atcoder.jp/tasks/arc062_c 题目大意: 给你\(N\)块正方形木板,每块木板四角有四种颜色(可以相同),木板中央有编号 ...
最新文章
- 索引 mysql_MySQL 索引
- Mysql 存储引擎有哪些以及MyISAM和InnoDB区别
- 【实战】数据可视化系统后端开发环境搭建
- WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
- IDEA加载mysql 报:java.sql.SQLException: Unknown system variable ‘query_cache_size‘
- C++代码片段(三)过滤可变模板参数中某些类型的变量
- RSA客户端js加密服务器C#解密(含源码)
- 3005-基于二叉链表的二叉树最大宽度的计算(附思路,注释,可能错误分析)
- Angularjs 中使用 layDate 日期控件
- (开源)XMind2TestCase一个高效的测试用例设计解决方案
- 012 基于以太访的本地文件hash存储查找Dapp实例(合约安装部署)
- python123下载失败_安装python3.5时出现严重错误无法完成安装,请问这个是什么情况?怎么解决??...
- php操作mysql工具类_PHP操作数据库的工具类
- 浅谈InnoDB存储引擎下锁的分类
- c语言换行用分号代替,go语言换行的地方可以用分号替代吗?
- 英语口语175之每日十句口语
- Python入门(二) part1 列表
- 什么是RF、IF信号
- uniapp引入字体图标库
- java计算机毕业设计高校四六级报名管理系统源程序+mysql+系统+lw文档+远程调试